diff --git a/src/main/java/net/minestom/server/entity/Entity.java b/src/main/java/net/minestom/server/entity/Entity.java index 87b539f61..477cd9f2d 100644 --- a/src/main/java/net/minestom/server/entity/Entity.java +++ b/src/main/java/net/minestom/server/entity/Entity.java @@ -268,7 +268,7 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer, final ChunkCallback endCallback = (chunk) -> { refreshPosition(teleportPosition); - synchronizePosition(); + synchronizePosition(true); OptionalCallback.execute(callback); }; @@ -594,7 +594,7 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer, // Synchronization and packets... if (!isNettyClient) { - synchronizePosition(); + synchronizePosition(true); } // Verify if velocity packet has to be sent if (hasVelocity() || (!isNettyClient && gravityTickCount > 0)) { @@ -665,7 +665,7 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer, // Scheduled synchronization if (!Cooldown.hasCooldown(time, lastAbsoluteSynchronizationTime, getSynchronizationCooldown())) { - synchronizePosition(); + synchronizePosition(false); } if (shouldRemove() && !MinecraftServer.isStopping()) { @@ -680,7 +680,7 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer, * The following packets are sent to viewers (check are performed in this order): *
    *
  1. {@link EntityTeleportPacket} if {@code distanceX > 8 || distanceY > 8 || distanceZ > 8} - * (performed using {@link #synchronizePosition()})
  2. + * (performed using {@link #synchronizePosition(boolean)}) *
  3. {@link EntityPositionAndRotationPacket} if {@code positionChange && viewChange}
  4. *
  5. {@link EntityPositionPacket} if {@code positionChange}
  6. *
  7. {@link EntityRotationPacket} and {@link EntityHeadLookPacket} if {@code viewChange}
  8. @@ -698,7 +698,7 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer, final boolean positionChange = (distanceX+distanceY+distanceZ) > 0; if (distanceX > 8 || distanceY > 8 || distanceZ > 8) { - synchronizePosition(); + synchronizePosition(true); // #synchronizePosition sets sync fields, it's safe to return return; } else if (positionChange && viewChange) { @@ -1583,9 +1583,11 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer, * {@link EntityTeleportPacket} to viewers, in case of a player this is * overridden in order to send an additional {@link PlayerPositionAndLookPacket} * to itself. + * @param includeSelf if {@code true} and this is a {@link Player} an additional {@link PlayerPositionAndLookPacket} + * will be sent to the player itself */ @ApiStatus.Internal - protected void synchronizePosition() { + protected void synchronizePosition(boolean includeSelf) { final Position pos = position.clone(); final EntityTeleportPacket entityTeleportPacket = new EntityTeleportPacket(); entityTeleportPacket.entityId = getEntityId(); diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index 8a7ecad0c..cb7ea2dd4 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -661,7 +661,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable, } if (dimensionChange || firstSpawn) { - synchronizePosition(); // So the player doesn't get stuck + synchronizePosition(true); // So the player doesn't get stuck this.inventory.update(); } @@ -1984,18 +1984,19 @@ public class Player extends LivingEntity implements CommandSender, Localizable, } /** - * @see Entity#synchronizePosition() + * @see Entity#synchronizePosition(boolean) + * @param includeSelf */ @Override @ApiStatus.Internal - protected void synchronizePosition() { + protected void synchronizePosition(boolean includeSelf) { final PlayerPositionAndLookPacket positionAndLookPacket = new PlayerPositionAndLookPacket(); positionAndLookPacket.position = position.clone(); positionAndLookPacket.flags = 0x00; positionAndLookPacket.teleportId = teleportId.incrementAndGet(); playerConnection.sendPacket(positionAndLookPacket); - super.synchronizePosition(); + super.synchronizePosition(includeSelf); } /**