Fix or clarify behaviour of EntityMoveEvent
Expected behavior
EntityMoveEvent fires every time an entity changes location or any of its rotations
Observed/Actual behavior
EntityMoveEvent is only firing for certain types of movement.
From my observations, it fires:
- When the entity is changing its x/y/z in any way
- When the entity is changing ONLY its yaw/pitch IF a player is in close proximity of it (a few blocks, close enough for the entity to look at the player)
However it does not fire: 3) When the entity is changing ONLY its yaw/pitch and no player is in close proximity
Steps/models to reproduce
I tested this with a cow entity spawned via /summon.
I stuck the cow in a 1x1 hole 2 blocks deep, so that the cow is unable to change its x/y/z; will not try to pathfind.
Create a simple listener for EntityMoveEvent and print a message to console every time it fires. I used this:
@EventHandler(priority = EventPriority.MONITOR)
public void test(@NotNull EntityMoveEvent event) {
Logger logger = Rorrim.getInstance().getLogger();
Location from = event.getFrom();
Location to = event.getTo();
Vector v = new Vector(
to.getX() - from.getX(),
to.getY() - from.getY(),
to.getZ() - from.getZ()
);
logger.info("EntityMoveEvent fired for " + event.getEntityType());
logger.info("---> velocity x/y/z: " + v.getX() + "/" + v.getY() + "/" + v.getZ());
}
Get close to that entity and observe your console. You will see that the event fires, despite the entity only changing yaw/pitch.
Now fly far away. 16 blocks or so. You will observe that the entity is still changing yaw/pitch, but no EntityMoveEvent is fired.
Those rotations of the entity are not client-side.
I used this code to double check that yaw/pitch are changing server-side:
Bukkit.getWorlds()
.forEach(world -> world.getEntities()
.forEach(entity -> {
if (entity.getType() != EntityType.PLAYER) {
Rorrim.getInstance().getLogger().info("Yaw of " + entity.getType() + ": " + entity.getLocation().getYaw());
}
})
);
The values of these code change despite the event not firing.
Plugin and Datapack List
Tested w/o any
Paper version
This server is running Paper version git-Paper-399 (MC: 1.17.1) (Implementing API version 1.17.1-R0.1-SNAPSHOT) (Git: d4318a6 on ver/1.17.1) You are 9 version(s) behind Download the new version at: https://papermc.io/downloads
Other
If this is a bug, then it shall please be fixed, If this is intentional behaviour, then please clarify the documentations - for the sake of others that would expect this event to work just like PlayerMoveEvent.
Thank you