[PR #7845] Menus: the guest menu reads Slot.mayPickup and Player.canDropItems #7858

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

📋 Pull Request Information

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

Base: main ← Head: fix/menu-may-pickup


📝 Commits (3)

  • 54d75a8 Menus: the guest menu reads Slot.mayPickup and Player.canDropItems
  • 2671f09 Test the guest menu's pickup and drop guards
  • 8b6d24f Ledger: Slot.mayPickup and Player.canDropItems

📊 Changes

3 files changed (+227 additions, -3 deletions)

View changed files

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

📄 Description

Behaviour

The guest menu engine now reads the two vanilla guards it had no answer for:
Slot.mayPickup before it takes anything out of a slot (a click, a
shift-click, the clicked slot of a double-click and every slot that
double-click sweeps) and Player.canDropItems before a THROW drops. With the
Rules defaults they stay permissive, so the host's own container slots behave
exactly as before; the one rule that is not permissive is the armour slots',
which is user-visible: a survival guest can no longer take off armour carrying
the binding curse, while a creative guest still can. menu.rs, the engine
behind the local player's menus, already refuses that take.

Vanilla

AbstractContainerMenu.doClick (javap -p -c -constants, offsets):

  • QUICK_MOVE: if (!slot.mayPickup(player)) return; before quickMoveStack
    (665-693).
  • PICKUP: the whole non-empty-slot arm is else if (slot.mayPickup(player))
    (852-859), and the two tryRemove calls inside it are allowModification
    takes (Slot.tryRemove asks mayPickup first).
  • PICKUP_ALL: if (slot.hasItem() && slot.mayPickup(player)) return; (1653-1668)
    — a collect starts from an empty slot or from one that refuses — and each
    swept slot is tested too: if (slot2.mayPickup(player)) (1777-1784).
  • THROW: if (!player.canDropItems()) return; before the first safeTake
    (1499-1507) and again inside the button-1 repeat loop (1567-1575).

ArmorSlot.mayPickup is the one slot rule in vanilla's own menus (offsets
0-36): an empty slot, a creative player or a stack without
EnchantmentEffectComponents.PREVENT_ARMOR_CHANGE goes to super.mayPickup,
which is true; otherwise it answers false. PREVENT_ARMOR_CHANGE is the
binding curse's effect component, and menu.rs already models it as the
minecraft:binding_curse level (its Role::Armor arm).

Player.canDropItems returns true (offsets 0-1) and nothing on the server
side overrides it; LocalPlayer overrides it with
dropSpamThrottler.isUnderThreshold() (offsets 0-7), so the guard is the
client's own throttle on the clicks it sends.

What Horizon got wrong

lan::menu had no pickup guard at all: pickup took from a slot whatever it
held, QUICK_MOVE moved whatever it was pointed at, pickup_all ignored the
clicked slot, and THROW dropped regardless. The engine could not even express a
slot that refuses, so the three guards were untestable as well as absent.

The change

Rules gains may_pickup(slot, stack) and can_drop_items(), both true by
default — a host's plain container slots and the player's own inventory answer
true, which is what they answered before. View::may_pickup combines the
armour rule above with them, and the four call sites use it. lan_actions'
ItemRules needs no new code: the defaults are its answer.

Decision, since the brief left it open: the trait hook is worth adding. It
is what makes the guards expressible for a menu whose slots refuse (a mod's
menu type), and it is the only way these three guards can be proven headless;
the defaults keep the shipped behaviour identical, so the change is additive
for the host.

Proof

lan::menu::tests (all through lan::menu::click, the function
lan::containers::Hub::container_click calls):

guest_pickup_and_quick_move_need_the_slots_consent — without the change the
click on a refused slot empties it, and the shift-click moves its 5 stone to the
inventory's end (menu slot 37):

assertion `left == right` failed            (before the click-count assertions)
  left: None
 right: Some(5)

guest_pickup_all_starts_from_an_empty_or_refusing_slot — without the change a
double-click on a slot that holds the carried item collects anyway (slot 0 5 →
4, cursor 63 → 64):

assertion `left == right` failed
  left: Some(4)
 right: Some(5)

