From 7b40465f85ba3b91e8de8ef904e1faf617cf723b Mon Sep 17 00:00:00 2001 From: gemakfy Date: Tue, 27 Oct 2026 22:38:19 +0300 Subject: [PATCH] Fix creative inventory off-hand swap crash on Key F --- crates/horizon-client/src/creative.rs | 15 ++++++++++++--- crates/horizon-client/src/game.rs | 7 +++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/crates/horizon-client/src/creative.rs b/crates/horizon-client/src/creative.rs index 1a227db65..a6e0f0b93 100644 --- a/crates/horizon-client/src/creative.rs +++ b/crates/horizon-client/src/creative.rs @@ -575,6 +575,8 @@ pub enum DisplayClick { Nothing, /// SWAP: the hotbar slot gets a full stack of the item. Hotbar(usize, ItemStack), + /// SWAP with button 40 (Key F): the off-hand gets a full stack of the item. + Offhand(ItemStack), /// THROW: a copy of the item is dropped. Drop(ItemStack), } @@ -596,8 +598,11 @@ pub fn click_display( match input { Input::Swap => { return match shown { - Some(s) => DisplayClick::Hotbar(button as usize, copy(s, max(s))), - None => DisplayClick::Nothing, + Some(s) if button == 40 => DisplayClick::Offhand(copy(s, max(s))), + Some(s) if (0..9).contains(&button) => { + DisplayClick::Hotbar(button as usize, copy(s, max(s))) + } + Some(_) | None => DisplayClick::Nothing, }; } Input::Clone => { @@ -720,11 +725,15 @@ mod tests { display(Some(stack("ender_pearl", 9)), 1, Pickup).0, Some(stack("ender_pearl", 8)) ); - // Number keys fill a hotbar slot, Q drops copies, pick block clones. + // Number keys fill a hotbar slot, F fills off-hand, Q drops copies, pick block clones. assert_eq!( display(None, 3, Swap).1, DisplayClick::Hotbar(3, stack("stone", 64)) ); + assert_eq!( + display(None, 40, Swap).1, + DisplayClick::Offhand(stack("stone", 64)) + ); assert_eq!( display(None, 0, Throw).1, DisplayClick::Drop(stack("stone", 1)) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 05c8765e5..e8c29b61b 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -6552,9 +6552,12 @@ impl Game<'_> { let catalog = self.res.items(); let max = |s: &ItemStack| catalog.get(&s.item).map_or(64, |i| i.max_stack); match click_display(&mut self.carried, shown, max, button, input) { - DisplayClick::Hotbar(i, stack) => self.inventory[i] = Some(stack), + DisplayClick::Hotbar(i, stack) if i < self.inventory.len() => { + self.inventory[i] = Some(stack); + } + DisplayClick::Offhand(stack) => self.offhand = Some(stack), DisplayClick::Drop(stack) => self.player_drop(stack), - DisplayClick::Nothing => {} + _ => {} } } /// Several clicks on one menu instance (a quick craft drag is three).