[PR #999] [MERGED] Server: a right click with an item on a block uses it once #2974

Closed
opened 2026-11-02 16:00:32 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: fix/guest-use-item-on


📝 Commits (1)

  • ca1e3a1 Server: a right click with an item on a block uses it once

📊 Changes

6 files changed (+306 additions, -62 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+67 -33)
📝 crates/horizon-client/src/game/end.rs (+4 -0)
📝 crates/horizon-client/src/game/lan_actions.rs (+12 -6)
📝 crates/horizon-client/src/game/remote.rs (+169 -22)
📝 mods/horizon/src/test/java/dev/horizonlab/parity/VanillaProtocolClient.java (+49 -0)
📝 tools/test_dedicated_server_parity.py (+5 -1)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

Part of #484: "an item used on a block is used twice".

What was wrong

A vanilla client sends one right click as up to four packets (Minecraft.startUseItem):

  1. UseItemOn(main): the block's part and ItemStack.useOn.
  2. UseItem(main), when that passed: Item.use.
  3. UseItemOn(off), then UseItem(off), when the main hand passed both.

Horizon's server ran the whole click for UseItemOn, with both hands, including Item.use. It then ran the item again for UseItem, again with both hands. A snowball thrown at the ground flew twice from the main hand and three times from the off hand. Buckets, potions, eggs, pearls and anything else with a use did the same.

What changed

  • Server (game.rs use_item_as_player / use_hand, game/lan_actions.rs). Each packet now does its own part with its own hand, as ServerGamePacketListenerImpl.handleUseItemOn / handleUseItem do. The old lan_item_only flag becomes guest_use: Option<GuestUse>, either OnBlock(hand) or Item(hand).
    • UseItemOn stops at useOn. It no longer throws, drinks, eats, raises a shield, equips or uses a bucket, and an ender eye only fills a frame.
    • Neither packet touches entities: Interact does that.
  • Horizon's own client on a server (game/remote.rs). It used to send only the main hand's packets and counted on the server to try the off hand. It now follows vanilla's order:
    • When the main hand's useItemOn and useItem pass, it sends the off hand's UseItemOn and UseItem. Example: a torch in the off hand while holding a pickaxe.
    • Whether the block takes the click is worked out the way vanilla's client predicts it: BlockState.useItemOn runs on a throwaway copy of the level (DryLevel, writes dropped). A door or chest therefore ends the click. Before, it was followed by a UseItem, so opening a chest with a snowball in hand also threw it.
    • Whether Item.use acts is a guess (item_has_use: food, equipment, shields, throwables, bows, buckets, boats…). Tools and materials pass to the off hand.

Tested

New case in tools/test_dedicated_server_parity.py, a vanilla-codec client against a vanilla server and Horizon's dedicated server. The client right-clicks the ground with a snowball in the main hand, then with only one in the off hand, sending exactly what the 26.3 client sends. It counts the snowballs the server spawns.

  • On main:
    -play-use main hand on a block: 1 snowball(s)
    -play-use off hand on a block: 1 snowball(s)
    +play-use main hand on a block: 2 snowball(s)
    +play-use off hand on a block: 3 snowball(s)
    
  • With this PR: the transcripts are identical. This ran on an integration commit with #998, #1000 and #1001: dedicated server: 604 transcript lines identical.

tools/lan_e2e.py runs a Horizon guest on a Horizon host, so it covers the client half. On the same integration build these checks pass: pvp chest crafting containers machines swings eat sign. swings is the guest tilling with a hoe through the server's UseItemOn, chest / containers / machines are blocks that take the click, and eat is a UseItem.

Self-check

On one integration build of the four #484 PRs (#998, #999, #1000, #1001), on main at dbfaf2e0. The branches sit on ee59df13, which adds only #980's renderer change, which none of them touch:

cargo fmt --all -- --check                                ok (each branch too)
cargo clippy --workspace --all-targets -- -D warnings     ok
cargo test -p horizon-client                              ok: 920 + 77 + 15 + 2 + 2 + 2 + 1 passed, 0 failed
tools/test_dedicated_server_parity.py                     dedicated server: 604 transcript lines identical
tools/lan_e2e.py --check pvp chest crafting containers machines swings eat sign   all pass
tools/lan_e2e.py --check effects recipes projectiles                              all pass

Nothing needs Ludovic.

🤖 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/999 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/19/2026 **Status:** ✅ Merged **Merged:** 10/19/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/guest-use-item-on` --- ### 📝 Commits (1) - [`ca1e3a1`](https://github.com/horizon-rust/horizon/commit/ca1e3a17c845473d10958050084c0c5f284efcea) Server: a right click with an item on a block uses it once ### 📊 Changes **6 files changed** (+306 additions, -62 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+67 -33) 📝 `crates/horizon-client/src/game/end.rs` (+4 -0) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+12 -6) 📝 `crates/horizon-client/src/game/remote.rs` (+169 -22) 📝 `mods/horizon/src/test/java/dev/horizonlab/parity/VanillaProtocolClient.java` (+49 -0) 📝 `tools/test_dedicated_server_parity.py` (+5 -1) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Part of #484: "an item used on a block is used twice". ## What was wrong A vanilla client sends one right click as up to four packets (`Minecraft.startUseItem`): 1. `UseItemOn(main)`: the block's part and `ItemStack.useOn`. 2. `UseItem(main)`, when that passed: `Item.use`. 3. `UseItemOn(off)`, then `UseItem(off)`, when the main hand passed both. Horizon's server ran the whole click for `UseItemOn`, with both hands, including `Item.use`. It then ran the item again for `UseItem`, again with both hands. A snowball thrown at the ground flew twice from the main hand and three times from the off hand. Buckets, potions, eggs, pearls and anything else with a use did the same. ## What changed - **Server** (`game.rs` `use_item_as_player` / `use_hand`, `game/lan_actions.rs`). Each packet now does its own part with its own hand, as `ServerGamePacketListenerImpl.handleUseItemOn` / `handleUseItem` do. The old `lan_item_only` flag becomes `guest_use: Option<GuestUse>`, either `OnBlock(hand)` or `Item(hand)`. - `UseItemOn` stops at `useOn`. It no longer throws, drinks, eats, raises a shield, equips or uses a bucket, and an ender eye only fills a frame. - Neither packet touches entities: `Interact` does that. - **Horizon's own client on a server** (`game/remote.rs`). It used to send only the main hand's packets and counted on the server to try the off hand. It now follows vanilla's order: - When the main hand's `useItemOn` and `useItem` pass, it sends the off hand's `UseItemOn` and `UseItem`. Example: a torch in the off hand while holding a pickaxe. - Whether the block takes the click is worked out the way vanilla's client predicts it: `BlockState.useItemOn` runs on a throwaway copy of the level (`DryLevel`, writes dropped). A door or chest therefore ends the click. Before, it was followed by a `UseItem`, so opening a chest with a snowball in hand also threw it. - Whether `Item.use` acts is a guess (`item_has_use`: food, equipment, shields, throwables, bows, buckets, boats…). Tools and materials pass to the off hand. ## Tested New case in `tools/test_dedicated_server_parity.py`, a vanilla-codec client against a vanilla server and Horizon's dedicated server. The client right-clicks the ground with a snowball in the main hand, then with only one in the off hand, sending exactly what the 26.3 client sends. It counts the snowballs the server spawns. - **On main:** ``` -play-use main hand on a block: 1 snowball(s) -play-use off hand on a block: 1 snowball(s) +play-use main hand on a block: 2 snowball(s) +play-use off hand on a block: 3 snowball(s) ``` - **With this PR:** the transcripts are identical. This ran on an integration commit with #998, #1000 and #1001: `dedicated server: 604 transcript lines identical`. `tools/lan_e2e.py` runs a Horizon guest on a Horizon host, so it covers the client half. On the same integration build these checks pass: `pvp chest crafting containers machines swings eat sign`. `swings` is the guest tilling with a hoe through the server's `UseItemOn`, `chest` / `containers` / `machines` are blocks that take the click, and `eat` is a `UseItem`. ## Self-check On one integration build of the four #484 PRs (#998, #999, #1000, #1001), on main at dbfaf2e0. The branches sit on ee59df13, which adds only #980's renderer change, which none of them touch: ``` cargo fmt --all -- --check ok (each branch too) cargo clippy --workspace --all-targets -- -D warnings ok cargo test -p horizon-client ok: 920 + 77 + 15 + 2 + 2 + 2 + 1 passed, 0 failed tools/test_dedicated_server_parity.py dedicated server: 604 transcript lines identical tools/lan_e2e.py --check pvp chest crafting containers machines swings eat sign all pass tools/lan_e2e.py --check effects recipes projectiles all pass ``` Nothing needs Ludovic. 🤖 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 16:00:32 +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#2974
No description provided.