[PR #3445] [MERGED] Spectators open chests and other containers, read-only #4984

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

📋 Pull Request Information

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

Base: main ← Head: fix-3414


📝 Commits (1)

  • 99b6b8f Spectators open chests and other containers, read-only

📊 Changes

7 files changed (+183 additions, -6 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+8 -1)
📝 crates/horizon-client/src/game/lan_actions.rs (+0 -3)
📝 crates/horizon-client/src/game/lan_crafting.rs (+3 -0)
📝 crates/horizon-client/src/game/remote.rs (+8 -1)
📝 crates/horizon-client/src/game/storage.rs (+45 -0)
📝 crates/horizon-client/src/lan/containers.rs (+25 -1)
📝 crates/horizon-client/tests/lan_bot.rs (+94 -0)

📄 Description

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

What and why

Fixes #3414

In vanilla a spectator can right-click a chest and look inside without touching anything. In Horizon nothing happened. The client predicted the use like any player's, and the server ignored a spectator's UseItemOn (lan_actions.rs: if spectator { return; }). "Loaded" in the report means a chest that already holds items: the reporter filled it in survival or creative, switched to spectator, and couldn't open it.

This follows vanilla's three steps:

  • Client (remote_use_item_on): MultiPlayerGameMode.performUseItemOn returns CONSUME for a spectator before any prediction. The spectator's use is sent, nothing is predicted (no door or lever flips on the spectator's screen), and the click ends there without a swing or an off-hand turn.
  • Server (use_item_as_player → new Game::spectator_open_menu): ServerPlayerGameMode.useItemOn's spectator branch opens BlockState.getMenuProvider and does nothing else. No lid, lid sound or container_open game event (ChestBlockEntity.startOpen and ContainerOpenersCounter skip spectators), and no stat, piglin anger or shulker room check (those belong to useWithoutItem, which this branch never calls). A chest blocked from above is still not opened (ChestBlock.getMenuProvider returns null).
  • Clicks (Hub::container_click, lan_machine_click): ServerGamePacketListenerImpl.handleContainerClick changes nothing for a spectator and calls sendAllDataToRemote. Horizon already ignored those clicks but sent nothing back, so the items the client had predicted stayed moved on its screen. The new Hub::resend_menu sends the menu's contents and the carried stack again.

Scope: the blocks that open are the ones whose menus go through the hub's container path, which now resyncs: chests, trapped chests, barrels, shulker boxes, hoppers, dispensers, droppers, the furnaces, the brewing stand and the crafter. Vanilla also opens workstations, beacons, lecterns with a book and the enchanting table for spectators, and teleports them through portals (useItemOn's Portal branch). Those menus are handled elsewhere (lan_stations.rs, lan_crafting.rs, lecterns), and their click and button handlers would each need the same spectator check and resync, so they are left for a follow-up. Two other things this doesn't change:

  • Unopened loot chests. Horizon rolls a loot table when the chunk loads (save.rs, roll_loaded_loot), so it has no "loot not generated yet" state. A spectator therefore sees the loot of a chest nobody has opened, where vanilla shows container.spectatorCantOpen (RandomizableContainerBlockEntity.canOpen).
  • The in-frame path (--in-frame): it has no server step, so spectators still can't open containers there.

Vanilla reference

From javap -c on the 26.3 client.jar:

  • MultiPlayerGameMode.performUseItemOn (spectator → InteractionResult.CONSUME)
  • ServerPlayerGameMode.useItemOn (spectator → BlockState.getMenuProvider → ServerPlayer.openMenu)
  • ServerPlayer.openMenu
  • ChestBlock.getMenuProvider
  • ChestBlockEntity.startOpen / stopOpen (isSpectator)
  • RandomizableContainerBlockEntity.canOpen / createMenu
  • ServerGamePacketListenerImpl.handleContainerClick (isSpectator → AbstractContainerMenu.sendAllDataToRemote)

