1.12.2 Entity Move

Discussion in 'Spigot Plugin Development' started by Plochem, Jan 10, 2020.

  1. Hi, how should I make any entity (Any Mob and EntityPlayer) move toward a location? I googled some solutions, but PathfinderGoalSelector and Navigator are only applicable for EntityInsentient. After looking through the NMS's Entity class, I found a method Entity#move(EnumMoveType, d0, d1, d2). Does anyone know if I should use this method or is there another way of doing it?

    Edit: Would using PacketPlayOutRelEntityMove work better?
    #1 Plochem, Jan 10, 2020
    Last edited: Jan 10, 2020
  2. Just out of curiosity, what would this be used for?
  3. It's for something similar to pvp bosses
  4. Oh cool. i thought you were doing some type of battle royale game :D
  5. The only way i know is using a plugin called denizen. it would require you to do some scripting of your own tho.
  6. thanks, but i prefer to do it in java
  7. oh ok :p good luck man!!!
  8. If you’re piggybacking off the server to manage your entity (ie using addEntity) then teleporting or Entity#move(...) should work fine

    If you’re spawning a client-side entity you need to use the movement packet (+ head look and rotation if needed)
  9. Ah ok. So I’m still kinda forced to use Entity#move() for mobs and the packets for player NPCs unless I spawn both mobs and NPCs with packets.
  10. Don’t send your own packets if the server spawns them or their movement gets out of sync. The server sends its packets for entities through EntityTracker which updates whenever the position of an entity is changed or over some time interval, whichever comes first.
  11. Like you said, players do not extend EntityInsentient so you can not add a custom PathfinderGoal.
    You can however copy the navigator classes and implement them in your own way with a few adjustments, since they just call the entity move methods.
    A popular NPC plugin called Citizens does something similar, you might want to check it out.

    Their implementation of a Player NPC:
  12. Alright then. Anyways, the Entity#move() method that I mentioned only moves relative to its position. So, d0, d1, d2 in the method's parameters are the change in the entity's x, y, and z respectively. With that said, how would I utilize this method to move an entity to a given location at a given speed (blocks per second)?

    Yeah, I might end up using that if I can't get the Entity#move() working.
    #13 Plochem, Jan 13, 2020
    Last edited: Jan 13, 2020
  13. you don't need a pathfinder to make the entity move:
    this is what i do for TheLab
    Code (Text):
        public boolean navigateTo(Villager villager, double x, double y, double z) {
            EntityVillager v = ((CraftVillager) villager).getHandle();
            return v.getNavigation().a(x, y, z, 0.84);
  14. I know, but I prefer to use Entity#move() since it moves any type of entity, not just EntityInsentient.
  15. Assume d0, d1, and d2 stand for change in x, y, and z:
    Code (Java):
    d0 = entity.getLocation().getX() - targetLocation.getX()
    Move speed could be calculated as well if you know the base speed of the entity. Just scale it
    • Agree Agree x 1