1.16.5 Walk NPC

Discussion in 'Spigot Plugin Development' started by gamerpig, Apr 10, 2021.

  1. finally tried this but it didnt do the walk animation!
     
  2. for anyone whoes interested this didnt work (RIP)
     
  3. Code (Java):
    PacketPlayOutEntity movepacket = new PacketPlayOutEntity.PacketPlayOutRelEntityMove(martinnpc.getId(), (short) (-10.500 * 4096), (short) (67.93750 * 1), (short) (43.500 * 4096), true);
                    ((CraftPlayer) p).getHandle().playerConnection.sendPacket(movepacket);
    Remember that this packet controls the delta X/Y/Z of an entity. You're sending a packet to move the entity relative to where it was before. Your code right now tries to teleport an entity -10.5 blocks in X, 0.01658 in the Y, and 43.5 block in Z. The main problem with this is that the maximum blocks you can teleport with this packet is 8, so you've already run into an overflow issue.

    The formula that is supposed to be used in this packet is as follows:
    Code (Java):
    new PacketPlayOutEntity.PacketPlayOutRelEntityMove(martinnpc.getId(), 4096 * (currentX - prevX), 4096 * (currentY - prevZ), 4096 * (currentZ - prevZ), true);
    or in other words...
    Code (Java):
    new PacketPlayOutEntity.PacketPlayOutRelEntityMove(martinnpc.getId(), 4096 * (ΔX), 4096 * (ΔY), 4096 * (ΔZ), true);
    In order to test, I would recommend you set either ΔX or ΔZ to 0.21585 in order to test movement, it should roughly simulate a walking speed of a player.

    If you want to generate a path to a location YOU specify, you're in a very rough spot. That's why I mentioned the NMS Navigation class, because it allows you to generate paths that contain a bunch of locations/vectors for entity movement. But even then it can be too hard to deal with. In all honesty, I would use LibsDisguises API. Spawn an entity, set its pathfinder goals, and disguise it as a player. It will go to the location you specify without all the extra math and packet sending.
     
    #23 Martoph, Apr 17, 2021
    Last edited: Apr 17, 2021
  4. thanks for all this info! i agree that this is would be a very long and though out process. I'm going to try one more thing and if this doesnt work ill try out LibsDisguises!