guest_throw_needs_can_drop_items — without the change THROW drops one item
(drops = [stone × 1]) although can_drop_items is false.

guest_survival_cannot_remove_cursed_armour — without the change a survival
guest takes the cursed chestplate off (slot 6 empties, the cursor holds it) by
both a click and a shift-click:

assertion `left == right` failed
  left: false
 right: true

With the change: the refused slot keeps its stack under both clicks while its
neighbour gives its own up, the collect starts only from an empty or refusing
slot and skips the refusing one, THROW drops nothing, and the cursed chestplate
stays on in survival and comes off in creative.

cargo test -q -p horizon-client-lib --lib lan::menu → 10 passed.
cargo clippy -q -p horizon-client-lib --lib --all-targets silent, cargo fmt -p horizon-client-lib -- --check clean.
tools/port_ledger.py map-check tools/port_map/game2-005.tsv tools/port_map/game2-008.tsv → 143 and 150 rows, no problems.

Note for #7636

#7636 changes the sweep direction of the same pickup_all and its test
double-clicks a slot that holds the carried item (slot 0 with 5 stone, cursor at
63), expecting a collect. With the guard above that click returns at once —
vanilla's slot.hasItem() && slot.mayPickup(player) — so its test needs to
double-click an empty slot to exercise the direction. The two changes are
otherwise compatible: menu.rs already had this guard
(if self.has_item(s) && self.may_pickup(env, s) { return; }), and this PR
brings the guest path in line with it.

Proven: all four guards and the armour rule against the bytecode above,
including that the defaults leave the host's slots permissive.
Not proven: not seen in the running game (no GUI here); SWAP's own
mayPickup (doClick 1152, 1271) is not ported — lan::menu::swap still
checks placement only, which is noted here rather than changed; the
PREVENT_ARMOR_CHANGE component is matched by the binding-curse id, as
menu.rs does.


