From 481e75bc33bea120cad48a40294fdaf3df2b19aa Mon Sep 17 00:00:00 2001 From: rdbtCVS <87152661+rdbtCVS@users.noreply.github.com> Date: Sun, 25 Oct 2026 19:16:36 +0000 Subject: [PATCH] Clear off-hand items in vanilla inventory slot order Co-Authored-By: OpenAI Codex GPT-6.1 --- crates/horizon-client/src/game/commands.rs | 9 ++++++--- tools/command_exec_corpus.py | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/crates/horizon-client/src/game/commands.rs b/crates/horizon-client/src/game/commands.rs index 19a16e261..1f24c8a4f 100644 --- a/crates/horizon-client/src/game/commands.rs +++ b/crates/horizon-client/src/game/commands.rs @@ -2499,12 +2499,14 @@ impl Game<'_> { }; let max = Self::int(ctx, "maxCount").unwrap_or(-1); let counting = max == 0; - // Inventory.clearOrCountMatchingItems: main, armor, crafting grid, carried. + // Inventory slots 0..40: main, armor feet to head, off hand; + // then clearOrCountMatchingItems visits the crafting grid and carried stack. let mut removed = 0i32; let mut budget = if max < 0 { i32::MAX } else { max }; let all = |g: &Self| -> Vec> { let mut v: Vec> = g.inventory.clone(); - v.extend(g.armor.iter().cloned()); + v.extend(g.armor.iter().rev().cloned()); + v.push(g.offhand.clone()); v.extend(g.craft_grid.iter().cloned()); v.push(g.carried.clone()); v @@ -2518,7 +2520,8 @@ impl Game<'_> { .collect(); let mut slots: Vec<&mut Option> = Vec::new(); slots.extend(self.inventory.iter_mut()); - slots.extend(self.armor.iter_mut()); + slots.extend(self.armor.iter_mut().rev()); + slots.push(&mut self.offhand); slots.extend(self.craft_grid.iter_mut()); slots.push(&mut self.carried); for (slot, matches) in slots.into_iter().zip(matching) { diff --git a/tools/command_exec_corpus.py b/tools/command_exec_corpus.py index 0e376e260..4b24ca80f 100644 --- a/tools/command_exec_corpus.py +++ b/tools/command_exec_corpus.py @@ -182,6 +182,23 @@ def player_state(): cmd('/item modify entity @s weapon.mainhand {type:"minecraft:set_count",count:1}'), cmd('/clear @s'), cmd('/clear @s'), + # Inventory.clearOrCountMatchingItems visits the off hand as well as + # the main inventory, and consumes limited clears in inventory-slot order. + cmd('/item replace entity @s weapon.offhand with minecraft:shield'), + cmd('/clear @s minecraft:shield 0'), + cmd('/clear @s minecraft:shield 1'), + cmd('/clear @s minecraft:shield 0'), + cmd('/item replace entity @s weapon.offhand with minecraft:stone 5'), + cmd('/clear @s minecraft:stone 2'), + cmd('/clear @s minecraft:stone 0'), + cmd('/clear @s'), + cmd('/clear @s minecraft:stone 0'), + cmd('/item replace entity @s armor.head with minecraft:iron_helmet'), + cmd('/item replace entity @s armor.feet with minecraft:iron_boots'), + cmd('/clear @s * 1'), + cmd('/clear @s minecraft:iron_boots 0'), + cmd('/clear @s minecraft:iron_helmet 0'), + cmd('/clear @s'), cmd('/attribute @s minecraft:max_health get'), cmd('/attribute @s minecraft:max_health base get'), cmd('/attribute @s minecraft:max_health base set 30'),