voxels: add shears and wool sheared from sheep
- Commit
28622dac8c556218043c7647535641cd86c40f8f- Author
- Vayun Mathur <[email protected]>
- When
- 2026-08-05 17:16 UTC (4 months ago)
- Parents
87ea781
Diff
games/voxels/src/main/assets/block/shears.png
diff --git a/games/voxels/src/main/assets/block/shears.png b/games/voxels/src/main/assets/block/shears.pngnew file mode 100644index 0000000000..8ee6f11bb9Binary files /dev/null and b/games/voxels/src/main/assets/block/shears.png differ
games/voxels/src/main/assets/block/wool.png
diff --git a/games/voxels/src/main/assets/block/wool.png b/games/voxels/src/main/assets/block/wool.pngnew file mode 100644index 0000000000..8daf3e2f56Binary files /dev/null and b/games/voxels/src/main/assets/block/wool.png differ
games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/Hotbar.kt
diff --git a/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/Hotbar.kt b/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/Hotbar.ktindex 5a8795585f..3190d5731c 100644--- a/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/Hotbar.kt+++ b/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/Hotbar.kt@@ -39,12 +39,12 @@ data class InvSlot(val id: Int, val count: Int) data class InventoryState(val selected: Int = 0, val slots: List<InvSlot> = List(9) { InvSlot(0, 0) }, val armor: List<InvSlot> = emptyList()) // Ids 163..178 and 197..202 are tools/armor whose slot `count` is durability (not a stack size).-fun isDurabilityItem(id: Int) = id in 163..178 || id in 197..202 || id in 239..244 || id == 186 || id == 188+fun isDurabilityItem(id: Int) = id in 163..178 || id in 197..202 || id in 239..244 || id == 186 || id == 188 || id == 252 val maxDurability = mapOf( 163 to 60, 164 to 60, 165 to 132, 166 to 132, 167 to 250, 168 to 250, 169 to 1562, 170 to 1562, 171 to 240, 172 to 240, 173 to 240, 174 to 240, 175 to 528, 176 to 528, 177 to 528, 178 to 528,- 186 to 64, 188 to 432,+ 186 to 64, 188 to 432, 252 to 238, 239 to 700, 240 to 700, 241 to 380, 242 to 380, 243 to 380, 244 to 380, 197 to 2031, 198 to 2031, 199 to 666, 200 to 666, 201 to 666, 202 to 666 )@@ -118,6 +118,7 @@ val blockNames = mapOf( 197 to "Adamant Pickaxe", 198 to "Adamant Sword", 199 to "Adamant Helmet", 200 to "Adamant Chestplate", 201 to "Adamant Leggings", 202 to "Adamant Boots", // Matcha's building set: slabs and stairs, cut on a stonecutter.+ 119 to "Wool", 252 to "Shears", 102 to "Stone Slab", 103 to "Stone Stairs", 104 to "Cobble Slab", 105 to "Cobble Stairs", 106 to "Plank Slab", 107 to "Plank Stairs", 108 to "Brick Slab", 109 to "Brick Stairs", 110 to "Sandstone Slab", 111 to "Sandstone Stairs",@@ -164,6 +165,7 @@ val blockIconFile = mapOf( 212 to "blessing_will.png", 213 to "blessing_hyacinthus.png", 214 to "blessing_aeolus.png", 215 to "blessing_cronus.png", 216 to "blessing_demeter.png", 217 to "blessing_glaucus.png", 218 to "blessing_apollo.png", 219 to "blessing_artemis.png", 220 to "blessing_warding.png",+ 119 to "wool.png", 252 to "shears.png", 221 to "blessing_paris.png", 245 to "blessing_athena.png", 246 to "blessing_sekhmet.png", 247 to "blessing_camazotz.png", 248 to "blessing_tangaroa.png", 249 to "blessing_anubis.png",@@ -219,10 +221,10 @@ val catalogBlessings = listOf(160, 161, 162, 203, 204, 205, 206, 207, 208, 209, val catalogGear = listOf(163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 186, 188, 239, 240, 241, 242, 243, 244,- 197, 198, 199, 200, 201, 202)+ 197, 198, 199, 200, 201, 202, 252) val catalogMusic = listOf(82, 179, 180, 181, 182, 183, 184, 185) val catalogBuilding = listOf(10, 27, 30, 49, 52, 8, 57, 9, 53, 54, 55, 56, 58, 59, 72, 74, 76, 77, 78, 81, 7, 33, 34, 35, 96, 118, 88, 89,- 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117)+ 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 119) @Composable fun rememberBlockIcon(id: Int): androidx.compose.ui.graphics.ImageBitmap? {
games/voxels/src/main/rust/shaders/atlas.bin
diff --git a/games/voxels/src/main/rust/shaders/atlas.bin b/games/voxels/src/main/rust/shaders/atlas.binindex f2da2b78fe..8ca28db8d0 100644Binary files a/games/voxels/src/main/rust/shaders/atlas.bin and b/games/voxels/src/main/rust/shaders/atlas.bin differ
games/voxels/src/main/rust/src/engine.rs
diff --git a/games/voxels/src/main/rust/src/engine.rs b/games/voxels/src/main/rust/src/engine.rsindex 8a7e4aed8e..e176246409 100644--- a/games/voxels/src/main/rust/src/engine.rs+++ b/games/voxels/src/main/rust/src/engine.rs@@ -1597,6 +1597,8 @@ fn slayer_mult(player: &Player, kind: MobKind) -> f32 { let horror = matches!(kind, MobKind::Creeper | MobKind::Shulker | MobKind::Ghast); if (is_undead(kind) && player.blessed(Passive::SmiteUndead)) || (horror && player.blessed(Passive::BaneOfHorrors)) { 2.0 } else { 1.0 } }+/// Wool from one shearing. A sheep only carries one coat, so this is the whole yield.+const WOOL_PER_SHEARING: i32 = 3; /// Anubis keeps the dead this far back. const WARD_UNDEAD_RADIUS: f32 = 6.0; pub fn is_undead(kind: MobKind) -> bool {@@ -1734,6 +1736,15 @@ pub fn place_block_at(px: f32, py: f32) -> i32 { state.trade_prof = state.mobs[idx].profession; return 20; }+ // Shearing a sheep: wool now, and the sheep walks away unharmed to regrow it.+ let held = state.inventory.selected_block();+ if crate::item::is_shears(held) && state.mobs[idx].kind == MobKind::Sheep && !state.mobs[idx].sheared {+ if !state.inventory.has_room_for(Block::Wool as u8, WOOL_PER_SHEARING) { return 0; }+ state.mobs[idx].sheared = true;+ for _ in 0..WOOL_PER_SHEARING { state.inventory.add_block(Block::Wool as u8); }+ damage_tool(state);+ return 1;+ } } if let Some(hit) = block_hit { let (x, y, z) = hit.pos;
games/voxels/src/main/rust/src/entity.rs
diff --git a/games/voxels/src/main/rust/src/entity.rs b/games/voxels/src/main/rust/src/entity.rsindex ce898be342..216f75ac7c 100644--- a/games/voxels/src/main/rust/src/entity.rs+++ b/games/voxels/src/main/rust/src/entity.rs@@ -185,6 +185,8 @@ pub struct Mob { /// Radius the mob refuses to come inside, set by the engine each tick. Anubis pushes the undead /// back; everything else leaves this at zero. pub repelled: f32,+ /// Sheep only: its coat has already been taken.+ pub sheared: bool, } /// Per-spawn stat jitter. Matcha retunes mobs by type; this adds variation *within* a type so an@@ -241,7 +243,7 @@ impl Mob { Mob { kind, pos, vel: Vec3::ZERO, yaw: 0.0, health: v.health, attack_cd: 0.0, fuse: 0.0, target_yaw: 0.0, wander: 0.0, anim: 0.0, on_ground: false, rng: seed | 1, profession: crate::villager::Profession::from_seed(seed | 1).index() as u8,- max_health: v.health, speed: v.speed, elite: v.elite, repelled: 0.0 }+ max_health: v.health, speed: v.speed, elite: v.elite, repelled: 0.0, sheared: false } } pub fn tick(&mut self, dt: f32, player: Vec3, terrain: &Terrain) {
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 c7bac919a2..ad193b6068 100644--- a/games/voxels/src/main/rust/src/inventory.rs+++ b/games/voxels/src/main/rust/src/inventory.rs@@ -24,8 +24,9 @@ pub struct Inventory { // (in1_id, in1_count, in2_id, in2_count, out_id, out_count). in2_id == 0 means a single ingredient. // Item ids 154+ are materials/tools (see item.rs). Ore -> material conversions live in SMELTING // instead, since those need a furnace, fuel and time.-pub const RECIPES: [(u8, i32, u8, i32, u8, i32); 91] = [+pub const RECIPES: [(u8, i32, u8, i32, u8, i32); 92] = [ (154, 1, 157, 1, 186, 1), // iron + coal -> flint & steel+ (154, 2, 0, 0, 252, 1), // iron -> shears (187, 1, Block::Glass as u8, 5, Block::Beacon as u8, 1), // nether star + glass -> beacon (138, 2, 0, 0, 189, 3), // gunpowder -> firework rockets (Block::Snow as u8, 1, 0, 0, 190, 4), // snow -> snowballs
games/voxels/src/main/rust/src/item.rs
diff --git a/games/voxels/src/main/rust/src/item.rs b/games/voxels/src/main/rust/src/item.rsindex 6f65c8dde3..89d2163fba 100644--- a/games/voxels/src/main/rust/src/item.rs+++ b/games/voxels/src/main/rust/src/item.rs@@ -39,7 +39,9 @@ pub fn is_food(id: u8) -> bool { food_effects(id).is_some() } // Tools 163..170: {wood,stone,iron,diamond} x {pickaxe,sword}. Armor 171..178: {iron,diamond} x // {helmet,chestplate,leggings,boots}. Matcha's bronze sits between iron and diamond at 239..244, // and adamant tops the ladder at 197..202. Durability is stored in the inventory slot's `count`.-pub fn is_tool(id: u8) -> bool { (163..=170).contains(&id) || matches!(id, 197 | 198 | 239 | 240) }+pub fn is_tool(id: u8) -> bool { (163..=170).contains(&id) || matches!(id, 197 | 198 | 239 | 240 | 252) }+/// Shears: used on a sheep rather than on terrain, so they're a tool that mines nothing.+pub fn is_shears(id: u8) -> bool { id == 252 } pub fn is_pickaxe(id: u8) -> bool { matches!(id, 163 | 165 | 167 | 169 | 197 | 239) } pub fn is_sword(id: u8) -> bool { matches!(id, 164 | 166 | 168 | 170 | 198 | 240) } pub fn is_elytra(id: u8) -> bool { id == 188 }@@ -73,6 +75,7 @@ pub fn max_durability(id: u8) -> i32 { 163 | 164 => 60, 165 | 166 => 132, 167 | 168 => 250, 169 | 170 => 1562, // wood/stone/iron/diamond tools 171..=174 => 240, 175..=178 => 528, // iron/diamond armor 186 => 64, // flint & steel+ 252 => 238, // shears 188 => 432, // elytra 197 | 198 => 2031, // adamant tools 199..=202 => 666, // adamant armor@@ -150,7 +153,11 @@ mod tests { fn tools_and_armor_do_not_overlap() { for id in 0..=255u8 { assert!(!(is_tool(id) && is_armor(id)), "{id} is both a tool and armor");- if is_tool(id) { assert!(is_pickaxe(id) ^ is_sword(id), "{id} must be exactly one tool kind"); }+ // Shears are the exception: a tool that neither mines nor fights.+ if is_tool(id) && !is_shears(id) {+ assert!(is_pickaxe(id) ^ is_sword(id), "{id} must be exactly one tool kind");+ }+ if is_shears(id) { assert!(!is_pickaxe(id) && !is_sword(id), "shears are not a weapon"); } if is_tool(id) || is_armor(id) { assert!(max_durability(id) > 0, "{id} has no durability"); } } }
games/voxels/src/main/rust/src/world/block.rs
diff --git a/games/voxels/src/main/rust/src/world/block.rs b/games/voxels/src/main/rust/src/world/block.rsindex 1ecff01db9..983b3622a4 100644--- a/games/voxels/src/main/rust/src/world/block.rs+++ b/games/voxels/src/main/rust/src/world/block.rs@@ -129,9 +129,11 @@ pub enum Block { PurpurSlab = 116, PurpurStairs = 117, Stonecutter = 118,+ /// Sheared from sheep; the game's first block that can't be mined out of the ground.+ Wool = 119, } -pub const MAX_BLOCK_ID: u8 = 118;+pub const MAX_BLOCK_ID: u8 = 119; /// The geometry a block occupies within its cell. #[derive(Clone, Copy, Debug, PartialEq, Eq)]@@ -414,6 +416,7 @@ impl Block { Self::GoldBlock => 139, Self::BronzeBlock => 140, Self::Stonecutter => 141,+ Self::Wool => 143, // Slabs and stairs are textured entirely from their parent material. Self::StoneSlab | Self::StoneStairs => Self::Stone.tile_top(), Self::CobbleSlab | Self::CobbleStairs => Self::Cobble.tile_top(),
scripts/voxels/build_atlas.py
diff --git a/scripts/voxels/build_atlas.py b/scripts/voxels/build_atlas.pyindex 62ee27d5c2..8c99e9361e 100644--- a/scripts/voxels/build_atlas.py+++ b/scripts/voxels/build_atlas.py@@ -70,6 +70,7 @@ NEW_TILES = { # cave, and ocean specials). Each is a solid colour with light deterministic speckle so it reads as a # textured block rather than a flat swatch. PROC_TILES = {+ 143: (236, 238, 234), # wool (soft off-white; the pack never retextures it) 97: (52, 90, 235), # tube coral (blue) 98: (240, 116, 168), # brain coral (pink) 99: (178, 52, 216), # bubble coral (purple)@@ -133,6 +134,7 @@ COPY_ICONS = { "adamant_leggings.png": ("item", "netherite_leggings.png"), "adamant_boots.png": ("item", "netherite_boots.png"), "silver_ingot.png": ("item", "prismarine_crystals.png"),+ "shears.png": ("item", "shears.png"), "quicksilver.png": ("item", "prismarine_shard.png"), # The blessing pantheon. Items only: a blessing is never placed as a block, so no atlas tile. **{f"blessing_{n}.png": ("item", f"blessing_{n}.png") for n in (@@ -186,6 +188,7 @@ PROC_ICON = { 136: "copper_ore.png", 137: "gold_ore.png", 138: "copper_block.png", 139: "gold_block.png", 140: "bronze_block.png", 141: "stonecutter.png",+ 143: "wool.png", }