aboutsummaryrefslogtreecommitdiff
path: root/azalea-entity/src
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-06-26 15:24:41 +0930
committermat <git@matdoes.dev>2025-06-25 16:10:15 -1345
commitf12589ab809ece7dfd34c58b2ddc67dd5801ccb3 (patch)
tree7ffef4672378715c92d82749d3ef1a82cc7f9f24 /azalea-entity/src
parent08c409d04896e7057c31250f2d6f99c75b8af5b5 (diff)
downloadazalea-drasl-f12589ab809ece7dfd34c58b2ddc67dd5801ccb3.tar.xz
fix invalid look directions on teleport
Diffstat (limited to 'azalea-entity/src')
-rw-r--r--azalea-entity/src/lib.rs4
-rw-r--r--azalea-entity/src/plugin/mod.rs8
2 files changed, 9 insertions, 3 deletions
diff --git a/azalea-entity/src/lib.rs b/azalea-entity/src/lib.rs
index b8644546..340b6f25 100644
--- a/azalea-entity/src/lib.rs
+++ b/azalea-entity/src/lib.rs
@@ -226,8 +226,10 @@ pub struct LookDirection {
}
impl LookDirection {
+ /// Create a new look direction, while clamping and wrapping the rotations
+ /// to the allowed values.
pub fn new(y_rot: f32, x_rot: f32) -> Self {
- Self { y_rot, x_rot }
+ apply_clamp_look_direction(Self { y_rot, x_rot })
}
}
diff --git a/azalea-entity/src/plugin/mod.rs b/azalea-entity/src/plugin/mod.rs
index 65b28a59..88e87de1 100644
--- a/azalea-entity/src/plugin/mod.rs
+++ b/azalea-entity/src/plugin/mod.rs
@@ -187,10 +187,14 @@ pub struct LoadedBy(pub HashSet<Entity>);
pub fn clamp_look_direction(mut query: Query<&mut LookDirection>) {
for mut look_direction in &mut query {
- look_direction.y_rot = look_direction.y_rot.rem_euclid(360.0);
- look_direction.x_rot = look_direction.x_rot.clamp(-90.0, 90.0) % 360.0;
+ *look_direction = apply_clamp_look_direction(*look_direction);
}
}
+pub fn apply_clamp_look_direction(mut look_direction: LookDirection) -> LookDirection {
+ look_direction.y_rot = look_direction.y_rot.rem_euclid(360.0);
+ look_direction.x_rot = look_direction.x_rot.clamp(-90.0, 90.0) % 360.0;
+ look_direction
+}
/// Sets the position of the entity. This doesn't update the cache in
/// azalea-world, and should only be used within azalea-world!