From 3abef8c9a72b10d127d7d9598c3dfdadfd7b64d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9meth=20Noel?= Date: Sat, 1 May 2021 04:27:21 +0200 Subject: [PATCH 1/3] Fix position update --- src/main/java/net/minestom/server/entity/Entity.java | 7 ++----- .../minestom/server/listener/PlayerPositionListener.java | 1 + 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/minestom/server/entity/Entity.java b/src/main/java/net/minestom/server/entity/Entity.java index 421dd4b26..f822063c6 100644 --- a/src/main/java/net/minestom/server/entity/Entity.java +++ b/src/main/java/net/minestom/server/entity/Entity.java @@ -693,7 +693,8 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer, * * @param notFromListener {@code true} if the client triggered this action */ - protected void sendPositionUpdate(final boolean notFromListener) { + @ApiStatus.Internal + public void sendPositionUpdate(final boolean notFromListener) { final boolean viewChange = !position.hasSimilarView(lastSyncedPosition); final double distanceX = Math.abs(position.getX()-lastSyncedPosition.getX()); final double distanceY = Math.abs(position.getY()-lastSyncedPosition.getY()); @@ -1357,8 +1358,6 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer, position.setY(y); position.setZ(z); - sendPositionUpdate(false); - if (hasPassenger()) { for (Entity passenger : getPassengers()) { passenger.refreshPosition(x, y, z); @@ -1416,8 +1415,6 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer, this.lastPosition.setPitch(position.getPitch()); position.setYaw(yaw); position.setPitch(pitch); - - sendPositionUpdate(false); } /** diff --git a/src/main/java/net/minestom/server/listener/PlayerPositionListener.java b/src/main/java/net/minestom/server/listener/PlayerPositionListener.java index f1c835604..7c4ba8e41 100644 --- a/src/main/java/net/minestom/server/listener/PlayerPositionListener.java +++ b/src/main/java/net/minestom/server/listener/PlayerPositionListener.java @@ -90,6 +90,7 @@ public class PlayerPositionListener { player.refreshPosition(newPosition.getX(), newPosition.getY(), newPosition.getZ()); player.refreshView(newPosition.getYaw(), newPosition.getPitch()); player.refreshOnGround(onGround); + player.sendPositionUpdate(false); } else { player.teleport(player.getPosition()); } From 78dc2b32cdb155fae04025d15158502007bafd9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9meth=20Noel?= Date: Sat, 1 May 2021 04:38:04 +0200 Subject: [PATCH 2/3] Removed isNettyClient field --- src/main/java/net/minestom/server/entity/Entity.java | 5 ++--- src/main/java/net/minestom/server/entity/Player.java | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/minestom/server/entity/Entity.java b/src/main/java/net/minestom/server/entity/Entity.java index f822063c6..699a30392 100644 --- a/src/main/java/net/minestom/server/entity/Entity.java +++ b/src/main/java/net/minestom/server/entity/Entity.java @@ -138,8 +138,6 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer, */ private final Object entityTypeLock = new Object(); - protected boolean isNettyClient; - public Entity(@NotNull EntityType entityType, @NotNull UUID uuid) { this.id = generateId(); this.entityType = entityType; @@ -496,6 +494,7 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer, } sendPositionUpdate(true); + final boolean isNettyClient = PlayerUtils.isNettyClient(this); // Entity tick { @@ -742,7 +741,7 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer, return; } - if (isNettyClient && notFromListener) { + if (PlayerUtils.isNettyClient(this) && notFromListener) { final PlayerPositionAndLookPacket playerPositionAndLookPacket = new PlayerPositionAndLookPacket(); playerPositionAndLookPacket.flags = 0b111; playerPositionAndLookPacket.position = position.clone().subtract(lastSyncedPosition.getX(), lastSyncedPosition.getY(), lastSyncedPosition.getZ()); diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index 507b84683..7bc218402 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -181,7 +181,6 @@ public class Player extends LivingEntity implements CommandSender, Localizable, super(EntityType.PLAYER, uuid); this.username = username; this.playerConnection = playerConnection; - this.isNettyClient = PlayerUtils.isNettyClient(this); setBoundingBox(0.6f, 1.8f, 0.6f); From f4c55dd4b2f07d3a327b8e8bec7cb2ca2b0ccf8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9meth=20Noel?= Date: Sat, 1 May 2021 04:38:28 +0200 Subject: [PATCH 3/3] Fixed javadoc --- src/main/java/net/minestom/server/entity/Entity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/minestom/server/entity/Entity.java b/src/main/java/net/minestom/server/entity/Entity.java index 699a30392..7eff6248f 100644 --- a/src/main/java/net/minestom/server/entity/Entity.java +++ b/src/main/java/net/minestom/server/entity/Entity.java @@ -690,7 +690,7 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer, * In case of a player's position and/or view change an additional {@link PlayerPositionAndLookPacket} * is sent to self. * - * @param notFromListener {@code true} if the client triggered this action + * @param notFromListener {@code false} if the client triggered this action */ @ApiStatus.Internal public void sendPositionUpdate(final boolean notFromListener) {