[PR #7508] [MERGED] Inventory: a shift-click puts a shield in the empty off-hand slot #7632

Closed
opened 2026-11-03 07:21:08 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7508
Author: @MSedgeMC
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: fix/menu-offhand-quick-move


📝 Commits (2)

  • d9f93b4 Inventory: a shift-click sends an off-hand item to the off hand
  • 8987ae7 Test the off-hand quick move against an empty and a taken off hand

📊 Changes

1 file changed (+81 additions, -0 deletions)

View changed files

📝 crates/horizon-client/src/lan/menu.rs (+81 -0)

📄 Description

Behaviour

In the inventory menu (window 0) a shift-click on a shield now puts it in the
off-hand slot (menu slot 45) when that slot is empty. Horizon sent it to the
first empty hotbar slot instead, so getting a shield into the off hand meant
dragging it there by hand.

Vanilla

InventoryMenu.quickMoveStack resolves the item's equipment slot before the
main-inventory/hotbar branches and moves the stack there:

EquipmentSlot equipmentSlot = player.getEquipmentSlotForItem(itemStack3);   // 38-43
...
} else if (equipmentSlot == EquipmentSlot.OFFHAND
           && this.slots.get(45).isEmpty()) {                              // 203-226
   if (!this.moveItemStackTo(itemStack2, 45, 46, false)) return ItemStack.EMPTY;  // 229-240

(offsets in javap -p -c -constants net.minecraft.world.inventory.InventoryMenu.)

LivingEntity.getEquipmentSlotForItem returns
((Equippable) itemStack.get(DataComponents.EQUIPPABLE)).slot() when
canUseSlot allows that slot and MAINHAND otherwise (offsets 0-34 of that
method), so the slot is item data rather than a class test. Items.<clinit>
registers the shield with Item.Properties.equippableUnswappable, called with
EquipmentSlot.OFFHAND (offsets 20373-20412: ItemIds.SHIELD ...
EquipmentSlot.OFFHAND ... equippableUnswappable) — the only
EquipmentSlot.OFFHAND in Items.<clinit>, so the shield is the one vanilla
item that reaches this branch. The move goes through
moveItemStackTo(45, 46, false), so it stops at the slot's max stack size and
leaves the remainder in the clicked slot.

What Horizon got wrong

lan::menu::quick_move knew only the armor branch (Rules::armor_index).
An item with no armor slot fell straight through to "hotbar, or the main
inventory", so a shield shift-clicked from the main inventory went to the first
empty hotbar slot and the off hand stayed empty.

The change

Rules gains equip_slot, defaulted to the item registry's
minecraft:equippable slot (ItemInfo::equip_slot), and quick_move tests it
for "offhand" after the armor branch — the order of vanilla's if-chain. The
production ItemRules needs no change: the default reads the Items registry
it already returns, so a content mod's off-hand item takes the branch too.

Proof

lan::menu::tests::inventory_quick_move_equips_an_off_hand_item shift-clicks a
shield out of menu slot 9, the first main-inventory slot.

Without the change the test fails with

assertion failed: view.get(36).is_none()

— the shield is in the first hotbar slot — and with only that assert moved
after the next one, left: None, right: Some("minecraft:shield"): menu slot 45,
the off hand, is empty.

With the change, slot 45 holds the shield and slots 9 and 36 are both empty. A
second shield with the off hand taken still goes to slot 36, and 3 diamonds with
the off hand taken still go to slot 37, leaving the off hand alone.

cargo test -q -p horizon-client-lib --lib lan::menu → 6 passed.
cargo clippy -q -p horizon-client-lib --lib silent, rustfmt --edition 2024 --check clean.

Proven: the off-hand branch and both of its guards (empty slot 45, the item's
equippable slot is offhand) against the bytecode above; the armor branch
still wins when it applies, and a non-equippable stack is unaffected.
Not proven: not seen in the running game (no GUI here); Slot.mayPickup is
not modelled by this click engine, so a slot that refuses pickup is out of
scope; the same if-chain also equips armor from the off-hand slot (index 45,
getEquipmentSlotForItem → HUMANOID_ARMOR with slots.get(8 - index)
empty), which this change leaves as it was.


🔄 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/7508 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/menu-offhand-quick-move` --- ### 📝 Commits (2) - [`d9f93b4`](https://github.com/horizon-rust/horizon/commit/d9f93b474f36138c590eb518f36fe4f9a4a4a5b9) Inventory: a shift-click sends an off-hand item to the off hand - [`8987ae7`](https://github.com/horizon-rust/horizon/commit/8987ae75eb3e29aa02ecf876832757dac8d20f72) Test the off-hand quick move against an empty and a taken off hand ### 📊 Changes **1 file changed** (+81 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/lan/menu.rs` (+81 -0) </details> ### 📄 Description ## Behaviour In the inventory menu (window 0) a shift-click on a shield now puts it in the **off-hand slot** (menu slot 45) when that slot is empty. Horizon sent it to the first empty hotbar slot instead, so getting a shield into the off hand meant dragging it there by hand. ## Vanilla `InventoryMenu.quickMoveStack` resolves the item's equipment slot before the main-inventory/hotbar branches and moves the stack there: ``` EquipmentSlot equipmentSlot = player.getEquipmentSlotForItem(itemStack3); // 38-43 ... } else if (equipmentSlot == EquipmentSlot.OFFHAND && this.slots.get(45).isEmpty()) { // 203-226 if (!this.moveItemStackTo(itemStack2, 45, 46, false)) return ItemStack.EMPTY; // 229-240 ``` (offsets in `javap -p -c -constants net.minecraft.world.inventory.InventoryMenu`.) `LivingEntity.getEquipmentSlotForItem` returns `((Equippable) itemStack.get(DataComponents.EQUIPPABLE)).slot()` when `canUseSlot` allows that slot and `MAINHAND` otherwise (offsets 0-34 of that method), so the slot is item data rather than a class test. `Items.<clinit>` registers the shield with `Item.Properties.equippableUnswappable`, called with `EquipmentSlot.OFFHAND` (offsets 20373-20412: `ItemIds.SHIELD` ... `EquipmentSlot.OFFHAND` ... `equippableUnswappable`) — the only `EquipmentSlot.OFFHAND` in `Items.<clinit>`, so the shield is the one vanilla item that reaches this branch. The move goes through `moveItemStackTo(45, 46, false)`, so it stops at the slot's max stack size and leaves the remainder in the clicked slot. ## What Horizon got wrong `lan::menu::quick_move` knew only the armor branch (`Rules::armor_index`). An item with no armor slot fell straight through to "hotbar, or the main inventory", so a shield shift-clicked from the main inventory went to the first empty hotbar slot and the off hand stayed empty. ## The change `Rules` gains `equip_slot`, defaulted to the item registry's `minecraft:equippable` slot (`ItemInfo::equip_slot`), and `quick_move` tests it for `"offhand"` after the armor branch — the order of vanilla's if-chain. The production `ItemRules` needs no change: the default reads the `Items` registry it already returns, so a content mod's off-hand item takes the branch too. ## Proof `lan::menu::tests::inventory_quick_move_equips_an_off_hand_item` shift-clicks a shield out of menu slot 9, the first main-inventory slot. Without the change the test fails with ``` assertion failed: view.get(36).is_none() ``` — the shield is in the first hotbar slot — and with only that assert moved after the next one, `left: None, right: Some("minecraft:shield")`: menu slot 45, the off hand, is empty. With the change, slot 45 holds the shield and slots 9 and 36 are both empty. A second shield with the off hand taken still goes to slot 36, and 3 diamonds with the off hand taken still go to slot 37, leaving the off hand alone. `cargo test -q -p horizon-client-lib --lib lan::menu` → 6 passed. `cargo clippy -q -p horizon-client-lib --lib` silent, `rustfmt --edition 2024 --check` clean. **Proven:** the off-hand branch and both of its guards (empty slot 45, the item's `equippable` slot is `offhand`) against the bytecode above; the armor branch still wins when it applies, and a non-equippable stack is unaffected. **Not proven:** not seen in the running game (no GUI here); `Slot.mayPickup` is not modelled by this click engine, so a slot that refuses pickup is out of scope; the same if-chain also equips armor *from* the off-hand slot (index 45, `getEquipmentSlotForItem` → `HUMANOID_ARMOR` with `slots.get(8 - index)` empty), which this change leaves as it was. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 07:21:08 +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#7632
No description provided.