Modern Apps git

← Modern-Apps.git

voxels: add Inventory::empty() for the hotbar rules test

Commit
a7936af17aa78a6c1cc47e232c8897c26c0b6cb0
Author
Vayun Mathur <[email protected]>
When
2026-11-07 19:17 UTC (28 days ago)
Parents
8255951
inventory_hotbar_rules_hold assumed Inventory::default() is blank,
but Default is the new-player starter kit (64 stone, dirt, wood,
...), so the very first count assertion saw 65 instead of 1 and the
swap scenario inherited kit slots. The game-design default is
correct; the test now starts from a new explicit Inventory::empty(),
which is also the honest constructor for any blank-state caller.

Verified: cargo +1.97.0 test --locked --tests in
games/voxels/src/main/rust — 122 + 5 passed.

Diff

games/voxels/src/main/rust/src/inventory.rs
diff --git a/games/voxels/src/main/rust/src/inventory.rs b/games/voxels/src/main/rust/src/inventory.rsindex bedb5faafe..6bf75c00c3 100644--- a/games/voxels/src/main/rust/src/inventory.rs+++ b/games/voxels/src/main/rust/src/inventory.rs@@ -256,6 +256,20 @@ const DECOR_CUTS: &[(Block, Block)] = &[     (Block::Netherrack, Block::NetherBricks), ]; +impl Inventory {+    /// A blank inventory: no starter kit (see `Default`, which is the+    /// new-player grant). For tests and anywhere an empty state is meant.+    pub fn empty() -> Self {+        Self {+            selected: 0,+            slots: [InvSlot::default(); SLOTS],+            placed: 0,+            broken: 0,+            armor: [InvSlot::default(); 4],+        }+    }+}+ impl Default for Inventory {     fn default() -> Self {         let mut slots = [InvSlot::default(); SLOTS];
games/voxels/src/main/rust/tests/world_edges.rs
diff --git a/games/voxels/src/main/rust/tests/world_edges.rs b/games/voxels/src/main/rust/tests/world_edges.rsindex cabbcabf97..447f35a8cf 100644--- a/games/voxels/src/main/rust/tests/world_edges.rs+++ b/games/voxels/src/main/rust/tests/world_edges.rs@@ -110,7 +110,9 @@ fn block_predicates_cover_shapes_and_light() {  #[test] fn inventory_hotbar_rules_hold() {-    let mut inv = Inventory::default();+    // The rules below are about an empty inventory; `Inventory::default()`+    // is the new-player starter kit (64 stone among it), not a blank state.+    let mut inv = Inventory::empty();     assert_eq!(inv.selected, 0);     inv.select(HOTBAR + 5);     assert_eq!(inv.selected, 0, "out-of-hotbar selection is ignored");@@ -131,7 +133,7 @@ fn inventory_hotbar_rules_hold() {     assert!(total <= (SLOTS as i32) * (STACK as i32), "capacity is bounded: {total}");     inv.move_item(SLOTS + 1, 0);     inv.move_item(0, 0);-    let mut swap_inv = Inventory::default();+    let mut swap_inv = Inventory::empty();     swap_inv.try_add_block(Block::Stone as u16);     swap_inv.slots[1].id = Block::Dirt as u16;     swap_inv.slots[1].count = 3;