[PR #83] [MERGED] Hand sway: the first-person hands lag behind the view, as in vanilla #2314

Closed
opened 2026-11-02 15:54:52 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/83
Author: @ludovic111
Created: 10/14/2026
Status: ✅ Merged
Merged: 10/14/2026
Merged by: @ludovic111

Base: main ← Head: fix/hand-sway-66


📝 Commits (1)

  • 84adffc Hand sway: the first-person hands lag behind the view, as in vanilla

📊 Changes

8 files changed (+96 additions, -11 deletions)

View changed files

📝 crates/horizon-client/examples/first_person_probe.rs (+14 -3)
📝 crates/horizon-client/src/first_person.rs (+29 -0)
📝 crates/horizon-client/src/game.rs (+11 -1)
📝 crates/horizon-client/src/game/end.rs (+1 -0)
📝 crates/horizon-client/src/game/hand.rs (+4 -0)
📝 crates/horizon-client/src/game/remote.rs (+1 -0)
📝 mods/horizon/src/test/java/dev/horizonlab/parity/VanillaFirstPersonOracle.java (+15 -2)
📝 tools/test_first_person_parity.py (+21 -5)

📄 Description

What was wrong

The first-person hand (empty arm, held items, maps) was fixed to the view. Vanilla's hands trail behind when the view turns and catch up over a few ticks.

What vanilla does

  • LocalPlayer.applyInput (from aiStep, when the player is the camera) runs every tick: yBobO = yBob; xBobO = xBob; xBob += (getXRot() - xBob) * 0.5F; yBob += (getYRot() - yBob) * 0.5F.
  • FirstPersonHandsAndItems.extractRenderState stores viewXRot/viewYRot and Mth.lerp(partialTicks, xBobO, xBob) / yBob.
  • FirstPersonHandsAndItemsRenderer then calls rotateDegrees(Axis.XP, (viewXRot - xBob) * 0.1F) and rotateDegrees(Axis.YP, (viewYRot - yBob) * 0.1F) before drawing either hand.
  • The bobs belong to the LocalPlayer, so they start at 0 for every new one (login, respawn, dimension change).

The fix

  • first_person::HandSway holds the bobs, applyInput's tick, and the rotation from the interpolated bobs.
  • The game ticks it with the hands, resets it wherever vanilla creates a new LocalPlayer, and hand_geometry applies the rotation to the base transform, so the arm, held items and held maps all sway.

Tests

  • First-person harness (tools/test_first_person_parity.py): steps can now turn the player. The oracle sets the real LocalPlayer's rotation (setXRot/setYRot) and calls the real applyInput (the shell player overrides only isControlledCamera, because the mocked Minecraft has no game renderer). Both sides print xBob yBob xBobO yBobO on every tick line. Added turning scenarios (smooth turns, snaps, yaw past ±180 and multiples of 360, pitch at ±90) and random turns in the random cases. 4,194 cases match the pinned client (382,070 output lines; about 120k distinct bob pairs compared).
  • Seen in the game on the virtual screen: right after a 90° turn the arm sits further left, then settles back.
  • cargo fmt --check, cargo clippy --workspace --all-targets -D warnings and cargo test --workspace pass; tools/check_public_tree.py passes.

Left open

  • The off-hand item is still not drawn in first person (unchanged by this PR); it will get the same rotation once it is, because the sway is in the shared base transform.

Fixes #66

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/83 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/14/2026 **Status:** ✅ Merged **Merged:** 10/14/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/hand-sway-66` --- ### 📝 Commits (1) - [`84adffc`](https://github.com/horizon-rust/horizon/commit/84adffc3f227baa6747f7f9bf864181d47ba7ca9) Hand sway: the first-person hands lag behind the view, as in vanilla ### 📊 Changes **8 files changed** (+96 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/examples/first_person_probe.rs` (+14 -3) 📝 `crates/horizon-client/src/first_person.rs` (+29 -0) 📝 `crates/horizon-client/src/game.rs` (+11 -1) 📝 `crates/horizon-client/src/game/end.rs` (+1 -0) 📝 `crates/horizon-client/src/game/hand.rs` (+4 -0) 📝 `crates/horizon-client/src/game/remote.rs` (+1 -0) 📝 `mods/horizon/src/test/java/dev/horizonlab/parity/VanillaFirstPersonOracle.java` (+15 -2) 📝 `tools/test_first_person_parity.py` (+21 -5) </details> ### 📄 Description ## What was wrong The first-person hand (empty arm, held items, maps) was fixed to the view. Vanilla's hands trail behind when the view turns and catch up over a few ticks. ## What vanilla does - `LocalPlayer.applyInput` (from `aiStep`, when the player is the camera) runs every tick: `yBobO = yBob; xBobO = xBob; xBob += (getXRot() - xBob) * 0.5F; yBob += (getYRot() - yBob) * 0.5F`. - `FirstPersonHandsAndItems.extractRenderState` stores `viewXRot`/`viewYRot` and `Mth.lerp(partialTicks, xBobO, xBob)` / `yBob`. - `FirstPersonHandsAndItemsRenderer` then calls `rotateDegrees(Axis.XP, (viewXRot - xBob) * 0.1F)` and `rotateDegrees(Axis.YP, (viewYRot - yBob) * 0.1F)` before drawing either hand. - The bobs belong to the `LocalPlayer`, so they start at 0 for every new one (login, respawn, dimension change). ## The fix - `first_person::HandSway` holds the bobs, `applyInput`'s tick, and the rotation from the interpolated bobs. - The game ticks it with the hands, resets it wherever vanilla creates a new `LocalPlayer`, and `hand_geometry` applies the rotation to the base transform, so the arm, held items and held maps all sway. ## Tests - First-person harness (`tools/test_first_person_parity.py`): steps can now turn the player. The oracle sets the real `LocalPlayer`'s rotation (`setXRot`/`setYRot`) and calls the real `applyInput` (the shell player overrides only `isControlledCamera`, because the mocked `Minecraft` has no game renderer). Both sides print `xBob yBob xBobO yBobO` on every tick line. Added turning scenarios (smooth turns, snaps, yaw past ±180 and multiples of 360, pitch at ±90) and random turns in the random cases. **4,194 cases match the pinned client (382,070 output lines; about 120k distinct bob pairs compared).** - Seen in the game on the virtual screen: right after a 90° turn the arm sits further left, then settles back. - `cargo fmt --check`, `cargo clippy --workspace --all-targets -D warnings` and `cargo test --workspace` pass; `tools/check_public_tree.py` passes. ## Left open - The off-hand item is still not drawn in first person (unchanged by this PR); it will get the same rotation once it is, because the sway is in the shared base transform. Fixes #66 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 15:54:52 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#2314
No description provided.