Wrap teleport pitch before clamping

This commit is contained in:
arismoko committed 2026-11-03 04:02:19 +00:00
1 parent f105fc0d7b
commit 4ac46cd511
1 file changed
+19 -3
+19 -3
View File
@@ -78,6 +78,11 @@ pub(super) enum Target {
/// A simulated lingering, creeper or dragon area-effect cloud.
Cloud(u32),
}
/// `Entity.setXRot`: reduce the angle before clamping the pitch.
fn entity_pitch(pitch: f32) -> f32 {
(pitch % 360.0).clamp(-90.0, 90.0)
}
/// An entity of a type Horizon does not simulate: its compound lives in the
/// entity memory (`persist.raw`), its position and rotation here.
#[derive(Clone, Debug)]
@@ -1534,7 +1539,7 @@ impl Game<'_> {
self.previous_position = v;
if let Some([yaw, pitch]) = rotation {
self.yaw = yaw;
self.pitch = pitch.clamp(-90.0, 90.0);
self.pitch = entity_pitch(pitch);
}
// A server player's teleport is told to the mods once their
// move is in the hub (`leave_guest`).
@@ -1565,7 +1570,7 @@ impl Game<'_> {
m.yaw = yaw;
m.body_yaw = yaw;
m.head_yaw = yaw;
m.head_pitch = pitch.clamp(-90.0, 90.0);
m.head_pitch = entity_pitch(pitch);
m.previous_yaw = m.yaw;
m.previous_head_pitch = m.head_pitch;
}
@@ -1629,7 +1634,7 @@ impl Game<'_> {
o.position = v;
if let Some([yaw, pitch]) = rotation {
o.yaw = yaw;
o.pitch = pitch;
o.pitch = entity_pitch(pitch);
}
}
}
@@ -3923,6 +3928,17 @@ fn difficulty_names(from: u8, to: u8) -> (&'static str, &'static str) {
)
}
#[cfg(test)]
mod teleport_pitch_tests {
#[test]
fn pitch_wraps_before_clamping() {
assert_eq!(super::entity_pitch(360.0), 0.0);
assert_eq!(super::entity_pitch(450.0), 90.0);
assert_eq!(super::entity_pitch(-360.0), 0.0);
assert_eq!(super::entity_pitch(-450.0), -90.0);
}
}
#[cfg(test)]
mod difficulty_tests {
use super::difficulty_names;