[PR #7840] Inventory: a shift-click from the off hand wears the armour it holds #7855

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

📋 Pull Request Information

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

Base: main ← Head: fix/menu-offhand-armor


📝 Commits (3)

  • 34e8899 Menus: a shift-click from the off hand wears the armour it holds
  • c686e9e Test wearing armour out of the off-hand slot
  • cabb448 Ledger: the off-hand armour branch of InventoryMenu.quickMoveStack

📊 Changes

2 files changed (+67 additions, -4 deletions)

View changed files

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

📄 Description

Behaviour

A shift-click on an armour piece held in the off-hand slot (menu slot 45)
now puts it on, when the matching armour slot is empty. Horizon sent it to the
main inventory and left the armour slot empty, so a helmet carried in the off
hand had to be dragged to the helmet slot by hand.

Vanilla

InventoryMenu.quickMoveStack resolves the item's equipment slot before it
looks at the clicked index, and its armour branch is therefore reached from
every index above the crafting grid — the off-hand slot included:

EquipmentSlot equipmentSlot = player.getEquipmentSlotForItem(itemStack3);   // 38-43
...
} else if (equipmentSlot.getType() == EquipmentSlot.Type.HUMANOID_ARMOR
           && !this.slots.get(8 - equipmentSlot.getIndex()).hasItem()) {     // 135-167
   int i7 = 8 - equipmentSlot.getIndex();                                    // 170-178
   if (!this.moveItemStackTo(itemStack2, i7, i7 + 1, false)) return ItemStack.EMPTY;  // 180-193
...
} else if (index >= 9 && index < 36) { ... }                                 // 247-276
} else if (index >= 36 && index < 45) { ... }                                // 277-306
} else { moveItemStackTo(itemStack2, 9, 45, false); }                        // 307-324

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

The chain is ordered by the item's slot, not by the clicked index: indices
1-8 (crafting grid and armour) take the two moveItemStackTo(9, 45, ...)
branches at 78-134, and every other index reaches the equipment-slot test at
135 first, so index 45 with a HUMANOID_ARMOR item and a free armour slot is
worn. With no armour to wear, or with the armour slot taken, index 45 falls to
the final else and goes to 9..45, the main inventory before the hotbar.

What Horizon got wrong

lan::menu::quick_move listed i == 45 with the armour and grid slots in its
first arm, so every off-hand stack went straight to move_to(9..45): the
armour branch was never reached from the off hand.

The change

The first arm keeps only the crafting grid and the armour slots (the indices
below 9). The rest of the chain follows vanilla's order: the equipment slot
first, then the item's equippable slot branch that is already on main, then
the hotbar and main-inventory ranges by index, then the final else that sends
an off-hand stack to 9..45 — where that index already went, unchanged.

Proof

lan::menu::tests::inventory_quick_move_wears_armor_from_the_off_hand
shift-clicks through lan::menu::click.

Without the change the helmet slot (menu slot 5) is empty and the helmet sits
in menu slot 9, the first main-inventory slot:

assertion `left == right` failed
  left: None
 right: Some("minecraft:iron_helmet")

With the change the helmet goes to slot 5 and slot 45 empties; a second helmet
with the helmet slot taken lands in slot 9; 3 diamonds from the off hand land
in slot 10 (slot 9 being taken) and leave the hotbar alone.

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 branch order and the off-hand index against the bytecode above;
the non-armour off-hand path is unchanged (a diamond from slot 45 went to slot
9 before and after).
Not proven: not seen in the running game (no GUI here); this engine does
not consult Slot.mayPickup yet, so an armour slot that would refuse the stack
is out of scope.


🔄 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/7840 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/menu-offhand-armor` --- ### 📝 Commits (3) - [`34e8899`](https://github.com/horizon-rust/horizon/commit/34e889990df1910043044c1507c01d0a1d50a58a) Menus: a shift-click from the off hand wears the armour it holds - [`c686e9e`](https://github.com/horizon-rust/horizon/commit/c686e9eeef95dc2d0f8d8d987bd211a7d725b519) Test wearing armour out of the off-hand slot - [`cabb448`](https://github.com/horizon-rust/horizon/commit/cabb4486c1e9a81a7a2870371623610ceabdb783) Ledger: the off-hand armour branch of InventoryMenu.quickMoveStack ### 📊 Changes **2 files changed** (+67 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/lan/menu.rs` (+66 -3) 📝 `tools/port_map/game2-007.tsv` (+1 -1) </details> ### 📄 Description ## Behaviour A shift-click on an armour piece held in the **off-hand slot** (menu slot 45) now puts it on, when the matching armour slot is empty. Horizon sent it to the main inventory and left the armour slot empty, so a helmet carried in the off hand had to be dragged to the helmet slot by hand. ## Vanilla `InventoryMenu.quickMoveStack` resolves the item's equipment slot before it looks at the clicked index, and its armour branch is therefore reached from every index above the crafting grid — the off-hand slot included: ``` EquipmentSlot equipmentSlot = player.getEquipmentSlotForItem(itemStack3); // 38-43 ... } else if (equipmentSlot.getType() == EquipmentSlot.Type.HUMANOID_ARMOR && !this.slots.get(8 - equipmentSlot.getIndex()).hasItem()) { // 135-167 int i7 = 8 - equipmentSlot.getIndex(); // 170-178 if (!this.moveItemStackTo(itemStack2, i7, i7 + 1, false)) return ItemStack.EMPTY; // 180-193 ... } else if (index >= 9 && index < 36) { ... } // 247-276 } else if (index >= 36 && index < 45) { ... } // 277-306 } else { moveItemStackTo(itemStack2, 9, 45, false); } // 307-324 ``` (offsets in `javap -p -c -constants net.minecraft.world.inventory.InventoryMenu`.) The chain is ordered by the item's slot, not by the clicked index: indices 1-8 (crafting grid and armour) take the two `moveItemStackTo(9, 45, ...)` branches at 78-134, and every other index reaches the equipment-slot test at 135 first, so index 45 with a `HUMANOID_ARMOR` item and a free armour slot is worn. With no armour to wear, or with the armour slot taken, index 45 falls to the final `else` and goes to `9..45`, the main inventory before the hotbar. ## What Horizon got wrong `lan::menu::quick_move` listed `i == 45` with the armour and grid slots in its first arm, so every off-hand stack went straight to `move_to(9..45)`: the armour branch was never reached from the off hand. ## The change The first arm keeps only the crafting grid and the armour slots (the indices below 9). The rest of the chain follows vanilla's order: the equipment slot first, then the item's `equippable` slot branch that is already on main, then the hotbar and main-inventory ranges by index, then the final `else` that sends an off-hand stack to `9..45` — where that index already went, unchanged. ## Proof `lan::menu::tests::inventory_quick_move_wears_armor_from_the_off_hand` shift-clicks through `lan::menu::click`. Without the change the helmet slot (menu slot 5) is empty and the helmet sits in menu slot 9, the first main-inventory slot: ``` assertion `left == right` failed left: None right: Some("minecraft:iron_helmet") ``` With the change the helmet goes to slot 5 and slot 45 empties; a second helmet with the helmet slot taken lands in slot 9; 3 diamonds from the off hand land in slot 10 (slot 9 being taken) and leave the hotbar alone. `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 branch order and the off-hand index against the bytecode above; the non-armour off-hand path is unchanged (a diamond from slot 45 went to slot 9 before and after). **Not proven:** not seen in the running game (no GUI here); this engine does not consult `Slot.mayPickup` yet, so an armour slot that would refuse the stack is out of scope. --- <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#7855
No description provided.