From c31bd456f6bd93c0da3cc4db1119bb94bf493d1f Mon Sep 17 00:00:00 2001 From: Kevin Ludwig <32491319+valaphee@users.noreply.github.com> Date: Fri, 30 Sep 2022 18:12:27 +0200 Subject: [PATCH] Fix entity motion (arrows now rotate correctly) (#3307) --- .../geysermc/geyser/entity/type/Entity.java | 44 ++++++++++++++----- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index 1db2e6117..c4046bcf3 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -216,19 +216,41 @@ public class Entity { } public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch, float headYaw, boolean isOnGround) { - setYaw(yaw); - setPitch(pitch); - setHeadYaw(headYaw); - setOnGround(isOnGround); - this.position = Vector3f.from(position.getX() + relX, position.getY() + relY, position.getZ() + relZ); + position = Vector3f.from(position.getX() + relX, position.getY() + relY, position.getZ() + relZ); - MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket(); + MoveEntityDeltaPacket moveEntityPacket = new MoveEntityDeltaPacket(); moveEntityPacket.setRuntimeEntityId(geyserId); - moveEntityPacket.setPosition(position); - moveEntityPacket.setRotation(getBedrockRotation()); - moveEntityPacket.setOnGround(isOnGround); - moveEntityPacket.setTeleported(false); - + if (relX != 0.0) { + moveEntityPacket.setX(position.getX()); + moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_X); + } + if (relY != 0.0) { + moveEntityPacket.setY(position.getY()); + moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_Y); + } + if (relZ != 0.0) { + moveEntityPacket.setZ(position.getZ()); + moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_Z); + } + if (pitch != this.pitch) { + this.pitch = pitch; + moveEntityPacket.setPitch(pitch); + moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_PITCH); + } + if (yaw != this.yaw) { + this.yaw = yaw; + moveEntityPacket.setYaw(yaw); + moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_YAW); + } + if (headYaw != this.headYaw) { + this.headYaw = headYaw; + moveEntityPacket.setHeadYaw(headYaw); + moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_HEAD_YAW); + } + setOnGround(isOnGround); + if (isOnGround) { + moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.ON_GROUND); + } session.sendUpstreamPacket(moveEntityPacket); }