🔄 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/7845 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/menu-may-pickup` --- ### 📝 Commits (3) - [`54d75a8`](https://github.com/horizon-rust/horizon/commit/54d75a852bbad8bc4187a583c5829464fa692f29) Menus: the guest menu reads Slot.mayPickup and Player.canDropItems - [`2671f09`](https://github.com/horizon-rust/horizon/commit/2671f0926a72bb150b911ab384314b17f9eab436) Test the guest menu's pickup and drop guards - [`8b6d24f`](https://github.com/horizon-rust/horizon/commit/8b6d24fbae358a2d02c1ab89f5b682a2b0b889cd) Ledger: Slot.mayPickup and Player.canDropItems ### 📊 Changes **3 files changed** (+227 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/lan/menu.rs` (+225 -3) 📝 `tools/port_map/game2-005.tsv` (+1 -0) 📝 `tools/port_map/game2-008.tsv` (+1 -0) </details> ### 📄 Description ## Behaviour The guest menu engine now reads the two vanilla guards it had no answer for: `Slot.mayPickup` before it takes anything out of a slot (a click, a shift-click, the clicked slot of a double-click and every slot that double-click sweeps) and `Player.canDropItems` before a THROW drops. With the `Rules` defaults they stay permissive, so the host's own container slots behave exactly as before; the one rule that is not permissive is the armour slots', which is user-visible: a survival guest can no longer take off armour carrying the binding curse, while a creative guest still can. `menu.rs`, the engine behind the local player's menus, already refuses that take. ## Vanilla `AbstractContainerMenu.doClick` (`javap -p -c -constants`, offsets): - QUICK_MOVE: `if (!slot.mayPickup(player)) return;` before `quickMoveStack` (665-693). - PICKUP: the whole non-empty-slot arm is `else if (slot.mayPickup(player))` (852-859), and the two `tryRemove` calls inside it are `allowModification` takes (`Slot.tryRemove` asks `mayPickup` first). - PICKUP_ALL: `if (slot.hasItem() && slot.mayPickup(player)) return;` (1653-1668) — a collect starts from an empty slot or from one that refuses — and each swept slot is tested too: `if (slot2.mayPickup(player))` (1777-1784). - THROW: `if (!player.canDropItems()) return;` before the first `safeTake` (1499-1507) and again inside the button-1 repeat loop (1567-1575). `ArmorSlot.mayPickup` is the one slot rule in vanilla's own menus (offsets 0-36): an empty slot, a creative player or a stack without `EnchantmentEffectComponents.PREVENT_ARMOR_CHANGE` goes to `super.mayPickup`, which is `true`; otherwise it answers `false`. `PREVENT_ARMOR_CHANGE` is the binding curse's effect component, and `menu.rs` already models it as the `minecraft:binding_curse` level (its `Role::Armor` arm). `Player.canDropItems` returns `true` (offsets 0-1) and nothing on the server side overrides it; `LocalPlayer` overrides it with `dropSpamThrottler.isUnderThreshold()` (offsets 0-7), so the guard is the client's own throttle on the clicks it sends. ## What Horizon got wrong `lan::menu` had no pickup guard at all: `pickup` took from a slot whatever it held, `QUICK_MOVE` moved whatever it was pointed at, `pickup_all` ignored the clicked slot, and THROW dropped regardless. The engine could not even express a slot that refuses, so the three guards were untestable as well as absent. ## The change `Rules` gains `may_pickup(slot, stack)` and `can_drop_items()`, both `true` by default — a host's plain container slots and the player's own inventory answer `true`, which is what they answered before. `View::may_pickup` combines the armour rule above with them, and the four call sites use it. `lan_actions`' `ItemRules` needs no new code: the defaults are its answer. **Decision, since the brief left it open:** the trait hook is worth adding. It is what makes the guards expressible for a menu whose slots refuse (a mod's menu type), and it is the only way these three guards can be proven headless; the defaults keep the shipped behaviour identical, so the change is additive for the host. ## Proof `lan::menu::tests` (all through `lan::menu::click`, the function `lan::containers::Hub::container_click` calls): `guest_pickup_and_quick_move_need_the_slots_consent` — without the change the click on a refused slot empties it, and the shift-click moves its 5 stone to the inventory's end (menu slot 37): ``` assertion `left == right` failed (before the click-count assertions) left: None right: Some(5) ``` `guest_pickup_all_starts_from_an_empty_or_refusing_slot` — without the change a double-click on a slot that holds the carried item collects anyway (slot 0 5 → 4, cursor 63 → 64): ``` assertion `left == right` failed left: Some(4) right: Some(5) ``` `guest_throw_needs_can_drop_items` — without the change THROW drops one item (`drops = [stone × 1]`) although `can_drop_items` is false. `guest_survival_cannot_remove_cursed_armour` — without the change a survival guest takes the cursed chestplate off (slot 6 empties, the cursor holds it) by both a click and a shift-click: ``` assertion `left == right` failed left: false right: true ``` With the change: the refused slot keeps its stack under both clicks while its neighbour gives its own up, the collect starts only from an empty or refusing slot and skips the refusing one, THROW drops nothing, and the cursed chestplate stays on in survival and comes off in creative. `cargo test -q -p horizon-client-lib --lib lan::menu` → 10 passed. `cargo clippy -q -p horizon-client-lib --lib --all-targets` silent, `cargo fmt -p horizon-client-lib -- --check` clean. `tools/port_ledger.py map-check tools/port_map/game2-005.tsv tools/port_map/game2-008.tsv` → 143 and 150 rows, no problems. ## Note for #7636 #7636 changes the sweep direction of the same `pickup_all` and its test double-clicks a slot that holds the carried item (slot 0 with 5 stone, cursor at 63), expecting a collect. With the guard above that click returns at once — vanilla's `slot.hasItem() && slot.mayPickup(player)` — so its test needs to double-click an empty slot to exercise the direction. The two changes are otherwise compatible: `menu.rs` already had this guard (`if self.has_item(s) && self.may_pickup(env, s) { return; }`), and this PR brings the guest path in line with it. **Proven:** all four guards and the armour rule against the bytecode above, including that the defaults leave the host's slots permissive. **Not proven:** not seen in the running game (no GUI here); `SWAP`'s own `mayPickup` (`doClick` 1152, 1271) is not ported — `lan::menu::swap` still checks placement only, which is noted here rather than changed; the `PREVENT_ARMOR_CHANGE` component is matched by the binding-curse id, as `menu.rs` does. --- <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#7858
No description provided.