From 7b40465f85ba3b91e8de8ef904e1faf617cf723b Mon Sep 17 00:00:00 2001 From: gemakfy Date: Tue, 27 Oct 2026 22:38:19 +0300 Subject: [PATCH 1/2] 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). From 501e543105c09ca441cb4c189f86f94138ab4d43 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Tue, 27 Oct 2026 22:26:47 +0100 Subject: [PATCH 2/2] Creative on a server: the off hand's edits reach the server too CreativeInventoryListener sends every InventoryMenu slot that changes, the off hand (slot 45) included; only the 36 inventory slots were sent, so Key F's off-hand stack stayed on this client (single player runs on its server thread too). Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/remote.rs | 27 ++++++++++++++++-------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 9d79aa1a6..84346964b 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -213,7 +213,8 @@ pub(super) struct Remote { /// `LocalPlayer.showDeathScreen`: off with `immediate_respawn`. show_death_screen: bool, player_type: Option>, - /// Inventory as last synchronised, for creative-mode slot updates. + /// Inventory (then the off hand) as last synchronised, for creative-mode + /// slot updates. synced: Vec>, decode_errors: u32, clock: Option, @@ -510,7 +511,7 @@ impl Game<'_> { death_message: None, show_death_screen: true, player_type, - synced: vec![None; 36], + synced: vec![None; 37], decode_errors: 0, clock: None, clock_rate: 1.0, @@ -4307,12 +4308,14 @@ impl Game<'_> { { out.push(packet); } - // Creative inventory edits are sent slot by slot (SetCreativeModeSlot). + // Creative inventory edits are sent slot by slot (SetCreativeModeSlot); + // `synced[36]` is the off hand. let mut creative_slots = Vec::new(); if self.creative { - for i in 0..36 { - if self.inventory[i] != r.synced[i] { - r.synced[i] = self.inventory[i].clone(); + for i in 0..37 { + let stack = self.inventory.get(i).unwrap_or(&self.offhand); + if *stack != r.synced[i] { + r.synced[i] = stack.clone(); creative_slots.push(i); } } @@ -4321,8 +4324,13 @@ impl Game<'_> { self.send(packet); } for i in creative_slots { - let slot = if i < 9 { 36 + i } else { i } as i16; - let item = self.to_network(&self.inventory[i]); + // InventoryMenu's slots: the hotbar is 36..=44, the off hand 45. + let slot = match i { + 0..9 => 36 + i, + 36 => 45, + _ => i, + } as i16; + let item = self.to_network(self.inventory.get(i).unwrap_or(&self.offhand)); self.send(S::SetCreativeModeSlot(play::SetCreativeModeSlot { slot, item, @@ -4331,7 +4339,8 @@ impl Game<'_> { } /// Inventory as the server last described it. fn remote_synced(&mut self) { - let inventory = self.inventory.clone(); + let mut inventory = self.inventory.clone(); + inventory.push(self.offhand.clone()); if let Some(r) = self.remote.as_mut() { r.synced = inventory; }