[PR #3448] [MERGED] Creative inventory tab: click locally on a server, as vanilla does (#3307) #4985

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

📋 Pull Request Information

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

Base: main ← Head: fix-3307


📝 Commits (1)

  • dbb03a4 Creative inventory tab: click locally on a server, as vanilla does (#3307)

📊 Changes

3 files changed (+149 additions, -23 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+9 -1)
📝 crates/horizon-client/src/game/lan_actions.rs (+3 -0)
📝 crates/horizon-client/src/game/remote.rs (+137 -22)

📄 Description

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

What and why

Fixes #3307

On a server, including single player's server thread, the creative screen's Survival Inventory tab sent its slot clicks to the server as ContainerClick. The server then held the picked-up stack on its own cursor. The Destroy Item slot only cleared the client's copy, so the stack came back on the next click on the slot, or when the screen closed. The same mismatch duplicated stacks in other ways too:

  • moving a stack from one slot to another doubled it;
  • a stack thrown out of the window came back;
  • closing with a stack on the cursor doubled it.

Vanilla's tab never sends a ContainerClick. This PR makes Horizon do the same:

  • Clicks stay on the client. remote_click on the creative screen runs the click on the client's own inventory menu, the same verified menu engine the item tabs and the in-frame path already use. The changed slots go out through the existing SetCreativeModeSlot sync. A Shift double click on the creative screen also quick-moves on the client.
  • Q and Ctrl+Q over a slot of the tab drop the stack. The thrown stack is sent to the server as a SetCreativeModeSlot to slot -1. Before, the menu engine's drop was thrown away because it was treated as a prediction, so the item vanished.
  • Armour reaches the server. The creative slot sync now covers the armour slots (InventoryMenu 5..=8). Before, it covered only the 36 inventory slots and the off hand, and armour placed through the tab only worked because of the ContainerClicks.
  • No echo of a slot the client just set. The server marks a slot it received from SetCreativeModeSlot as already sent, as vanilla's setRemoteSlot does. Before, it echoed every such slot back, and the echo could land after a newer click.
  • A server slot packet only marks its own slot as synced. On the client, a slot packet from the server used to mark every slot as synced, which could leave a click made since unsent. Clicks a tick apart lost the helmet this way during testing, before this change.

Vanilla reference

I read the 26.3 client.jar with javap -c -p:

  • CreativeModeInventoryScreen.slotClicked, Survival Inventory tab (CreativeModeTab.Type.INVENTORY):
    • Destroy Item slot: only menu.setCarried(ItemStack.EMPTY).
    • Shift-click on the Destroy Item slot: every inventoryMenu slot is set to empty and sent with handleCreativeModeItemAdd.
    • THROW on a slot: Slot.remove, then LocalPlayer.drop(..., PREDICTED), handleCreativeModeItemDrop(dropped), and handleCreativeModeItemAdd(remaining, slot).
    • THROW at -999 (a PICKUP outside the window becomes THROW): the whole carried stack is dropped through handleCreativeModeItemDrop.
    • Anything else: player.inventoryMenu.clicked(...) and broadcastChanges() on the client. No ContainerClick is sent.
  • CreativeInventoryListener: added to inventoryMenu in init and removed in removed(). It sends every changed slot through MultiPlayerGameMode.handleCreativeModeItemAdd, the armour slots included.
  • ItemPickerMenu.getCarried / setCarried: both go to the player's inventoryMenu, so the carried stack is the client's own.
  • ServerGamePacketListenerImpl.handleSetCreativeModeSlot: getSlot(slot).setByPlayer(stack), then inventoryMenu.setRemoteSlot(slot, stack), then broadcastChanges(), so nothing is echoed. A slot below 0 goes to player.drop(stack, true, PREDICTED), limited by dropSpamThrottler.

Self-check

Run on Windows 11 with CARGO_TARGET_DIR set. I did not run tools/pr_ready.py itself: its integration tests open listening sockets, and every new test binary path brings up a firewall prompt here.

cargo fmt --all -- --check                                                     ok
cargo clippy -p horizon-client --features mods --all-targets -- -D warnings    ok
cargo test -p horizon-client --features mods --bins                            141 passed, 3 ignored; 18 passed

New unit tests in game/remote.rs:

  • the_creative_sync_covers_inventory_menu_slots_5_to_45_once_each: every synced entry goes to the InventoryMenu slot that holds that stack (checked through Game::menu_slot), and together they cover 5..=45 exactly once.
  • a_server_slot_update_leaves_an_unsent_creative_click_to_be_sent: a server slot packet marks only its own slot as synced.

Both fail with the old logic, which had no armour entries and marked every slot as synced. I checked this by putting that logic back temporarily. The first fails with left: [9..=45] and right: [5..=45].

The full bug can't be unit-tested: it is in Game's routing between the client and the server. I checked it in game instead.

In game

Setup:

  • a new creative world on the default server thread, Windows 11, RTX 5080;
  • --profile fast --features mods;
  • pauseOnLostFocus:false.

A horizon-ctl script drives the real mouse and keys (click-at, key) on the Survival Inventory tab. After each step it compares:

  • the client's inventory;
  • the server's view, from clear @s ITEM 0 (which also counts the server's cursor), execute if items entity @s armor.head|weapon.offhand and execute if entity @e[type=item].

At the end it quits, reopens the world and reads the saved inventory.

The table shows the client's count and the server's count (client / server).

Case main (791d8b895) this PR
Pick up 10 diamonds, put them in another slot 10 / 20 10 / 10
Pick up, then Destroy Item 0 / 10 0 / 0
...then click the emptied slot again 10 come back nothing
Shift-click Destroy Item, with a helmet and a shield equipped helmet stays on the server everything 0 / 0
Q, then Ctrl+Q over a 10-diamond slot 9 / 19, no item entity 9 / 9 with 1 dropped, then 0 / 0 with 1 + 9 dropped
Left click outside with 10 diamonds, right click outside with 10 emeralds dropped and kept on the server (10 / 10 emeralds) dropped 10 + 10, 0 / 0
Helmet to the head slot, shield to the off hand the server loses the helmet, shield 1 / 2 the server's head and off-hand slots are set; taken back: 1 / 1 each
Close with E with 10 on the cursor (Horizon puts them back) 10 / 20 10 / 10
Close with Esc with 10 on the cursor (deleted, as vanilla does) 0 / 10 0 / 0
20 clicks a tick apart (armour, off hand, a right-click split) not run client = server for everything: 5 diamonds in slot 0 and 5 in slot 20, the gold, the helmet on the head, the shield in slot 12
Reopen the world after moving diamonds to slot 20 and destroying gold 10 diamonds in slot 20, no gold

On main the reopened world kept the doubled stacks.

The in-frame path (HORIZON_SERVER_THREAD=0) doesn't take the changed code, and its client counts are unchanged.

Screenshots

Before: after Destroy Item, a click on the emptied hotbar slot brings the 10 diamonds back. After: the slot stays empty.

Destroy Item clicked a second time, before and after (the red chat lines are the test's own execute if items / clear @s X 0 checks reporting what the server holds):

before
after

A stack picked up and placed, then the world reopened, before and after:

before
after

🤖 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/3448 **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-3307` --- ### 📝 Commits (1) - [`dbb03a4`](https://github.com/horizon-rust/horizon/commit/dbb03a42d3dda5157c030087b1e999ca8fa4a760) Creative inventory tab: click locally on a server, as vanilla does (#3307) ### 📊 Changes **3 files changed** (+149 additions, -23 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+9 -1) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+3 -0) 📝 `crates/horizon-client/src/game/remote.rs` (+137 -22) </details> ### 📄 Description > 🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando themselves. ## What and why Fixes #3307 On a server, including single player's server thread, the creative screen's Survival Inventory tab sent its slot clicks to the server as `ContainerClick`. The server then held the picked-up stack on its own cursor. The Destroy Item slot only cleared the client's copy, so the stack came back on the next click on the slot, or when the screen closed. The same mismatch duplicated stacks in other ways too: - moving a stack from one slot to another doubled it; - a stack thrown out of the window came back; - closing with a stack on the cursor doubled it. Vanilla's tab never sends a `ContainerClick`. This PR makes Horizon do the same: - **Clicks stay on the client.** `remote_click` on the creative screen runs the click on the client's own inventory menu, the same verified menu engine the item tabs and the in-frame path already use. The changed slots go out through the existing `SetCreativeModeSlot` sync. A Shift double click on the creative screen also quick-moves on the client. - **Q and Ctrl+Q over a slot of the tab drop the stack.** The thrown stack is sent to the server as a `SetCreativeModeSlot` to slot -1. Before, the menu engine's drop was thrown away because it was treated as a prediction, so the item vanished. - **Armour reaches the server.** The creative slot sync now covers the armour slots (InventoryMenu 5..=8). Before, it covered only the 36 inventory slots and the off hand, and armour placed through the tab only worked because of the `ContainerClick`s. - **No echo of a slot the client just set.** The server marks a slot it received from `SetCreativeModeSlot` as already sent, as vanilla's `setRemoteSlot` does. Before, it echoed every such slot back, and the echo could land after a newer click. - **A server slot packet only marks its own slot as synced.** On the client, a slot packet from the server used to mark every slot as synced, which could leave a click made since unsent. Clicks a tick apart lost the helmet this way during testing, before this change. ## Vanilla reference I read the 26.3 `client.jar` with `javap -c -p`: - **`CreativeModeInventoryScreen.slotClicked`**, Survival Inventory tab (`CreativeModeTab.Type.INVENTORY`): - Destroy Item slot: only `menu.setCarried(ItemStack.EMPTY)`. - Shift-click on the Destroy Item slot: every `inventoryMenu` slot is set to empty and sent with `handleCreativeModeItemAdd`. - THROW on a slot: `Slot.remove`, then `LocalPlayer.drop(..., PREDICTED)`, `handleCreativeModeItemDrop(dropped)`, and `handleCreativeModeItemAdd(remaining, slot)`. - THROW at -999 (a PICKUP outside the window becomes THROW): the whole carried stack is dropped through `handleCreativeModeItemDrop`. - Anything else: `player.inventoryMenu.clicked(...)` and `broadcastChanges()` on the client. No `ContainerClick` is sent. - **`CreativeInventoryListener`**: added to `inventoryMenu` in `init` and removed in `removed()`. It sends every changed slot through `MultiPlayerGameMode.handleCreativeModeItemAdd`, the armour slots included. - **`ItemPickerMenu.getCarried` / `setCarried`**: both go to the player's `inventoryMenu`, so the carried stack is the client's own. - **`ServerGamePacketListenerImpl.handleSetCreativeModeSlot`**: `getSlot(slot).setByPlayer(stack)`, then `inventoryMenu.setRemoteSlot(slot, stack)`, then `broadcastChanges()`, so nothing is echoed. A slot below 0 goes to `player.drop(stack, true, PREDICTED)`, limited by `dropSpamThrottler`. ## Self-check Run on Windows 11 with `CARGO_TARGET_DIR` set. I did not run `tools/pr_ready.py` itself: its integration tests open listening sockets, and every new test binary path brings up a firewall prompt here. ``` cargo fmt --all -- --check ok cargo clippy -p horizon-client --features mods --all-targets -- -D warnings ok cargo test -p horizon-client --features mods --bins 141 passed, 3 ignored; 18 passed ``` New unit tests in `game/remote.rs`: - **`the_creative_sync_covers_inventory_menu_slots_5_to_45_once_each`**: every synced entry goes to the InventoryMenu slot that holds that stack (checked through `Game::menu_slot`), and together they cover 5..=45 exactly once. - **`a_server_slot_update_leaves_an_unsent_creative_click_to_be_sent`**: a server slot packet marks only its own slot as synced. Both fail with the old logic, which had no armour entries and marked every slot as synced. I checked this by putting that logic back temporarily. The first fails with `left: [9..=45]` and `right: [5..=45]`. The full bug can't be unit-tested: it is in `Game`'s routing between the client and the server. I checked it in game instead. ## In game **Setup:** - a new creative world on the default server thread, Windows 11, RTX 5080; - `--profile fast --features mods`; - `pauseOnLostFocus:false`. A horizon-ctl script drives the real mouse and keys (`click-at`, `key`) on the Survival Inventory tab. After each step it compares: - the client's `inventory`; - the server's view, from `clear @s ITEM 0` (which also counts the server's cursor), `execute if items entity @s armor.head|weapon.offhand` and `execute if entity @e[type=item]`. At the end it quits, reopens the world and reads the saved inventory. The table shows the client's count and the server's count (client / server). | Case | main (791d8b895) | this PR | |---|---|---| | Pick up 10 diamonds, put them in another slot | 10 / **20** | 10 / 10 | | Pick up, then Destroy Item | 0 / **10** | 0 / 0 | | ...then click the emptied slot again | **10 come back** | nothing | | Shift-click Destroy Item, with a helmet and a shield equipped | helmet **stays on the server** | everything 0 / 0 | | Q, then Ctrl+Q over a 10-diamond slot | 9 / 19, **no item entity** | 9 / 9 with 1 dropped, then 0 / 0 with 1 + 9 dropped | | Left click outside with 10 diamonds, right click outside with 10 emeralds | dropped **and** kept on the server (10 / 10 emeralds) | dropped 10 + 10, 0 / 0 | | Helmet to the head slot, shield to the off hand | the server loses the helmet, shield 1 / **2** | the server's head and off-hand slots are set; taken back: 1 / 1 each | | Close with E with 10 on the cursor (Horizon puts them back) | 10 / **20** | 10 / 10 | | Close with Esc with 10 on the cursor (deleted, as vanilla does) | 0 / **10** | 0 / 0 | | 20 clicks a tick apart (armour, off hand, a right-click split) | not run | client = server for everything: 5 diamonds in slot 0 and 5 in slot 20, the gold, the helmet on the head, the shield in slot 12 | | Reopen the world after moving diamonds to slot 20 and destroying gold | | 10 diamonds in slot 20, no gold | On main the reopened world kept the doubled stacks. The in-frame path (`HORIZON_SERVER_THREAD=0`) doesn't take the changed code, and its client counts are unchanged. ## Screenshots Before: after Destroy Item, a click on the emptied hotbar slot brings the 10 diamonds back. After: the slot stays empty. Destroy Item clicked a second time, before and after (the red chat lines are the test's own `execute if items` / `clear @s X 0` checks reporting what the server holds): ![before](https://raw.githubusercontent.com/d3grando/horizon/pr-assets/creative-3307-destroy-clicked-again-before.png) ![after](https://raw.githubusercontent.com/d3grando/horizon/pr-assets/creative-3307-destroy-clicked-again-after.png) A stack picked up and placed, then the world reopened, before and after: ![before](https://raw.githubusercontent.com/d3grando/horizon/pr-assets/creative-3307-place-open-before.png) ![after](https://raw.githubusercontent.com/d3grando/horizon/pr-assets/creative-3307-place-open-after.png) 🤖 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:24 +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#4985
No description provided.