diff --git a/src/main/java/net/minestom/server/coordinate/Pos.java b/src/main/java/net/minestom/server/coordinate/Pos.java index 7d1c39556..4ac61a305 100644 --- a/src/main/java/net/minestom/server/coordinate/Pos.java +++ b/src/main/java/net/minestom/server/coordinate/Pos.java @@ -133,8 +133,12 @@ public record Pos(double x, double y, double z, float yaw, float pitch) implemen * @return true if the two positions have the same view */ public boolean sameView(@NotNull Pos position) { - return Float.compare(position.yaw, yaw) == 0 && - Float.compare(position.pitch, pitch) == 0; + return sameView(position.yaw(), position.pitch()); + } + + public boolean sameView(float yaw, float pitch) { + return Float.compare(this.yaw, yaw) == 0 && + Float.compare(this.pitch, pitch) == 0; } /** diff --git a/src/main/java/net/minestom/server/entity/Entity.java b/src/main/java/net/minestom/server/entity/Entity.java index 7645733ba..413c6759d 100644 --- a/src/main/java/net/minestom/server/entity/Entity.java +++ b/src/main/java/net/minestom/server/entity/Entity.java @@ -323,7 +323,9 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev * @param pitch the new pitch */ public void setView(float yaw, float pitch) { - this.position = position.withView(yaw, pitch); + final Pos currentPosition = this.position; + if (currentPosition.sameView(yaw, pitch)) return; + this.position = currentPosition.withView(yaw, pitch); sendPacketToViewersAndSelf(new EntityHeadLookPacket(getEntityId(), yaw)); sendPacketToViewersAndSelf(new EntityRotationPacket(getEntityId(), yaw, pitch, onGround)); } @@ -336,7 +338,7 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev */ public void lookAt(@NotNull Pos position) { final Pos newPosition = this.position.withLookAt(position); - if (!newPosition.sameView(this.position)) setView(newPosition.yaw(), newPosition.pitch()); + setView(newPosition.yaw(), newPosition.pitch()); } /**