mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-06 08:27:43 +01:00
Add a new Pos#sameView
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
64f617c81c
commit
a4adbb49fe
@ -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
|
* @return true if the two positions have the same view
|
||||||
*/
|
*/
|
||||||
public boolean sameView(@NotNull Pos position) {
|
public boolean sameView(@NotNull Pos position) {
|
||||||
return Float.compare(position.yaw, yaw) == 0 &&
|
return sameView(position.yaw(), position.pitch());
|
||||||
Float.compare(position.pitch, pitch) == 0;
|
}
|
||||||
|
|
||||||
|
public boolean sameView(float yaw, float pitch) {
|
||||||
|
return Float.compare(this.yaw, yaw) == 0 &&
|
||||||
|
Float.compare(this.pitch, pitch) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -323,7 +323,9 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev
|
|||||||
* @param pitch the new pitch
|
* @param pitch the new pitch
|
||||||
*/
|
*/
|
||||||
public void setView(float yaw, float 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 EntityHeadLookPacket(getEntityId(), yaw));
|
||||||
sendPacketToViewersAndSelf(new EntityRotationPacket(getEntityId(), yaw, pitch, onGround));
|
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) {
|
public void lookAt(@NotNull Pos position) {
|
||||||
final Pos newPosition = this.position.withLookAt(position);
|
final Pos newPosition = this.position.withLookAt(position);
|
||||||
if (!newPosition.sameView(this.position)) setView(newPosition.yaw(), newPosition.pitch());
|
setView(newPosition.yaw(), newPosition.pitch());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user