voxels: add archaeology with suspicious sand and a brush
- Commit
b98ed273421a014caa55c84fe3129d6114eac326- Author
- Vayun Mathur <[email protected]>
- When
- 2026-08-05 18:17 UTC (4 months ago)
- Parents
fd7fa87
Diff
games/voxels/src/main/assets/block/brush.png
diff --git a/games/voxels/src/main/assets/block/brush.png b/games/voxels/src/main/assets/block/brush.pngnew file mode 100644index 0000000000..334bff5c87Binary files /dev/null and b/games/voxels/src/main/assets/block/brush.png differ
games/voxels/src/main/assets/block/suspicious_sand_0.png
diff --git a/games/voxels/src/main/assets/block/suspicious_sand_0.png b/games/voxels/src/main/assets/block/suspicious_sand_0.pngnew file mode 100644index 0000000000..df91dc1ad1Binary files /dev/null and b/games/voxels/src/main/assets/block/suspicious_sand_0.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 0ff91cd7f7..b49efe337c 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 || id in 252..253+fun isDurabilityItem(id: Int) = id in 163..178 || id in 197..202 || id in 239..244 || id == 186 || id == 188 || id in 252..253 || id == 255 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, 252 to 238, 253 to 64,+ 186 to 64, 188 to 432, 252 to 238, 253 to 64, 255 to 64, 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,7 +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", 253 to "Fishing Rod", 254 to "Raw Fish",+ 119 to "Wool", 120 to "Suspicious Sand", 252 to "Shears", 253 to "Fishing Rod", 254 to "Raw Fish", 255 to "Brush", 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",@@ -165,7 +165,8 @@ 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", 253 to "fishing_rod.png", 254 to "raw_fish.png",+ 119 to "wool.png", 120 to "suspicious_sand.png", 252 to "shears.png", 253 to "fishing_rod.png",+ 254 to "raw_fish.png", 255 to "brush.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",@@ -206,7 +207,7 @@ val blockIconFile = mapOf( // Creative catalog, split into tabs. val catalogNatural = listOf(3, 2, 40, 46, 60, 39, 41, 71, 1, 6, 38, 36, 37, 14, 16, 17, 15, 45, 79, 75, 70,- 4, 5, 26, 28, 29, 31, 47, 48, 50, 51, 80, 11, 42, 43, 44, 32, 84, 85, 13)+ 4, 5, 26, 28, 29, 31, 47, 48, 50, 51, 80, 11, 42, 43, 44, 32, 84, 85, 13, 120) val catalogOres = listOf(18, 19, 20, 21, 22, 90, 91, 92, 97, 98, 23, 24, 25, 93, 94, 95, 99, 100, 101, 73) val catalogOcean = listOf(61, 62, 63, 64, 65, 66, 67, 68, 69) val catalogItems = listOf(128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138,@@ -221,7 +222,7 @@ 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, 252, 253)+ 197, 198, 199, 200, 201, 202, 252, 253, 255) 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, 119)
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 8ca28db8d0..80be716704 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 2d152aef94..9b5f9e4544 100644--- a/games/voxels/src/main/rust/src/engine.rs+++ b/games/voxels/src/main/rust/src/engine.rs@@ -1316,6 +1316,28 @@ fn do_break(state: &mut EngineState, origin: Vec3, dir: Vec3) -> bool { return true; } }+ // Brushing: sweep suspicious sand for whatever was buried in it. The sand stays behind either+ // way, so a dig site can't be turned into a hole by accident.+ if sel == crate::item::BRUSH {+ if let Some(hit) = crate::raycast::raycast(&state.chunks, origin, dir, player_reach(state)) {+ let (x, y, z) = hit.pos;+ if state.chunks.get_block_world(x, y, z) == Block::SuspiciousSand as u8 {+ let mut r = state.spawn_rng;+ r ^= r << 13; r ^= r >> 17; r ^= r << 5;+ state.spawn_rng = r;+ let id = buried_find((r >> 8) as f32 / 16_777_216.0);+ if !state.inventory.has_room_for(id, 1) { return false; }+ state.inventory.add_block(id);+ state.chunks.set_block_world(x, y, z, Block::Sand as u8);+ mark_neighbors_dirty(state, x, z);+ damage_tool(state);+ let c = vec3(x as f32 + 0.5, y as f32 + 1.0, z as f32 + 0.5);+ spawn_particles(&mut state.spawn_rng, &mut state.particles, c, 12, [0.86, 0.78, 0.58], 2.5, 0.6, 0.1);+ return true;+ }+ }+ return false;+ } // Fishing: the first tap casts into water, the second strikes. Striking on a bite lands a catch; // striking early just reels the line back in. if sel == crate::fishing::ROD && state.player.eat_cd <= 0.0 {@@ -1656,6 +1678,19 @@ 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 } }+/// What a dig site gives up. Matcha's archaeology yields pottery sherds, which this game doesn't+/// model, so the pool is the small treasures a buried cache would plausibly hold.+pub fn buried_find(roll: f32) -> u8 {+ match (roll.clamp(0.0, 0.999) * 100.0) as u32 {+ 0..=29 => 137, // leather scraps+ 30..=54 => 236, // copper ingot+ 55..=74 => Block::Amethyst as u8,+ 75..=89 => 237, // gold ingot+ 90..=96 => 156, // emerald+ _ => 155, // diamond+ }+}+ /// March along the aim direction looking for the top of a body of water to drop a float onto. fn water_surface_along(state: &EngineState, origin: Vec3, dir: Vec3, max_dist: f32) -> Option<[f32; 3]> { let mut t = 1.0f32;@@ -1897,6 +1932,21 @@ mod tests { assert!((CLAMP / DAY_CYCLE).fract() < 1e-6, "the world_secs clamp must be a whole number of days"); } + // A dig site has to be worth digging: every roll gives a real item, most of them modest.+ #[test]+ fn every_buried_find_is_a_real_item() {+ let mut diamonds = 0;+ let n = 10_000;+ for i in 0..n {+ let id = buried_find(i as f32 / n as f32);+ assert!(id != 0, "an empty dig site");+ assert!(id <= crate::world::block::MAX_BLOCK_ID || crate::item::is_item(id), "{id} is not an id");+ if id == 155 { diamonds += 1; }+ }+ let rate = diamonds as f32 / n as f32;+ assert!(rate > 0.0 && rate < 0.06, "diamonds turn up {rate} of the time, which is not a treasure");+ }+ // The weather is a random walk, so what matters is that it can't wander somewhere invalid and that // clear skies stay the common case rather than the game raining most of the time. #[test]
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 ca972bafbd..8a49e2c135 100644--- a/games/voxels/src/main/rust/src/inventory.rs+++ b/games/voxels/src/main/rust/src/inventory.rs@@ -24,10 +24,11 @@ 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); 93] = [+pub const RECIPES: [(u8, i32, u8, i32, u8, i32); 94] = [ (154, 1, 157, 1, 186, 1), // iron + coal -> flint & steel (154, 2, 0, 0, 252, 1), // iron -> shears (159, 3, 137, 2, 253, 1), // sticks + leather -> fishing rod+ (159, 1, 236, 1, 255, 1), // stick + copper -> archaeologist's brush (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 42e6e384b1..9f2d20f30a 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 | 252 | 253) }+pub fn is_tool(id: u8) -> bool { (163..=170).contains(&id) || matches!(id, 197 | 198 | 239 | 240 | 252 | 253 | 255) }+/// Item 255. Brushing suspicious sand is the only thing it does.+pub const BRUSH: u8 = 255; /// 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) }@@ -77,6 +79,7 @@ pub fn max_durability(id: u8) -> i32 { 186 => 64, // flint & steel 252 => 238, // shears 253 => 64, // fishing rod+ 255 => 64, // brush 188 => 432, // elytra 197 | 198 => 2031, // adamant tools 199..=202 => 666, // adamant armor@@ -155,7 +158,7 @@ mod tests { for id in 0..=255u8 { assert!(!(is_tool(id) && is_armor(id)), "{id} is both a tool and armor"); // Shears and the fishing rod are the exceptions: tools that neither mine nor fight.- if is_tool(id) && !is_shears(id) && id != crate::fishing::ROD {+ if is_tool(id) && !is_shears(id) && id != crate::fishing::ROD && id != BRUSH { 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"); }
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 983b3622a4..84b054c013 100644--- a/games/voxels/src/main/rust/src/world/block.rs+++ b/games/voxels/src/main/rust/src/world/block.rs@@ -131,9 +131,11 @@ pub enum Block { Stonecutter = 118, /// Sheared from sheep; the game's first block that can't be mined out of the ground. Wool = 119,+ /// Buried finds. Brushing it yields loot and leaves plain sand behind; mining it just gives sand.+ SuspiciousSand = 120, } -pub const MAX_BLOCK_ID: u8 = 119;+pub const MAX_BLOCK_ID: u8 = 120; /// The geometry a block occupies within its cell. #[derive(Clone, Copy, Debug, PartialEq, Eq)]@@ -417,6 +419,7 @@ impl Block { Self::BronzeBlock => 140, Self::Stonecutter => 141, Self::Wool => 143,+ Self::SuspiciousSand => 144, // 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(),
games/voxels/src/main/rust/src/world/generator.rs
diff --git a/games/voxels/src/main/rust/src/world/generator.rs b/games/voxels/src/main/rust/src/world/generator.rsindex ad1c2c710a..254787973b 100644--- a/games/voxels/src/main/rust/src/world/generator.rs+++ b/games/voxels/src/main/rust/src/world/generator.rs@@ -597,6 +597,10 @@ impl TerrainGen { let surface: u8 = if h < 62 { match biome { Biome::Badlands => 36, Biome::SnowyPlains | Biome::SnowyTaiga | Biome::IceSpikes | Biome::FrozenPeaks | Biome::SnowySlopes => 11, _ => 6 } } else { surface_top };+ // Buried finds hide in sand, wherever sand happens to be the surface.+ let surface = if matches!(surface, 6 | 36) && hash3(wx as i32, wz as i32, 0x5A9D) % 900 == 0 {+ crate::world::block::Block::SuspiciousSand as u8+ } else { surface }; chunk.set_block(dx, h, dz, surface); if h > 1 && !self.cave_at(wx, (h-1) as f64, wz) { chunk.set_block(dx, h - 1, dz, sub); } }
scripts/voxels/build_atlas.py
diff --git a/scripts/voxels/build_atlas.py b/scripts/voxels/build_atlas.pyindex 3b2a8e5f77..2d80ec642b 100644--- a/scripts/voxels/build_atlas.py+++ b/scripts/voxels/build_atlas.py@@ -29,6 +29,7 @@ NEW_H = NEW_ROWS * TILE # New tiles: atlas index -> source PNG filename in the pack. Indices 0..63 are copied from the old # atlas untouched; new blocks start at 64. NEW_TILES = {+ 144: "suspicious_sand_0.png", 64: "red_sand.png", 65: "red_sandstone.png", 66: "red_sandstone_top.png",@@ -136,6 +137,7 @@ COPY_ICONS = { "silver_ingot.png": ("item", "prismarine_crystals.png"), "shears.png": ("item", "shears.png"), "raw_fish.png": ("item", "catfish.png"),+ "brush.png": ("item", "archaeologists_brush.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 (@@ -192,6 +194,7 @@ PROC_ICON = { 138: "copper_block.png", 139: "gold_block.png", 140: "bronze_block.png", 141: "stonecutter.png", 143: "wool.png",+ 144: "suspicious_sand.png", }