No parity harness covers spectator menus. The new lan_bot test a_spectators_container_click_is_taken_back drives a real hub with a protocol bot: a spectator's pickup click on a chest leaves the chest and the carried stack unchanged, and the client gets the full contents again. Without the resync it fails, because the bot never gets the contents again.

Self-check

Run on Windows 11. tools/pr_ready.py was not run; these are the steps it runs:

cargo fmt --all -- --check                                                    ok
cargo clippy -p horizon-client --features mods --all-targets -- -D warnings   ok
cargo test -p horizon-client --test lan_bot                                   6 passed (the new test fails without the resync)
cargo test -p horizon-client --bins                                           156 passed
cargo test -p horizon-client --lib lan::                                      52 passed
cargo test -p horizon-client --lib -- menu:: containers:: storage             16 passed
(the full --lib run stalled on this machine under full CPU load and was stopped; CI runs it)

In game (server thread, the default): a creative player fills a chest with diamonds and golden apples, then switches to spectator.

  • Before: a right-click does nothing.
  • After: the chest opens with its items. Clicking or shift-clicking the diamonds leaves them in the chest (horizon-ctl container and menu show them unchanged, and nothing is carried). The lid stays shut (lid 0.0) while the spectator looks in, and opens (1.0) for a creative player.

Screenshots

Before (origin/main): a spectator right-clicks a filled chest; no menu opens.
spectator 3414 before

After: the chest's menu opens for the spectator, read-only.
spectator 3414 after
spectator 3414 click

Not covered here either: copper chests (every oxidation and waxed state) aren't in the spectator list, although vanilla's CopperChestBlock extends ChestBlock; a one-line follow-up.

