From 626068da3aec4bef2e45a5b1d19a89f010a8eb4a Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 28 Oct 2026 10:40:11 +0300 Subject: [PATCH] Inventory draw: a slot is drawn from a reference, not a copy draw_slot_item needs neither ownership nor &mut self: it reads the carried stack only for a drag. Taking `&Option` and &self drops the copy every caller made, including the two the creative hotbar made per slot each frame (and one clone per hovered slot becomes a clone only when hovered). Co-Authored-By: Hermes Agent (Nous Research) --- crates/horizon-client/src/game.rs | 25 ++++++++++------------ crates/horizon-client/src/game/stations.rs | 2 +- crates/horizon-client/src/game/trading.rs | 2 +- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 1d7bbbbd6..759d3d019 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -5766,30 +5766,28 @@ impl Game<'_> { /// highlight (its count yellow when the slot caps it), and hides while /// it is the drag's only slot. fn draw_slot_item( - &mut self, + &self, batch: &mut HudBatch, drag: Option<&DragView>, slot: usize, - stack: Option, + stack: &Option, x: f32, y: f32, ) { + let carried; let (stack, capped) = match drag.and_then(|d| d.slots.get(&slot)) { Some(None) => return, Some(Some((count, capped))) => { batch.fill(&self.gui.atlas, x, y, 16.0, 16.0, rgba(255, 255, 255, 128)); - let carried = self - .carried - .clone() - .map(|c| ItemStack { count: *count, ..c }); - (carried, *capped) + carried = self.carried.clone().map(|c| ItemStack { count: *count, ..c }); + (carried.as_ref(), *capped) } - None => (stack, false), + None => (stack.as_ref(), false), }; if let Some(stack) = stack { - self.draw_item_model(batch, &stack, x, y); + self.draw_item_model(batch, stack, x, y); let text = capped.then(|| format!("\u{a7}e{}", stack.count)); - self.draw_item_decorations(batch, &stack, x, y, text); + self.draw_item_decorations(batch, stack, x, y, text); } } /// `extractCarriedItem`: the carried stack at the cursor, showing what a @@ -6407,7 +6405,7 @@ impl Game<'_> { ); } let stack = self.slot_view(i); - self.draw_slot_item(batch, drag.as_ref(), i, stack, ox + sx, oy + sy); + self.draw_slot_item(batch, drag.as_ref(), i, &stack, ox + sx, oy + sy); } } fn draw_inventory(&mut self, batch: &mut HudBatch) { @@ -11200,15 +11198,14 @@ impl Game<'_> { let drag = self.drag_view(); for c in 0..9 { let (x, y) = (ox + 9.0 + c as f32 * 18.0, oy + 112.0); - let stack = self.inventory[c].clone(); - self.draw_slot_item(batch, drag.as_ref(), c, stack.clone(), x, y); + self.draw_slot_item(batch, drag.as_ref(), c, &self.inventory[c], x, y); if self.cursor.0 >= x && self.cursor.0 < x + 16.0 && self.cursor.1 >= y && self.cursor.1 < y + 16.0 { batch.fill(&self.gui.atlas, x, y, 16.0, 16.0, rgba(255, 255, 255, 128)); - hovered = stack; + hovered = self.inventory[c].clone(); } } let scrollable = self.creative_screen.rows(&self.pack.names) > 5; diff --git a/crates/horizon-client/src/game/stations.rs b/crates/horizon-client/src/game/stations.rs index 38064caad..bbd564cb3 100644 --- a/crates/horizon-client/src/game/stations.rs +++ b/crates/horizon-client/src/game/stations.rs @@ -1643,7 +1643,7 @@ impl Game<'_> { continue; }; let stack = self.slot_mut(i).clone(); - self.draw_slot_item(batch, drag.as_ref(), i, stack, ox + sx, oy + sy); + self.draw_slot_item(batch, drag.as_ref(), i, &stack, ox + sx, oy + sy); } if let Some(slot) = self.slot_at(batch, self.cursor.0, self.cursor.1) { let (sx, sy) = self.slot_position(slot); diff --git a/crates/horizon-client/src/game/trading.rs b/crates/horizon-client/src/game/trading.rs index 0f8723737..61f6a93c5 100644 --- a/crates/horizon-client/src/game/trading.rs +++ b/crates/horizon-client/src/game/trading.rs @@ -783,7 +783,7 @@ impl Game<'_> { for i in slots { let (sx, sy) = self.slot_position(i); let stack = self.slot_mut(i).clone(); - self.draw_slot_item(batch, drag.as_ref(), i, stack, ox + sx, oy + sy); + self.draw_slot_item(batch, drag.as_ref(), i, &stack, ox + sx, oy + sy); } if let Some(slot) = self.slot_at(batch, self.cursor.0, self.cursor.1) { let (sx, sy) = self.slot_position(slot);