[PR #7838] Menus: a click with a button other than 0 or 1 changes nothing #7854

Open
opened 2026-11-03 07:25:29 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7838
Author: @MSedgeMC
Created: 11/2/2026
Status: 🔄 Open

Base: main ← Head: fix/menu-click-button


📝 Commits (3)

  • 357b48b Menus: a pickup or a quick move is a click with button 0 or 1
  • 7b1a5c6 Test that only buttons 0 and 1 click a container slot
  • 37049db Ledger: AbstractContainerMenu.isContainerClickButton

📊 Changes

2 files changed (+59 additions, -3 deletions)

View changed files

📝 crates/horizon-client/src/lan/menu.rs (+58 -3)
📝 tools/port_map/game2-007.tsv (+1 -0)

📄 Description

Behaviour

A click on a container slot whose button is neither 0 nor 1 does nothing at
all. Horizon read every button except 1 as the left one, so a PICKUP or
QUICK_MOVE with button 2 took the stack out of the slot, shift-clicked it into
the hotbar, or dropped the cursor, and a THROW with button 2 dropped one item
where vanilla drops the whole stack.

Vanilla

AbstractContainerMenu.doClick only enters its PICKUP/QUICK_MOVE arm when the
button is a mouse button. The private helper is two comparisons (javap -p -c -constants net.minecraft.world.inventory.AbstractContainerMenu, offsets 0-14):

private static boolean isContainerClickButton(int button);
   0: iload_0; 1: ifeq 9; 4: iload_0; 5: iconst_1; 6: if_icmpne 13
   9: iconst_1; 10: goto 14; 13: iconst_0; 14: ireturn

and the arm starts with it (offsets 561-579): when it is false the click skips
the whole slotIndex == -999 drop, the QUICK_MOVE branch and the PICKUP
branch, and falls through to the test at 1074, which wants
ContainerInput.SWAP — so nothing happens. getClickAction (offsets
1737-1754) has no answer for another button either: 0 is PRIMARY, 1 SECONDARY,
anything else throws; the guard is what keeps that unreachable.

THROW is not gated by that helper but reads the button the same way (offsets
1481-1497):

int amount = button == 0 ? 1 : slot.getItem().getCount();

The vanilla screen only sends 0 and 1: AbstractContainerScreen.mouseClicked
turns the mouse button into PICKUP, QUICK_MOVE or, outside the window, THROW
(offsets 163-300; a middle click is CLONE, offsets 189-202), and the drop key
sends hasControlDown() ? 1 : 0 with THROW (offsets 125-139).

What Horizon got wrong

lan::menu::click dispatched on the mode alone. pickup decided primary from
button == 1, the QUICK_MOVE arm ignored the button entirely, the shared
slot == -999 arm dropped the cursor for both modes, and THROW's amount was
button == 1 || count <= 1 ? whole : one. A modified client's button 2 was
therefore a full left click.

The change

is_container_click_button (the helper above) and one match arm: a PICKUP or
QUICK_MOVE that fails it is left to the _ => {} arm. THROW's amount becomes
vanilla's button == 0 ? 1 : count.

Why implement it rather than record it

The click is only reachable from a modified client — no vanilla screen builds
it — so this is a design call, and the guard is the faithful one: vanilla's
server refuses those clicks and its own getClickAction would throw on them,
so a client that sends one gets nothing done, and nothing about buttons 0 and 1
changes. It costs one match arm and keeps lan::menu a model of doClick
rather than of the vanilla screen's habits. The same family's other half,
isValidQuickcraftType for the drag types, is #7635.

Proof

lan::menu::tests::guest_clicks_with_a_button_other_than_0_or_1_move_nothing
drives lan::menu::click, the function lan::containers::Hub::container_click
calls for every guest container click.

Without the change:

  • PICKUP, button 2, on a slot holding 3 diamonds: carried becomes
    Some(diamond, 3) and the slot empties.
  • QUICK_MOVE, button 2: the 3 diamonds land in the hotbar's first slot (menu
    slot 36) and the clicked slot empties.
  • PICKUP, button 2, at slot -999 with 5 dirt on the cursor: one drop of 5 dirt,
    the cursor is emptied.
  • THROW, button 2, on 4 diamonds: one item dropped, 3 left in the slot.

With the change all four move nothing; button 1 still takes half a stack
(3 → 2 on the cursor, 1 left), and THROW with button 2 still drops all 4, since
that arm reads the button as "one or the stack", not as primary or secondary.

cargo test -q -p horizon-client-lib --lib lan::menu → 7 passed.
cargo clippy -q -p horizon-client-lib --lib --all-targets silent, cargo fmt -p horizon-client-lib -- --check clean.

Proven: the guard's position before all three PICKUP/QUICK_MOVE paths and
THROW's amount, against the bytecode above.
Not proven: not seen in the running game (no GUI here); every click the
vanilla screen produces has button 0 or 1, so only a modified client could tell
the difference.


