Want a better Minecraft server? Read about SpigotMC here!
Separate names with a comma.
Discussion in 'Spigot Plugin Development' started by gamerpig, Apr 10, 2021.
finally tried this but it didnt do the walk animation!
for anyone whoes interested this didnt work (RIP)
PacketPlayOutEntity movepacket = new PacketPlayOutEntity.PacketPlayOutRelEntityMove(martinnpc.getId(), (short) (-10.500 * 4096), (short) (67.93750 * 1), (short) (43.500 * 4096), true);
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:
new PacketPlayOutEntity.PacketPlayOutRelEntityMove(martinnpc.getId(), 4096 * (currentX - prevX), 4096 * (currentY - prevZ), 4096 * (currentZ - prevZ), true);
or in other words...
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.
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!