PaperMC / PaperMC/Paper

Fix or clarify behaviour of EntityMoveEvent

Open
#7,394 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

status: accepted type: bug
Dominant language
Java
Stars
12.7k
Forks
3.5k
Avg merge
3d 13h
Merged PRs (30d)
11

Description

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:

  1. When the entity is changing its x/y/z in any way
  2. 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the EntityMoveEvent and PlayerMoveEvent API entry points, then reproduce the cow rotation case described in the issue with no plugins or datapacks. Compare the documented event contract with observed server behavior; done means either rotation-only movement consistently triggers the event or the intentional limitation is clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend-api-design, documentation
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.