Skip to content

Minecraft: Java Edition 26.3 rewritten from scratch in Rust, checked against vanilla with 281 differential harnesses. Get it with the Horizon launcher.

Hand sway: tick follows vanilla's unwrapped yaw; the wrap moves to a separate method

HrafnaValkyrja602923d8a779
diff --git a/crates/horizon-client/src/first_person.rs b/crates/horizon-client/src/first_person.rs
index 52ceb46e9..078dd52c1 100644
--- a/crates/horizon-client/src/first_person.rs
+++ b/crates/horizon-client/src/first_person.rs
@@ -541,6 +541,8 @@ pub struct HandSway {
pub y_bob: f32,
pub x_bob_o: f32,
pub y_bob_o: f32,
+ /// The yaw `tick_wrapped` has followed so far, unwrapped like vanilla's.
+ y_rot: f32,
}
impl HandSway {
/// `LocalPlayer.applyInput` with the player's `getXRot` and `getYRot`.
@@ -548,9 +550,14 @@ impl HandSway {
self.y_bob_o = self.y_bob;
self.x_bob_o = self.x_bob;
self.x_bob += (x_rot - self.x_bob) * 0.5;
- // Vanilla's yaw runs on without wrapping, so `yRot - yBob` is the short way round. Ours
- // is kept in -180..180 (a boat turns its rider through it), so take the short way here.
- self.y_bob += wrap_degrees(y_rot - self.y_bob) * 0.5;
+ self.y_bob += (y_rot - self.y_bob) * 0.5;
+ }
+ /// `tick` for a yaw kept in -180..180 (a boat turns its rider through the wrap). Vanilla's
+ /// yaw runs on without wrapping, so `yRot - yBob` is always the short way round; this
+ /// follows the wrapped yaw by its short steps to give `tick` the same unwrapped yaw.
+ pub fn tick_wrapped(&mut self, x_rot: f32, y_rot: f32) {
+ self.y_rot += wrap_degrees(y_rot - self.y_rot);
+ self.tick(x_rot, self.y_rot);
}
/// The degrees the hands turn about X, then Y, before either is drawn:
/// `(viewXRot - xBob) * 0.1` and `(viewYRot - yBob) * 0.1`, the bobs
@@ -1406,12 +1413,12 @@ mod action_result_tests {
#[test]
fn hand_sway_takes_the_short_way_over_the_yaw_wrap() {
let mut sway = HandSway::default();
- sway.tick(0.0, 179.0);
+ sway.tick_wrapped(0.0, 179.0);
for _ in 0..20 {
- sway.tick(0.0, 179.0);
+ sway.tick_wrapped(0.0, 179.0);
}
// The view is still at 179; one tick later it reads -179 (2 degrees on).
- sway.tick(0.0, -179.0);
+ sway.tick_wrapped(0.0, -179.0);
let [_, y] = sway.rotation(1.0, 0.0, -179.0);
assert!(
y.abs() < 0.5,
diff --git a/crates/horizon-client/src/game/hand.rs b/crates/horizon-client/src/game/hand.rs
index c949e84a0..ca388287e 100644
--- a/crates/horizon-client/src/game/hand.rs
+++ b/crates/horizon-client/src/game/hand.rs
@@ -385,7 +385,7 @@ impl Game<'_> {
pub(super) fn tick_hand(&mut self) {
// LocalPlayer.applyInput (the camera is the player's own).
if self.player.is_some() {
- self.sway.tick(self.pitch, self.yaw);
+ self.sway.tick_wrapped(self.pitch, self.yaw);
}
self.swing.tick();
let main = self.inventory[self.selected].clone();