🤖 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/3445 **Author:** [@d3grando](https://github.com/d3grando) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/29/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix-3414` --- ### 📝 Commits (1) - [`99b6b8f`](https://github.com/horizon-rust/horizon/commit/99b6b8f3e87b0ecffa7f26d48746841e28f7d1f4) Spectators open chests and other containers, read-only ### 📊 Changes **7 files changed** (+183 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+8 -1) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+0 -3) 📝 `crates/horizon-client/src/game/lan_crafting.rs` (+3 -0) 📝 `crates/horizon-client/src/game/remote.rs` (+8 -1) 📝 `crates/horizon-client/src/game/storage.rs` (+45 -0) 📝 `crates/horizon-client/src/lan/containers.rs` (+25 -1) 📝 `crates/horizon-client/tests/lan_bot.rs` (+94 -0) </details> ### 📄 Description > 🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando themselves. ## What and why Fixes #3414 In vanilla a spectator can right-click a chest and look inside without touching anything. In Horizon nothing happened. The client predicted the use like any player's, and the server ignored a spectator's `UseItemOn` (`lan_actions.rs`: `if spectator { return; }`). "Loaded" in the report means a chest that already holds items: the reporter filled it in survival or creative, switched to spectator, and couldn't open it. This follows vanilla's three steps: - **Client** (`remote_use_item_on`): `MultiPlayerGameMode.performUseItemOn` returns `CONSUME` for a spectator before any prediction. The spectator's use is sent, nothing is predicted (no door or lever flips on the spectator's screen), and the click ends there without a swing or an off-hand turn. - **Server** (`use_item_as_player` → new `Game::spectator_open_menu`): `ServerPlayerGameMode.useItemOn`'s spectator branch opens `BlockState.getMenuProvider` and does nothing else. No lid, lid sound or `container_open` game event (`ChestBlockEntity.startOpen` and `ContainerOpenersCounter` skip spectators), and no stat, piglin anger or shulker room check (those belong to `useWithoutItem`, which this branch never calls). A chest blocked from above is still not opened (`ChestBlock.getMenuProvider` returns null). - **Clicks** (`Hub::container_click`, `lan_machine_click`): `ServerGamePacketListenerImpl.handleContainerClick` changes nothing for a spectator and calls `sendAllDataToRemote`. Horizon already ignored those clicks but sent nothing back, so the items the client had predicted stayed moved on its screen. The new `Hub::resend_menu` sends the menu's contents and the carried stack again. Scope: the blocks that open are the ones whose menus go through the hub's container path, which now resyncs: chests, trapped chests, barrels, shulker boxes, hoppers, dispensers, droppers, the furnaces, the brewing stand and the crafter. Vanilla also opens workstations, beacons, lecterns with a book and the enchanting table for spectators, and teleports them through portals (`useItemOn`'s `Portal` branch). Those menus are handled elsewhere (`lan_stations.rs`, `lan_crafting.rs`, lecterns), and their click and button handlers would each need the same spectator check and resync, so they are left for a follow-up. Two other things this doesn't change: - **Unopened loot chests.** Horizon rolls a loot table when the chunk loads (`save.rs`, `roll_loaded_loot`), so it has no "loot not generated yet" state. A spectator therefore sees the loot of a chest nobody has opened, where vanilla shows `container.spectatorCantOpen` (`RandomizableContainerBlockEntity.canOpen`). - **The in-frame path** (`--in-frame`): it has no server step, so spectators still can't open containers there. ## Vanilla reference From `javap -c` on the 26.3 `client.jar`: - `MultiPlayerGameMode.performUseItemOn` (spectator → `InteractionResult.CONSUME`) - `ServerPlayerGameMode.useItemOn` (spectator → `BlockState.getMenuProvider` → `ServerPlayer.openMenu`) - `ServerPlayer.openMenu` - `ChestBlock.getMenuProvider` - `ChestBlockEntity.startOpen` / `stopOpen` (`isSpectator`) - `RandomizableContainerBlockEntity.canOpen` / `createMenu` - `ServerGamePacketListenerImpl.handleContainerClick` (`isSpectator` → `AbstractContainerMenu.sendAllDataToRemote`) No parity harness covers spectator menus. The new `lan_bot` test `a_spectators_container_click_is_taken_back` drives a real hub with a protocol bot: a spectator's pickup click on a chest leaves the chest and the carried stack unchanged, and the client gets the full contents again. Without the resync it fails, because the bot never gets the contents again. ## Self-check Run on Windows 11. `tools/pr_ready.py` was not run; these are the steps it runs: ``` cargo fmt --all -- --check ok cargo clippy -p horizon-client --features mods --all-targets -- -D warnings ok cargo test -p horizon-client --test lan_bot 6 passed (the new test fails without the resync) cargo test -p horizon-client --bins 156 passed cargo test -p horizon-client --lib lan:: 52 passed cargo test -p horizon-client --lib -- menu:: containers:: storage 16 passed (the full --lib run stalled on this machine under full CPU load and was stopped; CI runs it) ``` In game (server thread, the default): a creative player fills a chest with diamonds and golden apples, then switches to spectator. - **Before:** a right-click does nothing. - **After:** the chest opens with its items. Clicking or shift-clicking the diamonds leaves them in the chest (`horizon-ctl container` and `menu` show them unchanged, and nothing is carried). The lid stays shut (`lid` 0.0) while the spectator looks in, and opens (1.0) for a creative player. ## Screenshots Before (origin/main): a spectator right-clicks a filled chest; no menu opens. ![spectator 3414 before](https://raw.githubusercontent.com/d3grando/horizon/pr-assets/spectator-3414-before.png) After: the chest's menu opens for the spectator, read-only. ![spectator 3414 after](https://raw.githubusercontent.com/d3grando/horizon/pr-assets/spectator-3414-after.png) ![spectator 3414 click](https://raw.githubusercontent.com/d3grando/horizon/pr-assets/spectator-3414-click.png) Not covered here either: copper chests (every oxidation and waxed state) aren't in the spectator list, although vanilla's `CopperChestBlock` extends `ChestBlock`; a one-line follow-up. 🤖 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:09:22 +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#4984
No description provided.