[PR #4073] [MERGED] Swapping the same item into the off hand plays the re-equip animation #5401

Closed
opened 2026-11-03 05:12:20 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4073
Author: @d3grando
Created: 10/29/2026
Status: ✅ Merged
Merged: 10/30/2026
Merged by: @levzzz5154

Base: main ← Head: fix-2866


📝 Commits (1)

  • 413e6e8 Swapping the same item into the off hand plays the re-equip animation

📊 Changes

3 files changed (+152 additions, -13 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+6 -0)
📝 crates/horizon-client/src/game/hand.rs (+96 -12)
📝 crates/horizon-client/src/game/remote.rs (+50 -1)

📄 Description

🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando personally.

What and why

Pressing F with the same item in both hands but different counts (64 torches in the main hand, 32 in the off hand) swapped the stacks with no re-equip animation. Vanilla lowers both hands and raises them again with the swapped stacks.

Cause: FirstPersonHandsAndItems.shouldInstantlyReplaceVisibleItem keeps the visible item when the held stack is the same ItemStack object, or one that matchesIgnoringComponents accepts. tick_hand approximated "the same object" as "the same slot and the same item", so that stacks shrunk, grown or damaged in place don't re-equip. The off hand's slot never changes, so any stack of the same item swapped into it counted as the same object, whatever its count. The main hand had the same problem after a swap.

Fix:

  • shows_held_stack / matches_for_swap (game/hand.rs) take the comparison out of the loop. A hand whose slot was replaced compares by matchesIgnoringComponents: count, item and components, with damage ignored because DataComponents.DAMAGE is the one component built with ignoreSwapAnimation.
  • Game::hand_stack_replaced marks a hand as holding a new stack. The flag stays set until the hand shows the held stack again, so the whole animation plays.
  • Local game: the F swap marks both hands at once, like setItemInHand.
  • On a server (including the default server thread and LAN guests): remote_swap_hands waits for the slot updates that answer SWAP_ITEM_WITH_OFFHAND, and remote_hand_slot_set marks the hand when one arrives with a different stack.

Other server updates of a hand's slot still count as in-place changes, on purpose. Vanilla's client predicts uses like a thrown snowball (Item.use consumes on both sides). Horizon's remote client doesn't predict that yet, so treating every slot packet as a new object made the hand dip after every throw. I tried it and dropped it.

Fixes #2866

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

  • FirstPersonHandsAndItems.tick and shouldInstantlyReplaceVisibleItem, checked with javap on the 26.3 client jar. The first test is ItemStack.matchesIgnoringComponents(visible, held, DataComponentType::ignoreSwapAnimation), then ItemModelResolver.shouldPlaySwapAnimation.
  • ItemStack.matchesIgnoringComponents: identity first, then count, item and every component except the ones the predicate accepts.
  • DataComponents.<clinit>: damage is the component whose builder calls ignoreSwapAnimation().
  • ServerGamePacketListenerImpl.handlePlayerAction SWAP_ITEM_WITH_OFFHAND (setItemInHand for both hands), and ClientPacketListener.handleContainerSetSlot, which sets the packet's own stack into the slot.
  • Checked by the unit test game::hand::tests::a_swapped_in_stack_of_the_same_item_re_equips. No parity harness covers first-person hand heights.

Self-check

tools/pr_ready.py doesn't run on Windows, which is where this was done, so I ran its steps by hand:

  • cargo fmt --all -- --check: clean
  • cargo clippy -p horizon-client --all-targets -- -D warnings: clean
  • cargo test --profile fast -p horizon-client --bin horizon-client game::hand::tests:
    • with the fix: 3 passed
    • with only shows_held_stack reverted to the old slot-only rule: a_swapped_in_stack_of_the_same_item_re_equips FAILED (assertion failed: !shows_held_stack(&visible, &held, true)), the other 2 passed
  • cargo test --profile fast -p horizon-client --bin horizon-client game::remote: 21 passed

In game, on a build with a temporary log of tick_hand's changed flags and hand heights (removed before the commit):

  • Single player on the server thread, F with 64 / 32 torches:
    • before: no hand changed, both heights stayed at 1.0
    • after: both hands changed, and the heights went 1.0 → 0.6 → 0.2 → 0.0 → 0.4 → 0.8 → 1.0. Swapping back did the same.
  • Unchanged by the fix (no extra animation): placing six torches in survival, throwing two snowballs, and /give growing the held stack.
  • Swords that differ only in damage: they swap at once, as in vanilla.
  • LAN guest (a second game joined over LAN): the same swap plays the full animation on the guest.

Screenshots

before, mid-swap of 64 and 32 torches between the hands: both hands stay up, no animation

after, same moment: both hands dip for the re-equip animation

Single player, 64 torches in the main hand and 32 in the off hand, captured about 150 ms after pressing F:

  • before: both torches stay in place, and only the hotbar counts change.
  • after: both hands are lowered out of view, then come back up with the swapped stacks.

🤖 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/4073 **Author:** [@d3grando](https://github.com/d3grando) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `fix-2866` --- ### 📝 Commits (1) - [`413e6e8`](https://github.com/horizon-rust/horizon/commit/413e6e856e7c9ca16d1b5d2bf6e74888b709f18f) Swapping the same item into the off hand plays the re-equip animation ### 📊 Changes **3 files changed** (+152 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+6 -0) 📝 `crates/horizon-client/src/game/hand.rs` (+96 -12) 📝 `crates/horizon-client/src/game/remote.rs` (+50 -1) </details> ### 📄 Description > 🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando personally. ## What and why Pressing F with the same item in both hands but different counts (64 torches in the main hand, 32 in the off hand) swapped the stacks with no re-equip animation. Vanilla lowers both hands and raises them again with the swapped stacks. Cause: `FirstPersonHandsAndItems.shouldInstantlyReplaceVisibleItem` keeps the visible item when the held stack is the same `ItemStack` object, or one that `matchesIgnoringComponents` accepts. `tick_hand` approximated "the same object" as "the same slot and the same item", so that stacks shrunk, grown or damaged in place don't re-equip. The off hand's slot never changes, so any stack of the same item swapped into it counted as the same object, whatever its count. The main hand had the same problem after a swap. Fix: - `shows_held_stack` / `matches_for_swap` (`game/hand.rs`) take the comparison out of the loop. A hand whose slot was `replaced` compares by `matchesIgnoringComponents`: count, item and components, with damage ignored because `DataComponents.DAMAGE` is the one component built with `ignoreSwapAnimation`. - `Game::hand_stack_replaced` marks a hand as holding a new stack. The flag stays set until the hand shows the held stack again, so the whole animation plays. - Local game: the F swap marks both hands at once, like `setItemInHand`. - On a server (including the default server thread and LAN guests): `remote_swap_hands` waits for the slot updates that answer SWAP_ITEM_WITH_OFFHAND, and `remote_hand_slot_set` marks the hand when one arrives with a different stack. Other server updates of a hand's slot still count as in-place changes, on purpose. Vanilla's client predicts uses like a thrown snowball (`Item.use` consumes on both sides). Horizon's remote client doesn't predict that yet, so treating every slot packet as a new object made the hand dip after every throw. I tried it and dropped it. Fixes #2866 ## Kind - [x] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [ ] perf: faster, or less memory - [ ] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference - `FirstPersonHandsAndItems.tick` and `shouldInstantlyReplaceVisibleItem`, checked with javap on the 26.3 client jar. The first test is `ItemStack.matchesIgnoringComponents(visible, held, DataComponentType::ignoreSwapAnimation)`, then `ItemModelResolver.shouldPlaySwapAnimation`. - `ItemStack.matchesIgnoringComponents`: identity first, then count, item and every component except the ones the predicate accepts. - `DataComponents.<clinit>`: `damage` is the component whose builder calls `ignoreSwapAnimation()`. - `ServerGamePacketListenerImpl.handlePlayerAction` SWAP_ITEM_WITH_OFFHAND (`setItemInHand` for both hands), and `ClientPacketListener.handleContainerSetSlot`, which sets the packet's own stack into the slot. - Checked by the unit test `game::hand::tests::a_swapped_in_stack_of_the_same_item_re_equips`. No parity harness covers first-person hand heights. ## Self-check `tools/pr_ready.py` doesn't run on Windows, which is where this was done, so I ran its steps by hand: - `cargo fmt --all -- --check`: clean - `cargo clippy -p horizon-client --all-targets -- -D warnings`: clean - `cargo test --profile fast -p horizon-client --bin horizon-client game::hand::tests`: - with the fix: 3 passed - with only `shows_held_stack` reverted to the old slot-only rule: `a_swapped_in_stack_of_the_same_item_re_equips` FAILED (`assertion failed: !shows_held_stack(&visible, &held, true)`), the other 2 passed - `cargo test --profile fast -p horizon-client --bin horizon-client game::remote`: 21 passed In game, on a build with a temporary log of `tick_hand`'s `changed` flags and hand heights (removed before the commit): - Single player on the server thread, F with 64 / 32 torches: - before: no hand changed, both heights stayed at 1.0 - after: both hands changed, and the heights went 1.0 → 0.6 → 0.2 → 0.0 → 0.4 → 0.8 → 1.0. Swapping back did the same. - Unchanged by the fix (no extra animation): placing six torches in survival, throwing two snowballs, and `/give` growing the held stack. - Swords that differ only in damage: they swap at once, as in vanilla. - LAN guest (a second game joined over LAN): the same swap plays the full animation on the guest. ## Screenshots ![before, mid-swap of 64 and 32 torches between the hands: both hands stay up, no animation](https://raw.githubusercontent.com/d3grando/horizon/pr-assets/2866-1.png) ![after, same moment: both hands dip for the re-equip animation](https://raw.githubusercontent.com/d3grando/horizon/pr-assets/2866-2.png) Single player, 64 torches in the main hand and 32 in the off hand, captured about 150 ms after pressing F: - before: both torches stay in place, and only the hotbar counts change. - after: both hands are lowered out of view, then come back up with the swapped stacks. 🤖 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-03 05:12:20 +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#5401
No description provided.