🔄 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/7838 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/menu-click-button` --- ### 📝 Commits (3) - [`357b48b`](https://github.com/horizon-rust/horizon/commit/357b48baf19228f94090459f54b98844f7b1ae21) Menus: a pickup or a quick move is a click with button 0 or 1 - [`7b1a5c6`](https://github.com/horizon-rust/horizon/commit/7b1a5c6c0b6ae6675c7fd970278492cf9e631920) Test that only buttons 0 and 1 click a container slot - [`37049db`](https://github.com/horizon-rust/horizon/commit/37049dbca511ff25ae6b5238ff4baf2aa71e4e25) Ledger: AbstractContainerMenu.isContainerClickButton ### 📊 Changes **2 files changed** (+59 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/lan/menu.rs` (+58 -3) 📝 `tools/port_map/game2-007.tsv` (+1 -0) </details> ### 📄 Description ## Behaviour A click on a container slot whose button is neither 0 nor 1 does nothing at all. Horizon read every button except 1 as the left one, so a PICKUP or QUICK_MOVE with button 2 took the stack out of the slot, shift-clicked it into the hotbar, or dropped the cursor, and a THROW with button 2 dropped one item where vanilla drops the whole stack. ## Vanilla `AbstractContainerMenu.doClick` only enters its PICKUP/QUICK_MOVE arm when the button is a mouse button. The private helper is two comparisons (`javap -p -c -constants net.minecraft.world.inventory.AbstractContainerMenu`, offsets 0-14): ``` private static boolean isContainerClickButton(int button); 0: iload_0; 1: ifeq 9; 4: iload_0; 5: iconst_1; 6: if_icmpne 13 9: iconst_1; 10: goto 14; 13: iconst_0; 14: ireturn ``` and the arm starts with it (offsets 561-579): when it is false the click skips the whole `slotIndex == -999` drop, the QUICK_MOVE branch and the PICKUP branch, and falls through to the test at 1074, which wants `ContainerInput.SWAP` — so nothing happens. `getClickAction` (offsets 1737-1754) has no answer for another button either: 0 is PRIMARY, 1 SECONDARY, anything else throws; the guard is what keeps that unreachable. THROW is not gated by that helper but reads the button the same way (offsets 1481-1497): ``` int amount = button == 0 ? 1 : slot.getItem().getCount(); ``` The vanilla screen only sends 0 and 1: `AbstractContainerScreen.mouseClicked` turns the mouse button into PICKUP, QUICK_MOVE or, outside the window, THROW (offsets 163-300; a middle click is CLONE, offsets 189-202), and the drop key sends `hasControlDown() ? 1 : 0` with THROW (offsets 125-139). ## What Horizon got wrong `lan::menu::click` dispatched on the mode alone. `pickup` decided primary from `button == 1`, the QUICK_MOVE arm ignored the button entirely, the shared `slot == -999` arm dropped the cursor for both modes, and THROW's amount was `button == 1 || count <= 1 ? whole : one`. A modified client's button 2 was therefore a full left click. ## The change `is_container_click_button` (the helper above) and one match arm: a PICKUP or QUICK_MOVE that fails it is left to the `_ => {}` arm. THROW's amount becomes vanilla's `button == 0 ? 1 : count`. ## Why implement it rather than record it The click is only reachable from a modified client — no vanilla screen builds it — so this is a design call, and the guard is the faithful one: vanilla's server refuses those clicks and its own `getClickAction` would throw on them, so a client that sends one gets nothing done, and nothing about buttons 0 and 1 changes. It costs one match arm and keeps `lan::menu` a model of `doClick` rather than of the vanilla screen's habits. The same family's other half, `isValidQuickcraftType` for the drag types, is #7635. ## Proof `lan::menu::tests::guest_clicks_with_a_button_other_than_0_or_1_move_nothing` drives `lan::menu::click`, the function `lan::containers::Hub::container_click` calls for every guest container click. Without the change: - PICKUP, button 2, on a slot holding 3 diamonds: `carried` becomes `Some(diamond, 3)` and the slot empties. - QUICK_MOVE, button 2: the 3 diamonds land in the hotbar's first slot (menu slot 36) and the clicked slot empties. - PICKUP, button 2, at slot -999 with 5 dirt on the cursor: one drop of 5 dirt, the cursor is emptied. - THROW, button 2, on 4 diamonds: one item dropped, 3 left in the slot. With the change all four move nothing; button 1 still takes half a stack (3 → 2 on the cursor, 1 left), and THROW with button 2 still drops all 4, since that arm reads the button as "one or the stack", not as primary or secondary. `cargo test -q -p horizon-client-lib --lib lan::menu` → 7 passed. `cargo clippy -q -p horizon-client-lib --lib --all-targets` silent, `cargo fmt -p horizon-client-lib -- --check` clean. **Proven:** the guard's position before all three PICKUP/QUICK_MOVE paths and THROW's amount, against the bytecode above. **Not proven:** not seen in the running game (no GUI here); every click the vanilla screen produces has button 0 or 1, so only a modified client could tell the difference. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#7854
No description provided.