[PR #1476] [MERGED] Shields, tridents, crossbows and spyglasses work on a server's players #3552

Closed
opened 2026-11-03 04:10:21 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: fix/st-held-use


📝 Commits (6)

  • b8e729b Totems save a server's players: the guest's turn uses it up, and entity event 35 reaches every client
  • de358cd A server's players drop their inventory on death unless keep_inventory is on
  • 52d8ed6 Signs open their editor on a server's players, and what they write reaches the server
  • 5617d70 Books open on a server's players, and what they write and sign reaches the server
  • 5ed8181 Elytra glides on a server's players: the client sends START_FALL_FLYING and the server checks it
  • ad76f91 Shields, tridents, crossbows and spyglasses end their use on a server: the client starts it too

📊 Changes

17 files changed (+1128 additions, -128 deletions)

View changed files

📝 crates/horizon-client/src/audio.rs (+7 -0)
📝 crates/horizon-client/src/game.rs (+51 -39)
📝 crates/horizon-client/src/game/agent.rs (+7 -0)
📝 crates/horizon-client/src/game/books.rs (+124 -29)
📝 crates/horizon-client/src/game/control.rs (+12 -1)
📝 crates/horizon-client/src/game/lan.rs (+5 -0)
📝 crates/horizon-client/src/game/lan_actions.rs (+129 -7)
📝 crates/horizon-client/src/game/lan_stations.rs (+16 -11)
📝 crates/horizon-client/src/game/remote.rs (+92 -13)
📝 crates/horizon-client/src/game/sign_edit.rs (+86 -4)
📝 crates/horizon-client/src/game/station_control.rs (+1 -1)
📝 crates/horizon-client/src/game/totem.rs (+79 -20)
📝 crates/horizon-client/src/lan/guest.rs (+19 -0)
📝 crates/horizon-client/src/lan/hub.rs (+4 -3)
📝 crates/horizon-protocol/src/item.rs (+26 -0)
📝 crates/horizon-protocol/src/packets/play.rs (+112 -0)
📝 tools/lan_e2e.py (+358 -0)

📄 Description

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

Fixes #1300, #1281, #1282, #1301.

What

For a server's players (LAN guests, and the window's own player when single player runs on the server thread):

  • a shield stops blocking once use is let go;
  • a charged trident is thrown on release;
  • a crossbow charges, shows as loaded, and fires on the next use;
  • a spyglass zooms and shows its scope while held.

Why

All four had one cause. A server's client started its own use (using) only for bows and food. Item.use runs on the client too (MultiPlayerGameMode.useItem calls itemStack.use after sending ServerboundUseItemPacket), and the client lets go only of a use it started: releaseUsingItem sends RELEASE_USE_ITEM. So for these items:

  • the server never heard the release: the shield stayed raised, the trident stayed in hand, and the crossbow stayed "in use", so the next use never fired;
  • the spyglass never scoped.

Two server gaps sat behind that:

  • The release. RELEASE_USE_ITEM only let go of a bow, and only from the main hand.
  • The loaded crossbow. A loaded crossbow reached its client without its ammunition, because the network stack had no minecraft:charged_projectiles component.

How

  • Client (remote_start_held_use): starts the same uses the window's own Item.use does:

    • a bow with ammunition or in creative;
    • an uncharged crossbow with ammunition;
    • a trident (TridentItem.use: not about to break, Riptide only in water or rain);
    • a spyglass;
    • a shield off cooldown.

    remote_tick_using keeps those uses until the button lets go. The sounds, the loading and the shot stay the server's.

  • Server, RELEASE_USE_ITEM (ServerPlayer.releaseUsingItem): runs with the hand of the item in use, through release_used_item, which the window's own tick now shares. A bow or a trident is let go, and a spyglass stops scoping.

  • Protocol. DataComponents.CHARGED_PROJECTILES is registry id 51 (DataComponents.<clinit> order). Its stream codec is ItemStackTemplate.STREAM_CODEC listed (≤1024): item, count, then the patch. Guests now get it, and a server's client decodes it into the crossbow's loaded arrows. A byte-level test pins it.

  • Harness: using per guest in lan status (the item the server has them using).

Evidence

lan_e2e --check helduse, for each player in turn:

  • Shield and spyglass: hold use for 10 ticks, then let go. The check reads using on the client and on the server, while held and after letting go.
  • Trident: hold use for 1.2 s. The check counts the tridents the server still finds in the inventory, and the tridents the thrower's client draws in flight.
  • Crossbow: hold use for 1.6 s, then click once. The check reads whether the client's held crossbow carries charged_projectiles, the arrows left on the server, the arrows the shooter draws, and whether the crossbow is empty again.
in-frame host in-frame guest --server-thread host --server-thread guest
before all work shield and spyglass never in use on the client; trident kept (1 in inventory, 0 thrown); crossbow not loaded on the client, 0 fired same as the in-frame guest same
after all work all work all work all work

