[PR #2929] [CLOSED] Fix creative inventory off-hand swap crash on Key F #4688

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/2929
Author: @gemakfy
Created: 10/27/2026
Status: ❌ Closed

Base: main ← Head: fix/creative-f-offhand-crash


📝 Commits (1)

  • 7b40465 Fix creative inventory off-hand swap crash on Key F

📊 Changes

2 files changed (+17 additions, -5 deletions)

View changed files

📝 crates/horizon-client/src/creative.rs (+12 -3)
📝 crates/horizon-client/src/game.rs (+5 -2)

📄 Description

What and why

Pressing F (KeyCode::KeyF) over an item slot in the Creative mode inventory screen caused an immediate crash:
index out of bounds: the len is 36 but the index is 40 at crates/horizon-client/src/game.rs:6555.

inventory_hotkey sends button 40 for KeyF (the off-hand swap button in vanilla protocol). For creative display slots, click_display was returning DisplayClick::Hotbar(40, stack), which then tried to index into self.inventory (which only has 36 slots).

This patch:

  • Adds DisplayClick::Offhand(ItemStack) to DisplayClick.
  • Makes click_display return DisplayClick::Offhand when button == 40, and restricts DisplayClick::Hotbar to valid slots 0..9.
  • Handles DisplayClick::Offhand in creative_display_click by placing the stack into self.offhand, and adds a boundary check i < self.inventory.len().
  • Adds a unit test verifying that Swap with button 40 produces DisplayClick::Offhand.

Vanilla reference

  • net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen.slotClicked:
    clickType == ClickType.SWAP && dragType == 40 (swaps or copies item into offhand slot).

Self-check

Check Result
Scope ✅ 2 files, +14 −3
Unit tests ✅ display_slot_clicks_follow_slot_clicked passed
Parity ➖ CI's parity job picks the affected harnesses

🔄 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/2929 **Author:** [@gemakfy](https://github.com/gemakfy) **Created:** 10/27/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/creative-f-offhand-crash` --- ### 📝 Commits (1) - [`7b40465`](https://github.com/horizon-rust/horizon/commit/7b40465f85ba3b91e8de8ef904e1faf617cf723b) Fix creative inventory off-hand swap crash on Key F ### 📊 Changes **2 files changed** (+17 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/creative.rs` (+12 -3) 📝 `crates/horizon-client/src/game.rs` (+5 -2) </details> ### 📄 Description ## What and why Pressing `F` (`KeyCode::KeyF`) over an item slot in the Creative mode inventory screen caused an immediate crash: `index out of bounds: the len is 36 but the index is 40` at `crates/horizon-client/src/game.rs:6555`. `inventory_hotkey` sends button 40 for `KeyF` (the off-hand swap button in vanilla protocol). For creative display slots, `click_display` was returning `DisplayClick::Hotbar(40, stack)`, which then tried to index into `self.inventory` (which only has 36 slots). This patch: - Adds `DisplayClick::Offhand(ItemStack)` to `DisplayClick`. - Makes `click_display` return `DisplayClick::Offhand` when `button == 40`, and restricts `DisplayClick::Hotbar` to valid slots `0..9`. - Handles `DisplayClick::Offhand` in `creative_display_click` by placing the stack into `self.offhand`, and adds a boundary check `i < self.inventory.len()`. - Adds a unit test verifying that `Swap` with button 40 produces `DisplayClick::Offhand`. ## Vanilla reference - `net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen.slotClicked`: `clickType == ClickType.SWAP && dragType == 40` (swaps or copies item into offhand slot). ## Self-check | Check | Result | | --- | --- | | Scope | ✅ 2 files, +14 −3 | | Unit tests | ✅ `display_slot_clicks_follow_slot_clicked` passed | | Parity | ➖ CI's parity job picks the affected harnesses | --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:07:12 +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#4688
No description provided.