[PR #1467] [MERGED] Bundles take and give items in inventories and containers #3544

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

📋 Pull Request Information

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

Base: main ← Head: fix/bundle-clicks


📝 Commits (4)

  • 7dac46e Bundles take and give items in inventories and containers
  • 8acb467 Bundle clicks: the open menu's slotsChanged for the player's inventory
  • 0b0e4a8 Merge remote-tracking branch 'origin/main' into fix/bundle-clicks
  • cbc4692 Merge remote-tracking branch 'origin/main' into fix/bundle-clicks

📊 Changes

11 files changed (+618 additions, -13 deletions)

View changed files

📝 crates/horizon-client/examples/probe/menu_fixture.rs (+4 -2)
➕ crates/horizon-client/src/bundle.rs (+192 -0)
📝 crates/horizon-client/src/game.rs (+30 -0)
📝 crates/horizon-client/src/game/lan_actions.rs (+3 -0)
📝 crates/horizon-client/src/items.rs (+3 -0)
📝 crates/horizon-client/src/lan/menu.rs (+200 -1)
📝 crates/horizon-client/src/lib.rs (+1 -0)
📝 crates/horizon-client/src/menu.rs (+27 -3)
➕ crates/horizon-client/src/menu/bundle.rs (+102 -0)
📝 mods/horizon/src/test/java/dev/horizonlab/parity/VanillaMenuOracle.java (+12 -2)
📝 tools/test_menu_click_parity.py (+44 -5)

📄 Description

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

Fixes #1456: with a bundle in hand, clicking a stack swapped the two instead of putting the stack in the bundle.

Vanilla 26.3

AbstractContainerMenu.doClick (PICKUP) first calls tryItemClickBehaviourOverride: the carried stack's overrideStackedOnOther, then the clicked stack's overrideOtherStackedOnMe. BundleItem uses both on BundleContents.Mutable:

  • carried bundle, left click on a stack: tryTransfer takes as much as the remaining weight allows, through slot.safeTake
  • carried bundle, right click on an empty slot: removeOne goes into the slot (safeInsert), and whatever doesn't fit goes back into the bundle
  • left click on a bundle in a slot while holding a stack: tryInsert (needs slot.allowModification)
  • right click on a bundle in a slot with an empty hand: removeOne goes to the cursor
  • weights: 1/max stack size, 1 for a beehive with bees, and for a nested bundle its contents plus 1/16. Shulker boxes never fit. Exact Fraction arithmetic.
  • after either override: broadcastChangesOnContainerMenu, i.e. the open menu's slotsChanged(player inventory); crafting grids, the loom, stonecutter, cartography table and merchant recompute from their inputs
  • sounds at the player: item.bundle.insert / remove_one (0.8, 0.8 + rand x 0.4) and insert_fail (1, 1)

Change

  • horizon_client::bundle: BundleContents.Mutable (tryInsert, removeOne, getMaxAmountToAdd, exact weights). ItemInfo.bundle comes from the default bundle_contents component.
  • menu (the engine behind in-frame menus, server-thread and LAN inventory menus, and client prediction): Menu::pickup runs the two overrides first. Menu.player_sounds holds their sounds, which the game plays at the player. After a bundle click the menu runs slotsChanged for the inventory, as above.
  • lan::menu (the engine for a server's chests, barrels and shulker boxes, used for server-thread and LAN guests): the same overrides.
  • In in-frame single player, a press with an empty hand in the inventory screen went to an older click path and never reached the engine, so a right click on a bundle picked up half of it. It now goes to the engine, as it already did on a server.

Tests

  • tools/test_menu_click_parity.py: bundles are now among the generated stacks (empty, loaded, nested, often the carried stack, from their own RNG so the existing cases don't change), and the player's sounds are compared too (the Java oracle records Player.playSound). On inventory, chests, shulker box, hopper, dispenser and crafting, 3000 cases: 3000/3000 match, against 2796/3000 without the overrides (204 differing PICKUP/QUICK_CRAFT cases). On every menu, 8000 cases: 8000/8000 match, with seed 7 and with seed 11. The run over every menu caught the loom recomputing its result after a bundle click (slotsChanged).

  • lan::menu::tests::guest_chest_clicks_fill_and_empty_bundles (resource-backed) fails without the override and passes with it.

  • In game (Mac mini, Metal, offscreen, real mouse events through horizon-ctl click-at), survival inventory, in-frame and --server-thread give the same results:

    1. carry the bundle and click 32 stone: bundle [32 stone]
    2. click 16 ender pearls: 8 go in, giving [8 pearls, 32 stone]
    3. right click an empty slot: 8 pearls come out
    4. put the bundle down and click it while holding 4 pearls: [4 pearls, 32 stone]
    5. right click it with an empty hand: 4 pearls go to the cursor

    On main, step 1 swaps the bundle and the stone, as reported.

  • Server-thread chest: carry the bundle and click the chest's stone, then right click an empty chest slot. The stone moves in and back out, and is still there after the chest is closed and reopened (server state).

in-frame, after the steps above --server-thread, chest

Not in this PR (follow-ups)

These are vanilla bundle features Horizon still lacks:

  • the contents tooltip (ClientBundleTooltip)
  • the selected item, and scrolling to select it (ServerboundSelectBundleItemPacket). removeOne always takes the first stack, which is what vanilla does when nothing is selected.
  • using a bundle in hand to drop its contents (BundleItem.use)
  • dropping the contents when a bundle item entity is destroyed

Self-check

These checks ran on one integration commit with #1467, #1468, #1469, #1470 and #1471 merged on main (Mac mini):

  • cargo fmt --all -- --check: clean
  • cargo clippy --workspace --all-targets -- -D warnings: clean. The first run was on main at 8a4ebcc55, with the two functions #1472 restores added in a local commit. The final run, on main with #1472 merged, is clean too.
  • cargo test -p horizon-client --lib: 1063 passed. --bins: 98 + 18 passed.
  • tools/parity.py --changed origin/main: 309/310 passed in 69.8 min, the same run as the clippy check above. The one failure, menu_click, was the loom case fixed in #1467's second commit. On the refreshed integration commit (main with #1472, plus all five branches), menu_click passes: 8000/8000 with seed 7 and with seed 11.

Needs Ludovic

Nothing.

🤖 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/1467 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/23/2026 **Status:** ✅ Merged **Merged:** 10/23/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/bundle-clicks` --- ### 📝 Commits (4) - [`7dac46e`](https://github.com/horizon-rust/horizon/commit/7dac46ec3cc74eda07797572e84c7434065db3c8) Bundles take and give items in inventories and containers - [`8acb467`](https://github.com/horizon-rust/horizon/commit/8acb46756bca113619cc50b106b2f5012383b632) Bundle clicks: the open menu's slotsChanged for the player's inventory - [`0b0e4a8`](https://github.com/horizon-rust/horizon/commit/0b0e4a8aaeca0265f4999d190f5c00302393caae) Merge remote-tracking branch 'origin/main' into fix/bundle-clicks - [`cbc4692`](https://github.com/horizon-rust/horizon/commit/cbc469249e8bcc5477deb100e29a6ee5eee25840) Merge remote-tracking branch 'origin/main' into fix/bundle-clicks ### 📊 Changes **11 files changed** (+618 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/examples/probe/menu_fixture.rs` (+4 -2) ➕ `crates/horizon-client/src/bundle.rs` (+192 -0) 📝 `crates/horizon-client/src/game.rs` (+30 -0) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+3 -0) 📝 `crates/horizon-client/src/items.rs` (+3 -0) 📝 `crates/horizon-client/src/lan/menu.rs` (+200 -1) 📝 `crates/horizon-client/src/lib.rs` (+1 -0) 📝 `crates/horizon-client/src/menu.rs` (+27 -3) ➕ `crates/horizon-client/src/menu/bundle.rs` (+102 -0) 📝 `mods/horizon/src/test/java/dev/horizonlab/parity/VanillaMenuOracle.java` (+12 -2) 📝 `tools/test_menu_click_parity.py` (+44 -5) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Fixes #1456: with a bundle in hand, clicking a stack swapped the two instead of putting the stack in the bundle. ## Vanilla 26.3 `AbstractContainerMenu.doClick` (PICKUP) first calls `tryItemClickBehaviourOverride`: the carried stack's `overrideStackedOnOther`, then the clicked stack's `overrideOtherStackedOnMe`. `BundleItem` uses both on `BundleContents.Mutable`: - carried bundle, left click on a stack: `tryTransfer` takes as much as the remaining weight allows, through `slot.safeTake` - carried bundle, right click on an empty slot: `removeOne` goes into the slot (`safeInsert`), and whatever doesn't fit goes back into the bundle - left click on a bundle in a slot while holding a stack: `tryInsert` (needs `slot.allowModification`) - right click on a bundle in a slot with an empty hand: `removeOne` goes to the cursor - weights: 1/max stack size, 1 for a beehive with bees, and for a nested bundle its contents plus 1/16. Shulker boxes never fit. Exact `Fraction` arithmetic. - after either override: `broadcastChangesOnContainerMenu`, i.e. the open menu's `slotsChanged(player inventory)`; crafting grids, the loom, stonecutter, cartography table and merchant recompute from their inputs - sounds at the player: `item.bundle.insert` / `remove_one` (0.8, 0.8 + rand x 0.4) and `insert_fail` (1, 1) ## Change - `horizon_client::bundle`: `BundleContents.Mutable` (`tryInsert`, `removeOne`, `getMaxAmountToAdd`, exact weights). `ItemInfo.bundle` comes from the default `bundle_contents` component. - `menu` (the engine behind in-frame menus, server-thread and LAN inventory menus, and client prediction): `Menu::pickup` runs the two overrides first. `Menu.player_sounds` holds their sounds, which the game plays at the player. After a bundle click the menu runs `slotsChanged` for the inventory, as above. - `lan::menu` (the engine for a server's chests, barrels and shulker boxes, used for server-thread and LAN guests): the same overrides. - In in-frame single player, a press with an empty hand in the inventory screen went to an older click path and never reached the engine, so a right click on a bundle picked up half of it. It now goes to the engine, as it already did on a server. ## Tests - `tools/test_menu_click_parity.py`: bundles are now among the generated stacks (empty, loaded, nested, often the carried stack, from their own RNG so the existing cases don't change), and the player's sounds are compared too (the Java oracle records `Player.playSound`). On inventory, chests, shulker box, hopper, dispenser and crafting, 3000 cases: **3000/3000 match**, against **2796/3000 without the overrides** (204 differing PICKUP/QUICK_CRAFT cases). On every menu, 8000 cases: **8000/8000 match**, with seed 7 and with seed 11. The run over every menu caught the loom recomputing its result after a bundle click (`slotsChanged`). - `lan::menu::tests::guest_chest_clicks_fill_and_empty_bundles` (resource-backed) fails without the override and passes with it. - In game (Mac mini, Metal, offscreen, real mouse events through `horizon-ctl click-at`), survival inventory, in-frame and `--server-thread` give the same results: 1. carry the bundle and click 32 stone: bundle `[32 stone]` 2. click 16 ender pearls: 8 go in, giving `[8 pearls, 32 stone]` 3. right click an empty slot: 8 pearls come out 4. put the bundle down and click it while holding 4 pearls: `[4 pearls, 32 stone]` 5. right click it with an empty hand: 4 pearls go to the cursor On main, step 1 swaps the bundle and the stone, as reported. - Server-thread chest: carry the bundle and click the chest's stone, then right click an empty chest slot. The stone moves in and back out, and is still there after the chest is closed and reopened (server state). | in-frame, after the steps above | `--server-thread`, chest | |---|---| | ![](https://raw.githubusercontent.com/ludovic111/horizon/c5d43f6e724a6e9c6ad44ed4b6fc33fcfa081392/1456/bundle-inframe-after.png) | ![](https://raw.githubusercontent.com/ludovic111/horizon/c5d43f6e724a6e9c6ad44ed4b6fc33fcfa081392/1456/bundle-chest-st-after.png) | ## Not in this PR (follow-ups) These are vanilla bundle features Horizon still lacks: - the contents tooltip (`ClientBundleTooltip`) - the selected item, and scrolling to select it (`ServerboundSelectBundleItemPacket`). `removeOne` always takes the first stack, which is what vanilla does when nothing is selected. - using a bundle in hand to drop its contents (`BundleItem.use`) - dropping the contents when a bundle item entity is destroyed ## Self-check These checks ran on one integration commit with #1467, #1468, #1469, #1470 and #1471 merged on main (Mac mini): - `cargo fmt --all -- --check`: clean - `cargo clippy --workspace --all-targets -- -D warnings`: clean. The first run was on main at 8a4ebcc55, with the two functions #1472 restores added in a local commit. The final run, on main with #1472 merged, is clean too. - `cargo test -p horizon-client --lib`: 1063 passed. `--bins`: 98 + 18 passed. - `tools/parity.py --changed origin/main`: 309/310 passed in 69.8 min, the same run as the clippy check above. The one failure, `menu_click`, was the loom case fixed in #1467's second commit. On the refreshed integration commit (main with #1472, plus all five branches), `menu_click` passes: 8000/8000 with seed 7 and with seed 11. ## Needs Ludovic Nothing. 🤖 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:18 +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#3544
No description provided.