In every case after the fix:

  • shield and spyglass: using is set on the client and the server while held, and cleared on both after letting go;
  • trident: 0 left in the inventory, 1 drawn in flight;
  • crossbow: the client shows charged_projectiles, 15 of the 16 arrows are left, 1 arrow is fired, and the crossbow is empty again.

"Before" binaries have no using per guest in lan status, so their server column reads false for guests. The client's own using and the trident and crossbow results are the evidence there.

lan_e2e --check shield, --check arrows and --check eat still pass in both modes with this change.

Not in this PR: /kill finds no thrown trident (Horizon's entity selectors miss self.tridents). That gap is the same in both modes, and the check counts the new tridents instead.

How tested

Self-check on the top of the stack (fix/st-held-use, which contains this PR), Mac mini M4 Pro:

  • cargo fmt --all --check: OK
  • cargo clippy --workspace --all-targets -- -D warnings: OK
  • cargo test -p horizon-protocol: 72 passed. cargo test -p horizon-client --lib: 1061 passed (26 ignored). --bins: 98 + 18 passed.
  • python3 tools/parity.py --changed origin/main: 106 harnesses, 106 passed, 0 failed (105 in the full run, which hit its time limit on a busy machine; the last one, world_spawn#4, then passed on its own with the other three world_spawn cases)
  • tools/lan_e2e.py in both modes (in-frame, then --server-thread), host and guest, as tabled above. Before = origin/main b65e082fd built with the same profile, after = this stack.

Stack

This continues the stack of #1463 (totem) → #1464 (keep_inventory) → #1465 (signs) → #1466 (books). This PR sits on top of #1466 and its change is the top commit. Merge order: #1463 → #1464 → #1465 → #1466 → #1475 (Elytra) → #1476 (held use).

The new lan_e2e checks go at the end of the file, after the stack's block, and leave alone the lines that #1419, #1420 and #1423–#1427 change. git merge-tree is clean against each of #1423–#1427. #1419 and #1420 already conflict with main on their own.

Needs Ludovic

A review and a merge, in stack order. Nothing else.

🤖 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/1476 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/23/2026 **Status:** ✅ Merged **Merged:** 10/24/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/st-held-use` --- ### 📝 Commits (6) - [`b8e729b`](https://github.com/horizon-rust/horizon/commit/b8e729b950284890ec79d11e4bb448e3a3e4782c) Totems save a server's players: the guest's turn uses it up, and entity event 35 reaches every client - [`de358cd`](https://github.com/horizon-rust/horizon/commit/de358cd72127156cd9c27ecd662ee73b86adb113) A server's players drop their inventory on death unless keep_inventory is on - [`52d8ed6`](https://github.com/horizon-rust/horizon/commit/52d8ed6721be9b7db334284f14b0fb271ba13f86) Signs open their editor on a server's players, and what they write reaches the server - [`5617d70`](https://github.com/horizon-rust/horizon/commit/5617d702cc62e676de8c24c4506ad055a62617b8) Books open on a server's players, and what they write and sign reaches the server - [`5ed8181`](https://github.com/horizon-rust/horizon/commit/5ed8181adca456aae7ca081bc8b0acd6e1d5b47b) Elytra glides on a server's players: the client sends START_FALL_FLYING and the server checks it - [`ad76f91`](https://github.com/horizon-rust/horizon/commit/ad76f911bdeff02d524acc0cad0916fc59b23167) Shields, tridents, crossbows and spyglasses end their use on a server: the client starts it too ### 📊 Changes **17 files changed** (+1128 additions, -128 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/audio.rs` (+7 -0) 📝 `crates/horizon-client/src/game.rs` (+51 -39) 📝 `crates/horizon-client/src/game/agent.rs` (+7 -0) 📝 `crates/horizon-client/src/game/books.rs` (+124 -29) 📝 `crates/horizon-client/src/game/control.rs` (+12 -1) 📝 `crates/horizon-client/src/game/lan.rs` (+5 -0) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+129 -7) 📝 `crates/horizon-client/src/game/lan_stations.rs` (+16 -11) 📝 `crates/horizon-client/src/game/remote.rs` (+92 -13) 📝 `crates/horizon-client/src/game/sign_edit.rs` (+86 -4) 📝 `crates/horizon-client/src/game/station_control.rs` (+1 -1) 📝 `crates/horizon-client/src/game/totem.rs` (+79 -20) 📝 `crates/horizon-client/src/lan/guest.rs` (+19 -0) 📝 `crates/horizon-client/src/lan/hub.rs` (+4 -3) 📝 `crates/horizon-protocol/src/item.rs` (+26 -0) 📝 `crates/horizon-protocol/src/packets/play.rs` (+112 -0) 📝 `tools/lan_e2e.py` (+358 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Fixes #1300, #1281, #1282, #1301. ## What For a server's players (LAN guests, and the window's own player when single player runs on the server thread): - a shield stops blocking once use is let go; - a charged trident is thrown on release; - a crossbow charges, shows as loaded, and fires on the next use; - a spyglass zooms and shows its scope while held. ## Why All four had one cause. A server's client started its own use (`using`) only for bows and food. `Item.use` runs on the client too (`MultiPlayerGameMode.useItem` calls `itemStack.use` after sending `ServerboundUseItemPacket`), and the client lets go only of a use it started: `releaseUsingItem` sends `RELEASE_USE_ITEM`. So for these items: - the server never heard the release: the shield stayed raised, the trident stayed in hand, and the crossbow stayed "in use", so the next use never fired; - the spyglass never scoped. Two server gaps sat behind that: - **The release.** `RELEASE_USE_ITEM` only let go of a bow, and only from the main hand. - **The loaded crossbow.** A loaded crossbow reached its client without its ammunition, because the network stack had no `minecraft:charged_projectiles` component. ## How - **Client** (`remote_start_held_use`): starts the same uses the window's own `Item.use` does: - a bow with ammunition or in creative; - an uncharged crossbow with ammunition; - a trident (`TridentItem.use`: not about to break, Riptide only in water or rain); - a spyglass; - a shield off cooldown. `remote_tick_using` keeps those uses until the button lets go. The sounds, the loading and the shot stay the server's. - **Server, `RELEASE_USE_ITEM`** (`ServerPlayer.releaseUsingItem`): runs with the hand of the item in use, through `release_used_item`, which the window's own tick now shares. A bow or a trident is let go, and a spyglass stops scoping. - **Protocol.** `DataComponents.CHARGED_PROJECTILES` is registry id 51 (`DataComponents.<clinit>` order). Its stream codec is `ItemStackTemplate.STREAM_CODEC` listed (≤1024): item, count, then the patch. Guests now get it, and a server's client decodes it into the crossbow's loaded arrows. A byte-level test pins it. - **Harness:** `using` per guest in `lan status` (the item the server has them using). ## Evidence `lan_e2e --check helduse`, for each player in turn: - **Shield and spyglass:** hold use for 10 ticks, then let go. The check reads `using` on the client and on the server, while held and after letting go. - **Trident:** hold use for 1.2 s. The check counts the tridents the server still finds in the inventory, and the tridents the thrower's client draws in flight. - **Crossbow:** hold use for 1.6 s, then click once. The check reads whether the client's held crossbow carries `charged_projectiles`, the arrows left on the server, the arrows the shooter draws, and whether the crossbow is empty again. | | in-frame host | in-frame guest | `--server-thread` host | `--server-thread` guest | |---|---|---|---|---| | **before** | all work | **shield and spyglass never in use on the client; trident kept (1 in inventory, 0 thrown); crossbow not loaded on the client, 0 fired** | **same as the in-frame guest** | **same** | | **after** | all work | all work | all work | all work | In every case after the fix: - shield and spyglass: `using` is set on the client and the server while held, and cleared on both after letting go; - trident: 0 left in the inventory, 1 drawn in flight; - crossbow: the client shows `charged_projectiles`, 15 of the 16 arrows are left, 1 arrow is fired, and the crossbow is empty again. "Before" binaries have no `using` per guest in `lan status`, so their server column reads false for guests. The client's own `using` and the trident and crossbow results are the evidence there. `lan_e2e --check shield`, `--check arrows` and `--check eat` still pass in both modes with this change. Not in this PR: `/kill` finds no thrown trident (Horizon's entity selectors miss `self.tridents`). That gap is the same in both modes, and the check counts the new tridents instead. ## How tested Self-check on the top of the stack (fix/st-held-use, which contains this PR), Mac mini M4 Pro: - `cargo fmt --all --check`: OK - `cargo clippy --workspace --all-targets -- -D warnings`: OK - `cargo test -p horizon-protocol`: 72 passed. `cargo test -p horizon-client --lib`: 1061 passed (26 ignored). `--bins`: 98 + 18 passed. - `python3 tools/parity.py --changed origin/main`: 106 harnesses, 106 passed, 0 failed (105 in the full run, which hit its time limit on a busy machine; the last one, world_spawn#4, then passed on its own with the other three world_spawn cases) - `tools/lan_e2e.py` in both modes (in-frame, then `--server-thread`), host and guest, as tabled above. Before = origin/main b65e082fd built with the same profile, after = this stack. ## Stack This continues the stack of #1463 (totem) → #1464 (keep_inventory) → #1465 (signs) → #1466 (books). This PR sits on top of #1466 and its change is the top commit. Merge order: #1463 → #1464 → #1465 → #1466 → #1475 (Elytra) → #1476 (held use). The new lan_e2e checks go at the end of the file, after the stack's block, and leave alone the lines that #1419, #1420 and #1423–#1427 change. `git merge-tree` is clean against each of #1423–#1427. #1419 and #1420 already conflict with main on their own. ## Needs Ludovic A review and a merge, in stack order. Nothing else. 🤖 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 04:10:21 +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#3552
No description provided.