mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-08 09:27:58 +01:00
Added the Position#fixYaw method that fixes yaw values an used it on Position#setYaw and on a Position constructor to fix issue #168
This commit is contained in:
parent
5b98fbeb8b
commit
9c1eeb56d3
@ -20,7 +20,7 @@ public class Position implements PublicCloneable<Position> {
|
|||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
this.yaw = yaw;
|
this.yaw = fixYaw(yaw);
|
||||||
this.pitch = pitch;
|
this.pitch = pitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -356,7 +356,24 @@ public class Position implements PublicCloneable<Position> {
|
|||||||
* @param yaw the new yaw
|
* @param yaw the new yaw
|
||||||
*/
|
*/
|
||||||
public void setYaw(float yaw) {
|
public void setYaw(float yaw) {
|
||||||
this.yaw = yaw;
|
this.yaw = fixYaw(yaw);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fixes a yaw value that is not between -180.0F and 180.0F
|
||||||
|
* So for example -1355.0F becomes 85.0F and 225.0F becomes -135.0F
|
||||||
|
*
|
||||||
|
* @param yaw The possible "wrong" yaw
|
||||||
|
* @return a fixed yaw
|
||||||
|
*/
|
||||||
|
private float fixYaw(float yaw) {
|
||||||
|
yaw = yaw % 360;
|
||||||
|
if(yaw < -180.0F) {
|
||||||
|
yaw += 360.0F;
|
||||||
|
} else if(yaw > 180.0F) {
|
||||||
|
yaw -= 360.0F;
|
||||||
|
}
|
||||||
|
return yaw;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user