Modern Apps git

← Modern-Apps.git

voxels: more blocks, mobs, etc.

Commit
2dcceb84db3e47924bf8c7778b5503098a7c81b7
Author
Vayun Mathur <[email protected]>
When
2026-07-29 18:16 UTC (4 months ago)
Parents
8883597

Diff

games/voxels/src/main/assets/block/acacia_log.png
diff --git a/games/voxels/src/main/assets/block/acacia_log.png b/games/voxels/src/main/assets/block/acacia_log.pngnew file mode 100644index 0000000000..13b274ee12Binary files /dev/null and b/games/voxels/src/main/assets/block/acacia_log.png differ
games/voxels/src/main/assets/block/acacia_log_top.png
diff --git a/games/voxels/src/main/assets/block/acacia_log_top.png b/games/voxels/src/main/assets/block/acacia_log_top.pngnew file mode 100644index 0000000000..be00818862Binary files /dev/null and b/games/voxels/src/main/assets/block/acacia_log_top.png differ
games/voxels/src/main/assets/block/amethyst.png
diff --git a/games/voxels/src/main/assets/block/amethyst.png b/games/voxels/src/main/assets/block/amethyst.pngnew file mode 100644index 0000000000..d72c888e42Binary files /dev/null and b/games/voxels/src/main/assets/block/amethyst.png differ
games/voxels/src/main/assets/block/azalea_leaves.png
diff --git a/games/voxels/src/main/assets/block/azalea_leaves.png b/games/voxels/src/main/assets/block/azalea_leaves.pngnew file mode 100644index 0000000000..83c96ec131Binary files /dev/null and b/games/voxels/src/main/assets/block/azalea_leaves.png differ
games/voxels/src/main/assets/block/brain_coral.png
diff --git a/games/voxels/src/main/assets/block/brain_coral.png b/games/voxels/src/main/assets/block/brain_coral.pngnew file mode 100644index 0000000000..7ed5a3e809Binary files /dev/null and b/games/voxels/src/main/assets/block/brain_coral.png differ
games/voxels/src/main/assets/block/bubble_coral.png
diff --git a/games/voxels/src/main/assets/block/bubble_coral.png b/games/voxels/src/main/assets/block/bubble_coral.pngnew file mode 100644index 0000000000..0b421f903aBinary files /dev/null and b/games/voxels/src/main/assets/block/bubble_coral.png differ
games/voxels/src/main/assets/block/calcite.png
diff --git a/games/voxels/src/main/assets/block/calcite.png b/games/voxels/src/main/assets/block/calcite.pngnew file mode 100644index 0000000000..48c4bbf2b7Binary files /dev/null and b/games/voxels/src/main/assets/block/calcite.png differ
games/voxels/src/main/assets/block/clay.png
diff --git a/games/voxels/src/main/assets/block/clay.png b/games/voxels/src/main/assets/block/clay.pngnew file mode 100644index 0000000000..e44245b093Binary files /dev/null and b/games/voxels/src/main/assets/block/clay.png differ
games/voxels/src/main/assets/block/coarse_dirt.png
diff --git a/games/voxels/src/main/assets/block/coarse_dirt.png b/games/voxels/src/main/assets/block/coarse_dirt.pngnew file mode 100644index 0000000000..5fe81fd6d8Binary files /dev/null and b/games/voxels/src/main/assets/block/coarse_dirt.png differ
games/voxels/src/main/assets/block/cobbled_deepslate.png
diff --git a/games/voxels/src/main/assets/block/cobbled_deepslate.png b/games/voxels/src/main/assets/block/cobbled_deepslate.pngnew file mode 100644index 0000000000..9f9b9ecd7dBinary files /dev/null and b/games/voxels/src/main/assets/block/cobbled_deepslate.png differ
games/voxels/src/main/assets/block/dark_oak_leaves.png
diff --git a/games/voxels/src/main/assets/block/dark_oak_leaves.png b/games/voxels/src/main/assets/block/dark_oak_leaves.pngnew file mode 100644index 0000000000..052f14c7d1Binary files /dev/null and b/games/voxels/src/main/assets/block/dark_oak_leaves.png differ
games/voxels/src/main/assets/block/dark_oak_log.png
diff --git a/games/voxels/src/main/assets/block/dark_oak_log.png b/games/voxels/src/main/assets/block/dark_oak_log.pngnew file mode 100644index 0000000000..55e3c14db9Binary files /dev/null and b/games/voxels/src/main/assets/block/dark_oak_log.png differ
games/voxels/src/main/assets/block/dark_oak_log_top.png
diff --git a/games/voxels/src/main/assets/block/dark_oak_log_top.png b/games/voxels/src/main/assets/block/dark_oak_log_top.pngnew file mode 100644index 0000000000..2c625d4003Binary files /dev/null and b/games/voxels/src/main/assets/block/dark_oak_log_top.png differ
games/voxels/src/main/assets/block/dark_oak_planks.png
diff --git a/games/voxels/src/main/assets/block/dark_oak_planks.png b/games/voxels/src/main/assets/block/dark_oak_planks.pngnew file mode 100644index 0000000000..ef715cb71cBinary files /dev/null and b/games/voxels/src/main/assets/block/dark_oak_planks.png differ
games/voxels/src/main/assets/block/dark_prismarine.png
diff --git a/games/voxels/src/main/assets/block/dark_prismarine.png b/games/voxels/src/main/assets/block/dark_prismarine.pngnew file mode 100644index 0000000000..f3d088a8c7Binary files /dev/null and b/games/voxels/src/main/assets/block/dark_prismarine.png differ
games/voxels/src/main/assets/block/deepslate_bricks.png
diff --git a/games/voxels/src/main/assets/block/deepslate_bricks.png b/games/voxels/src/main/assets/block/deepslate_bricks.pngnew file mode 100644index 0000000000..fe579df979Binary files /dev/null and b/games/voxels/src/main/assets/block/deepslate_bricks.png differ
games/voxels/src/main/assets/block/dripstone.png
diff --git a/games/voxels/src/main/assets/block/dripstone.png b/games/voxels/src/main/assets/block/dripstone.pngnew file mode 100644index 0000000000..3369e345aaBinary files /dev/null and b/games/voxels/src/main/assets/block/dripstone.png differ
games/voxels/src/main/assets/block/end_stone_bricks.png
diff --git a/games/voxels/src/main/assets/block/end_stone_bricks.png b/games/voxels/src/main/assets/block/end_stone_bricks.pngnew file mode 100644index 0000000000..4112b1c272Binary files /dev/null and b/games/voxels/src/main/assets/block/end_stone_bricks.png differ
games/voxels/src/main/assets/block/farmland.png
diff --git a/games/voxels/src/main/assets/block/farmland.png b/games/voxels/src/main/assets/block/farmland.pngnew file mode 100644index 0000000000..478138c627Binary files /dev/null and b/games/voxels/src/main/assets/block/farmland.png differ
games/voxels/src/main/assets/block/fire_coral.png
diff --git a/games/voxels/src/main/assets/block/fire_coral.png b/games/voxels/src/main/assets/block/fire_coral.pngnew file mode 100644index 0000000000..4418f5a167Binary files /dev/null and b/games/voxels/src/main/assets/block/fire_coral.png differ
games/voxels/src/main/assets/block/glowstone.png
diff --git a/games/voxels/src/main/assets/block/glowstone.png b/games/voxels/src/main/assets/block/glowstone.pngnew file mode 100644index 0000000000..66446f84c8Binary files /dev/null and b/games/voxels/src/main/assets/block/glowstone.png differ
games/voxels/src/main/assets/block/granite_bricks.png
diff --git a/games/voxels/src/main/assets/block/granite_bricks.png b/games/voxels/src/main/assets/block/granite_bricks.pngnew file mode 100644index 0000000000..bfa1c76ecbBinary files /dev/null and b/games/voxels/src/main/assets/block/granite_bricks.png differ
games/voxels/src/main/assets/block/hay_block_side.png
diff --git a/games/voxels/src/main/assets/block/hay_block_side.png b/games/voxels/src/main/assets/block/hay_block_side.pngnew file mode 100644index 0000000000..92635ebc89Binary files /dev/null and b/games/voxels/src/main/assets/block/hay_block_side.png differ
games/voxels/src/main/assets/block/hay_block_top.png
diff --git a/games/voxels/src/main/assets/block/hay_block_top.png b/games/voxels/src/main/assets/block/hay_block_top.pngnew file mode 100644index 0000000000..a38ab5a821Binary files /dev/null and b/games/voxels/src/main/assets/block/hay_block_top.png differ
games/voxels/src/main/assets/block/horn_coral.png
diff --git a/games/voxels/src/main/assets/block/horn_coral.png b/games/voxels/src/main/assets/block/horn_coral.pngnew file mode 100644index 0000000000..2771bc2aa5Binary files /dev/null and b/games/voxels/src/main/assets/block/horn_coral.png differ
games/voxels/src/main/assets/block/jungle_log.png
diff --git a/games/voxels/src/main/assets/block/jungle_log.png b/games/voxels/src/main/assets/block/jungle_log.pngnew file mode 100644index 0000000000..cbf451fd3bBinary files /dev/null and b/games/voxels/src/main/assets/block/jungle_log.png differ
games/voxels/src/main/assets/block/jungle_log_top.png
diff --git a/games/voxels/src/main/assets/block/jungle_log_top.png b/games/voxels/src/main/assets/block/jungle_log_top.pngnew file mode 100644index 0000000000..d9cb2eb940Binary files /dev/null and b/games/voxels/src/main/assets/block/jungle_log_top.png differ
games/voxels/src/main/assets/block/jungle_planks.png
diff --git a/games/voxels/src/main/assets/block/jungle_planks.png b/games/voxels/src/main/assets/block/jungle_planks.pngnew file mode 100644index 0000000000..95f1fce870Binary files /dev/null and b/games/voxels/src/main/assets/block/jungle_planks.png differ
games/voxels/src/main/assets/block/kelp.png
diff --git a/games/voxels/src/main/assets/block/kelp.png b/games/voxels/src/main/assets/block/kelp.pngnew file mode 100644index 0000000000..3220aa9ddbBinary files /dev/null and b/games/voxels/src/main/assets/block/kelp.png differ
games/voxels/src/main/assets/block/magma.png
diff --git a/games/voxels/src/main/assets/block/magma.png b/games/voxels/src/main/assets/block/magma.pngnew file mode 100644index 0000000000..7f90744466Binary files /dev/null and b/games/voxels/src/main/assets/block/magma.png differ
games/voxels/src/main/assets/block/moss_block.png
diff --git a/games/voxels/src/main/assets/block/moss_block.png b/games/voxels/src/main/assets/block/moss_block.pngnew file mode 100644index 0000000000..69b2cfca2aBinary files /dev/null and b/games/voxels/src/main/assets/block/moss_block.png differ
games/voxels/src/main/assets/block/mud.png
diff --git a/games/voxels/src/main/assets/block/mud.png b/games/voxels/src/main/assets/block/mud.pngnew file mode 100644index 0000000000..078b7030caBinary files /dev/null and b/games/voxels/src/main/assets/block/mud.png differ
games/voxels/src/main/assets/block/mycelium_side.png
diff --git a/games/voxels/src/main/assets/block/mycelium_side.png b/games/voxels/src/main/assets/block/mycelium_side.pngnew file mode 100644index 0000000000..92850034a6Binary files /dev/null and b/games/voxels/src/main/assets/block/mycelium_side.png differ
games/voxels/src/main/assets/block/nether_bricks.png
diff --git a/games/voxels/src/main/assets/block/nether_bricks.png b/games/voxels/src/main/assets/block/nether_bricks.pngnew file mode 100644index 0000000000..df1ff09a3eBinary files /dev/null and b/games/voxels/src/main/assets/block/nether_bricks.png differ
games/voxels/src/main/assets/block/obsidian.png
diff --git a/games/voxels/src/main/assets/block/obsidian.png b/games/voxels/src/main/assets/block/obsidian.pngnew file mode 100644index 0000000000..2b101a6127Binary files /dev/null and b/games/voxels/src/main/assets/block/obsidian.png differ
games/voxels/src/main/assets/block/packed_dirt.png
diff --git a/games/voxels/src/main/assets/block/packed_dirt.png b/games/voxels/src/main/assets/block/packed_dirt.pngnew file mode 100644index 0000000000..15b8b06527Binary files /dev/null and b/games/voxels/src/main/assets/block/packed_dirt.png differ
games/voxels/src/main/assets/block/podzol_side.png
diff --git a/games/voxels/src/main/assets/block/podzol_side.png b/games/voxels/src/main/assets/block/podzol_side.pngnew file mode 100644index 0000000000..000b75fd42Binary files /dev/null and b/games/voxels/src/main/assets/block/podzol_side.png differ
games/voxels/src/main/assets/block/podzol_top.png
diff --git a/games/voxels/src/main/assets/block/podzol_top.png b/games/voxels/src/main/assets/block/podzol_top.pngnew file mode 100644index 0000000000..32f7e08e0aBinary files /dev/null and b/games/voxels/src/main/assets/block/podzol_top.png differ
games/voxels/src/main/assets/block/prismarine.png
diff --git a/games/voxels/src/main/assets/block/prismarine.png b/games/voxels/src/main/assets/block/prismarine.pngnew file mode 100644index 0000000000..86980dcbbeBinary files /dev/null and b/games/voxels/src/main/assets/block/prismarine.png differ
games/voxels/src/main/assets/block/red_sand.png
diff --git a/games/voxels/src/main/assets/block/red_sand.png b/games/voxels/src/main/assets/block/red_sand.pngnew file mode 100644index 0000000000..1e501e2437Binary files /dev/null and b/games/voxels/src/main/assets/block/red_sand.png differ
games/voxels/src/main/assets/block/red_sandstone.png
diff --git a/games/voxels/src/main/assets/block/red_sandstone.png b/games/voxels/src/main/assets/block/red_sandstone.pngnew file mode 100644index 0000000000..1315b4a9e8Binary files /dev/null and b/games/voxels/src/main/assets/block/red_sandstone.png differ
games/voxels/src/main/assets/block/red_sandstone_top.png
diff --git a/games/voxels/src/main/assets/block/red_sandstone_top.png b/games/voxels/src/main/assets/block/red_sandstone_top.pngnew file mode 100644index 0000000000..3d9977a90fBinary files /dev/null and b/games/voxels/src/main/assets/block/red_sandstone_top.png differ
games/voxels/src/main/assets/block/rooted_dirt.png
diff --git a/games/voxels/src/main/assets/block/rooted_dirt.png b/games/voxels/src/main/assets/block/rooted_dirt.pngnew file mode 100644index 0000000000..480aaaa06cBinary files /dev/null and b/games/voxels/src/main/assets/block/rooted_dirt.png differ
games/voxels/src/main/assets/block/sandstone.png
diff --git a/games/voxels/src/main/assets/block/sandstone.png b/games/voxels/src/main/assets/block/sandstone.pngnew file mode 100644index 0000000000..41645ce8beBinary files /dev/null and b/games/voxels/src/main/assets/block/sandstone.png differ
games/voxels/src/main/assets/block/sandstone_bottom.png
diff --git a/games/voxels/src/main/assets/block/sandstone_bottom.png b/games/voxels/src/main/assets/block/sandstone_bottom.pngnew file mode 100644index 0000000000..2c24f699d8Binary files /dev/null and b/games/voxels/src/main/assets/block/sandstone_bottom.png differ
games/voxels/src/main/assets/block/sandstone_top.png
diff --git a/games/voxels/src/main/assets/block/sandstone_top.png b/games/voxels/src/main/assets/block/sandstone_top.pngnew file mode 100644index 0000000000..246e483162Binary files /dev/null and b/games/voxels/src/main/assets/block/sandstone_top.png differ
games/voxels/src/main/assets/block/sculk.png
diff --git a/games/voxels/src/main/assets/block/sculk.png b/games/voxels/src/main/assets/block/sculk.pngnew file mode 100644index 0000000000..eb163d2b79Binary files /dev/null and b/games/voxels/src/main/assets/block/sculk.png differ
games/voxels/src/main/assets/block/sea_lantern.png
diff --git a/games/voxels/src/main/assets/block/sea_lantern.png b/games/voxels/src/main/assets/block/sea_lantern.pngnew file mode 100644index 0000000000..421d6c1aacBinary files /dev/null and b/games/voxels/src/main/assets/block/sea_lantern.png differ
games/voxels/src/main/assets/block/tube_coral.png
diff --git a/games/voxels/src/main/assets/block/tube_coral.png b/games/voxels/src/main/assets/block/tube_coral.pngnew file mode 100644index 0000000000..2ae7e670feBinary files /dev/null and b/games/voxels/src/main/assets/block/tube_coral.png differ
games/voxels/src/main/assets/block/tuff.png
diff --git a/games/voxels/src/main/assets/block/tuff.png b/games/voxels/src/main/assets/block/tuff.pngnew file mode 100644index 0000000000..ba7597c107Binary files /dev/null and b/games/voxels/src/main/assets/block/tuff.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 fb1c29ea14..236d282c5f 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@@ -38,7 +38,16 @@ val blockNames = mapOf(     14 to "Gravel", 15 to "Mossy", 16 to "Diorite", 17 to "Pol. Diorite", 18 to "Coal Ore", 19 to "Iron Ore",     20 to "Diamond Ore", 21 to "Redstone", 22 to "Emerald Ore", 23 to "Iron", 24 to "Diamond", 25 to "Emerald",     26 to "Birch Log", 27 to "Birch Plank", 28 to "Birch Leaf", 29 to "Spruce Log", 30 to "Spruce Plank", 31 to "Spruce Leaf",-    32 to "Netherrack", 33 to "Bookshelf", 34 to "Crafting Table", 35 to "Furnace"+    32 to "Netherrack", 33 to "Bookshelf", 34 to "Crafting Table", 35 to "Furnace",+    36 to "Red Sand", 37 to "Red Sandstone", 38 to "Sandstone", 39 to "Podzol", 40 to "Coarse Dirt", 41 to "Mycelium",+    42 to "Packed Ice", 43 to "Ice", 44 to "Blue Ice", 45 to "Mud", 46 to "Rooted Dirt",+    47 to "Dark Oak Log", 48 to "Dark Oak Leaf", 49 to "Dark Oak Plank", 50 to "Acacia Log", 51 to "Jungle Log", 52 to "Jungle Plank",+    53 to "Granite Bricks", 54 to "Deepslate Bricks", 55 to "Nether Bricks", 56 to "End Stone Bricks", 57 to "Cobbled Deepslate",+    58 to "Hay Bale", 59 to "Farmland", 60 to "Packed Dirt",+    61 to "Tube Coral", 62 to "Brain Coral", 63 to "Bubble Coral", 64 to "Fire Coral", 65 to "Horn Coral",+    66 to "Kelp", 67 to "Sea Lantern", 68 to "Prismarine", 69 to "Dark Prismarine",+    70 to "Dripstone", 71 to "Moss Block", 72 to "Sculk", 73 to "Amethyst", 74 to "Calcite", 75 to "Tuff",+    76 to "Magma", 77 to "Glowstone", 78 to "Obsidian", 79 to "Clay", 80 to "Azalea Leaves" )  val blockIconFile = mapOf(@@ -50,13 +59,25 @@ val blockIconFile = mapOf(     23 to "iron_block.png", 24 to "diamond_block.png", 25 to "emerald_block.png",     26 to "birch_log_top.png", 27 to "birch_planks.png", 28 to "birch_leaves.png",     29 to "spruce_log_top.png", 30 to "spruce_planks.png", 31 to "spruce_leaves.png",-    32 to "netherrack.png", 33 to "bookshelf.png", 34 to "crafting_table_top.png", 35 to "furnace_top.png"+    32 to "netherrack.png", 33 to "bookshelf.png", 34 to "crafting_table_top.png", 35 to "furnace_top.png",+    36 to "red_sand.png", 37 to "red_sandstone.png", 38 to "sandstone.png", 39 to "podzol_top.png", 40 to "coarse_dirt.png",+    41 to "mycelium_side.png", 42 to "packed_ice.png", 43 to "ice.png", 44 to "blue_ice.png", 45 to "mud.png", 46 to "rooted_dirt.png",+    47 to "dark_oak_log_top.png", 48 to "dark_oak_leaves.png", 49 to "dark_oak_planks.png",+    50 to "acacia_log_top.png", 51 to "jungle_log_top.png", 52 to "jungle_planks.png",+    53 to "granite_bricks.png", 54 to "deepslate_bricks.png", 55 to "nether_bricks.png", 56 to "end_stone_bricks.png",+    57 to "cobbled_deepslate.png", 58 to "hay_block_top.png", 59 to "farmland.png", 60 to "packed_dirt.png",+    61 to "tube_coral.png", 62 to "brain_coral.png", 63 to "bubble_coral.png", 64 to "fire_coral.png", 65 to "horn_coral.png",+    66 to "kelp.png", 67 to "sea_lantern.png", 68 to "prismarine.png", 69 to "dark_prismarine.png",+    70 to "dripstone.png", 71 to "moss_block.png", 72 to "sculk.png", 73 to "amethyst.png", 74 to "calcite.png",+    75 to "tuff.png", 76 to "magma.png", 77 to "glowstone.png", 78 to "obsidian.png", 79 to "clay.png", 80 to "azalea_leaves.png" )  // Creative catalog, split into tabs.-val catalogNatural = listOf(3, 2, 1, 6, 14, 16, 17, 15, 4, 5, 26, 28, 29, 31, 11, 32, 13)-val catalogOres = listOf(18, 19, 20, 21, 22, 23, 24, 25)-val catalogBuilding = listOf(10, 27, 30, 8, 9, 7, 33, 34, 35)+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, 13)+val catalogOres = listOf(18, 19, 20, 21, 22, 23, 24, 25, 73)+val catalogOcean = listOf(61, 62, 63, 64, 65, 66, 67, 68, 69)+val catalogBuilding = listOf(10, 27, 30, 49, 52, 8, 57, 9, 53, 54, 55, 56, 58, 59, 72, 74, 76, 77, 78, 7, 33, 34, 35)  @Composable fun rememberBlockIcon(id: Int): androidx.compose.ui.graphics.ImageBitmap? {
games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/InventoryScreen.kt
diff --git a/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/InventoryScreen.kt b/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/InventoryScreen.ktindex 144ff9b6c8..247ed5b3e9 100644--- a/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/InventoryScreen.kt+++ b/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/InventoryScreen.kt@@ -86,13 +86,14 @@ fun InventoryOverlay(inventoryJson: String, recipesJson: String, onClose: () ->              // Right catalog (creative): tap a block to add a stack.             Column(Modifier.width(236.dp).fillMaxHeight(), horizontalAlignment = Alignment.CenterHorizontally) {-                Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {+                Row(horizontalArrangement = Arrangement.spacedBy(4.dp)) {                     TabButton("Natural", catTab == 0) { catTab = 0 }                     TabButton("Ores", catTab == 1) { catTab = 1 }+                    TabButton("Ocean", catTab == 3) { catTab = 3 }                     TabButton("Build", catTab == 2) { catTab = 2 }                 }                 Spacer(Modifier.height(8.dp))-                val cat = when (catTab) { 0 -> catalogNatural; 1 -> catalogOres; else -> catalogBuilding }+                val cat = when (catTab) { 0 -> catalogNatural; 1 -> catalogOres; 3 -> catalogOcean; else -> catalogBuilding }                 CatalogGrid(cat) { id -> try { VoxelsNative.giveBlock(id) } catch (_: Exception) {} }             }         }
games/voxels/src/main/rust/Cargo.toml
diff --git a/games/voxels/src/main/rust/Cargo.toml b/games/voxels/src/main/rust/Cargo.tomlindex b8cb853426..3ebc5ef2f8 100644--- a/games/voxels/src/main/rust/Cargo.toml+++ b/games/voxels/src/main/rust/Cargo.toml@@ -1,3 +1,6 @@+# Standalone crate (built directly by Gradle); detached from any parent workspace Cargo.toml.+[workspace]+ [package] name = "voxels_engine" version = "0.1.0"
games/voxels/src/main/rust/build.rs
diff --git a/games/voxels/src/main/rust/build.rs b/games/voxels/src/main/rust/build.rsindex 6b953615a2..f2257ef0a1 100644--- a/games/voxels/src/main/rust/build.rs+++ b/games/voxels/src/main/rust/build.rs@@ -15,6 +15,10 @@ fn main() {     let sky_frag_spv = shaders_dir.join("sky.frag.spv");     let cloud_frag = shaders_dir.join("cloud.frag");     let cloud_frag_spv = shaders_dir.join("cloud.frag.spv");+    let entity_vert = shaders_dir.join("entity.vert");+    let entity_vert_spv = shaders_dir.join("entity.vert.spv");+    let entity_frag = shaders_dir.join("entity.frag");+    let entity_frag_spv = shaders_dir.join("entity.frag.spv");     let shadow_vert = shaders_dir.join("shadow.vert");     let shadow_vert_spv = shaders_dir.join("shadow.vert.spv");     let water_vert = shaders_dir.join("water.vert");@@ -43,6 +47,8 @@ fn main() {         let _ = Command::new(glslc_path).arg("-o").arg(&sky_vert_spv).arg(&sky_vert).status();         let _ = Command::new(glslc_path).arg("-o").arg(&sky_frag_spv).arg(&sky_frag).status();         let _ = Command::new(glslc_path).arg("-o").arg(&cloud_frag_spv).arg(&cloud_frag).status();+        let _ = Command::new(glslc_path).arg("-o").arg(&entity_vert_spv).arg(&entity_vert).status();+        let _ = Command::new(glslc_path).arg("-o").arg(&entity_frag_spv).arg(&entity_frag).status();         let _ = Command::new(glslc_path).arg("-o").arg(&shadow_vert_spv).arg(&shadow_vert).status();         let _ = Command::new(glslc_path).arg("-o").arg(&water_vert_spv).arg(&water_vert).status();         let _ = Command::new(glslc_path).arg("-o").arg(&water_frag_spv).arg(&water_frag).status();@@ -57,6 +63,8 @@ fn main() {     if !sky_vert_spv.exists() { std::fs::write(&sky_vert_spv, minimal_vert_spv()).ok(); }     if !sky_frag_spv.exists() { std::fs::write(&sky_frag_spv, minimal_frag_spv()).ok(); }     if !cloud_frag_spv.exists() { std::fs::write(&cloud_frag_spv, minimal_frag_spv()).ok(); }+    if !entity_vert_spv.exists() { std::fs::write(&entity_vert_spv, minimal_vert_spv()).ok(); }+    if !entity_frag_spv.exists() { std::fs::write(&entity_frag_spv, minimal_frag_spv()).ok(); }     if !shadow_vert_spv.exists() { std::fs::write(&shadow_vert_spv, minimal_vert_spv()).ok(); }     if !water_vert_spv.exists() { std::fs::write(&water_vert_spv, minimal_vert_spv()).ok(); }     if !water_frag_spv.exists() { std::fs::write(&water_frag_spv, minimal_frag_spv()).ok(); }@@ -70,6 +78,8 @@ fn main() {     println!("cargo:rerun-if-changed=shaders/sky.vert");     println!("cargo:rerun-if-changed=shaders/sky.frag");     println!("cargo:rerun-if-changed=shaders/cloud.frag");+    println!("cargo:rerun-if-changed=shaders/entity.vert");+    println!("cargo:rerun-if-changed=shaders/entity.frag");     println!("cargo:rerun-if-changed=shaders/shadow.vert");     println!("cargo:rerun-if-changed=shaders/water.vert");     println!("cargo:rerun-if-changed=shaders/water.frag");
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 cf71dd3059..0db14482a3 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/shaders/block.frag
diff --git a/games/voxels/src/main/rust/shaders/block.frag b/games/voxels/src/main/rust/shaders/block.fragindex de6e97534c..d376bd9053 100644--- a/games/voxels/src/main/rust/shaders/block.frag+++ b/games/voxels/src/main/rust/shaders/block.frag@@ -29,9 +29,9 @@ layout(binding=2) uniform sampler2D shadowMap;  layout(location=0) out vec4 outColor; -// Atlas is 8 cols x 8 rows.-const vec2 TILE_SPAN = vec2(1.0/8.0, 1.0/8.0);-const float ATLAS_COLS = 8.0;+// Atlas is 16 cols x 16 rows.+const vec2 TILE_SPAN = vec2(1.0/16.0, 1.0/16.0);+const float ATLAS_COLS = 16.0;  // --- Cloud coverage (matches sky.frag) for cloud shadows on the ground. --- const float CLOUD_MID = 165.0;@@ -80,7 +80,7 @@ void main() {     float tile = fragTile;     vec4 texColor;     vec3 albedo;-    if (tile > 99.0) {+    if (tile > 999.0) {         // Grass side: dirt base + the tinted grass_block_side_overlay fringe, composited in one quad         // (perfectly aligned with the top face, no z-fight offset).         vec2 dirtUV = vec2(mod(1.0, ATLAS_COLS) * TILE_SPAN.x, floor(1.0 / ATLAS_COLS + 0.001) * TILE_SPAN.y) + fuv * TILE_SPAN;
games/voxels/src/main/rust/shaders/block.frag.spv
diff --git a/games/voxels/src/main/rust/shaders/block.frag.spv b/games/voxels/src/main/rust/shaders/block.frag.spvindex fc9b364b8b..77956643a8 100644Binary files a/games/voxels/src/main/rust/shaders/block.frag.spv and b/games/voxels/src/main/rust/shaders/block.frag.spv differ
games/voxels/src/main/rust/shaders/entity.frag
diff --git a/games/voxels/src/main/rust/shaders/entity.frag b/games/voxels/src/main/rust/shaders/entity.fragnew file mode 100644index 0000000000..ba3b91ee3f--- /dev/null+++ b/games/voxels/src/main/rust/shaders/entity.frag@@ -0,0 +1,35 @@+#version 450+layout(location=0) in vec2 fragUv;+layout(location=1) in vec3 fragColor;+layout(location=2) in vec3 fragWorldPos;+layout(location=3) in vec3 fragNormal;++layout(binding=0) uniform Ubo {+    mat4 viewProj;+    vec3 sunDir;+    float time;+    vec3 fogColor;+    float fogDensity;+    vec4 playerPos;+    float dayFactor;+    mat4 invViewProj;+    vec3 sunColor;+    float cloudShadow;+    vec3 ambientColor;+    float _pad2;+    mat4 lightViewProj;+};+layout(binding=3) uniform sampler2D entityTex;++layout(location=0) out vec4 outColor;++void main() {+    vec4 t = texture(entityTex, fragUv);+    if (t.a < 0.5) discard;                       // cut out transparent skin regions+    vec3 n = normalize(fragNormal);+    vec3 s = normalize(sunDir);+    float ndl = max(dot(n, s), 0.0);+    vec3 amb = ambientColor * (0.55 + 0.45 * (0.5 + 0.5 * n.y));+    vec3 lit = t.rgb * fragColor * (sunColor * ndl + amb);+    outColor = vec4(lit, 1.0);                     // linear HDR; tonemapped in composite+}
games/voxels/src/main/rust/shaders/entity.frag.spv
diff --git a/games/voxels/src/main/rust/shaders/entity.frag.spv b/games/voxels/src/main/rust/shaders/entity.frag.spvnew file mode 100644index 0000000000..51cb701ae1Binary files /dev/null and b/games/voxels/src/main/rust/shaders/entity.frag.spv differ
games/voxels/src/main/rust/shaders/entity.vert
diff --git a/games/voxels/src/main/rust/shaders/entity.vert b/games/voxels/src/main/rust/shaders/entity.vertnew file mode 100644index 0000000000..d4d6961ba8--- /dev/null+++ b/games/voxels/src/main/rust/shaders/entity.vert@@ -0,0 +1,36 @@+#version 450+layout(location=0) in vec3 inPos;+layout(location=1) in vec2 inUv;+layout(location=2) in vec3 inColor;+layout(location=3) in float inAo;+layout(location=4) in float inTileIdx;+layout(location=5) in vec3 inNormal;++layout(binding=0) uniform Ubo {+    mat4 viewProj;+    vec3 sunDir;+    float time;+    vec3 fogColor;+    float fogDensity;+    vec4 playerPos;+    float dayFactor;+    mat4 invViewProj;+    vec3 sunColor;+    float cloudShadow;+    vec3 ambientColor;+    float _pad2;+    mat4 lightViewProj;+};++layout(location=0) out vec2 fragUv;+layout(location=1) out vec3 fragColor;+layout(location=2) out vec3 fragWorldPos;+layout(location=3) out vec3 fragNormal;++void main() {+    gl_Position = viewProj * vec4(inPos, 1.0);+    fragUv = inUv;+    fragColor = inColor;+    fragWorldPos = inPos;+    fragNormal = inNormal;+}
games/voxels/src/main/rust/shaders/entity.vert.spv
diff --git a/games/voxels/src/main/rust/shaders/entity.vert.spv b/games/voxels/src/main/rust/shaders/entity.vert.spvnew file mode 100644index 0000000000..c6a4ee79ecBinary files /dev/null and b/games/voxels/src/main/rust/shaders/entity.vert.spv differ
games/voxels/src/main/rust/shaders/entity_atlas.bin
diff --git a/games/voxels/src/main/rust/shaders/entity_atlas.bin b/games/voxels/src/main/rust/shaders/entity_atlas.binnew file mode 100644index 0000000000..fd746157a7Binary files /dev/null and b/games/voxels/src/main/rust/shaders/entity_atlas.bin differ
games/voxels/src/main/rust/shaders/water.frag
diff --git a/games/voxels/src/main/rust/shaders/water.frag b/games/voxels/src/main/rust/shaders/water.fragindex f51aca688b..6c455083e3 100644--- a/games/voxels/src/main/rust/shaders/water.frag+++ b/games/voxels/src/main/rust/shaders/water.frag@@ -25,10 +25,19 @@ void main() {     vec3 viewDir = normalize(playerPos.xyz - fragWorldPos);     vec3 wp = fragWorldPos; -    // Detailed animated surface normal: coarse wave normal + fine moving ripples for sparkle.+    // Animated surface normal from several NON-axis-aligned directional ripples. Summing waves that+    // travel along diagonal directions avoids the plaid "square wave" look that axis-aligned+    // sin(x)+sin(z) produces on the block grid.+    vec2 pw = wp.xz;     vec3 n = normalize(fragNormal);-    n.x += 0.06 * sin(wp.x * 2.3 + time * 2.5) + 0.04 * sin(wp.z * 3.1 - time * 1.7);-    n.z += 0.06 * sin(wp.z * 2.1 + time * 2.2) + 0.04 * sin(wp.x * 2.9 + time * 1.3);+    vec2 d1 = vec2(0.936, 0.351);   // ~20 deg+    vec2 d2 = vec2(-0.406, 0.914);  // ~114 deg+    vec2 d3 = vec2(0.274, -0.962);  // ~-74 deg+    float w1 = sin(dot(pw, d1) * 0.9 + time * 1.6);+    float w2 = sin(dot(pw, d2) * 1.7 + time * 2.1);+    float w3 = cos(dot(pw, d3) * 3.1 + time * 2.9);+    n.x += 0.11 * w1 * d1.x + 0.07 * w2 * d2.x + 0.035 * w3 * d3.x;+    n.z += 0.11 * w1 * d1.y + 0.07 * w2 * d2.y + 0.035 * w3 * d3.y;     n = normalize(n);      // Fresnel: near-transparent looking straight down, mirror-like at grazing angles.
games/voxels/src/main/rust/shaders/water.frag.spv
diff --git a/games/voxels/src/main/rust/shaders/water.frag.spv b/games/voxels/src/main/rust/shaders/water.frag.spvindex 250ae3a6c6..fda45a5fc2 100644Binary files a/games/voxels/src/main/rust/shaders/water.frag.spv and b/games/voxels/src/main/rust/shaders/water.frag.spv 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 babb6af056..643a5f66b1 100644--- a/games/voxels/src/main/rust/src/engine.rs+++ b/games/voxels/src/main/rust/src/engine.rs@@ -1,6 +1,7 @@ use crate::world::{ChunkMap, block::Block}; use crate::player::Player; use crate::inventory::Inventory;+use crate::entity::{Mob, MobKind, build_entity_mesh}; use crate::world::mesher; use crate::vulkan::context::{VulkanContext, ANativeWindow}; use crate::vulkan::renderer::VulkanRenderer;@@ -21,6 +22,9 @@ pub struct EngineState {     pub window_ptr: Option<*mut ANativeWindow>,     pub needs_resize: bool,     pub running: bool,+    pub mobs: Vec<Mob>,+    pub spawn_timer: f32,+    pub spawn_rng: u32, }  unsafe impl Send for EngineState {}@@ -84,6 +88,9 @@ pub fn init_engine(files_dir: String, seed: u32) -> bool {         window_ptr: None,         needs_resize: false,         running: true,+        mobs: Vec::new(),+        spawn_timer: 2.0,+        spawn_rng: seed ^ 0x9E3779B9,     });     INIT_DONE.store(true, Ordering::SeqCst);     true@@ -242,6 +249,50 @@ pub fn tick_and_render() {             rebuild_chunk_meshes(state, pos);         } +        // --- Mobs: AI/physics tick, spawn/despawn near the player. ---+        let player_pos = state.player.pos;+        {+            let chunks = &state.chunks;+            let solid = |x: i32, y: i32, z: i32| { let id = chunks.get_block_world(x, y, z); id != 0 && Block::from_id(id).is_solid() };+            for m in state.mobs.iter_mut() { m.tick(dt, player_pos, &solid); }+        }+        state.mobs.retain(|m| (m.pos - player_pos).length() < 96.0 && m.pos.y > -8.0);+        state.spawn_timer -= dt;+        if state.spawn_timer <= 0.0 {+            state.spawn_timer = 2.5;+            if state.mobs.len() < 22 {+                use crate::world::chunk::CHUNK_HEIGHT;+                let mut rng = state.spawn_rng;+                let mut rand = |r: &mut u32| { let mut x = *r; x ^= x << 13; x ^= x >> 17; x ^= x << 5; *r = x; (x >> 8) as f32 / 16_777_216.0 };+                let ang = rand(&mut rng) * std::f32::consts::TAU;+                let dist = 24.0 + rand(&mut rng) * 20.0;+                let sx = player_pos.x + ang.cos() * dist;+                let sz = player_pos.z + ang.sin() * dist;+                let (bx, bz) = (sx.floor() as i32, sz.floor() as i32);+                let mut gy = None;+                for y in (2..CHUNK_HEIGHT as i32).rev() {+                    let id = state.chunks.get_block_world(bx, y, bz);+                    if id != 0 && Block::from_id(id).is_solid() { gy = Some(y); break; }+                }+                if let Some(gy) = gy {+                    let world_time = 60.0 + (Instant::now() - state.start_time).as_secs_f32();+                    let day_t = (world_time / 120.0) % 1.0;+                    // Sun is below the horizon (night) near the ends of the cycle; ~noon at day_t=0.5.+                    let night = day_t < 0.25 || day_t > 0.75;+                    let kind = if night {+                        if rand(&mut rng) < 0.5 { MobKind::Zombie } else { MobKind::Creeper }+                    } else {+                        match (rand(&mut rng) * 4.0) as u32 { 0 => MobKind::Pig, 1 => MobKind::Cow, 2 => MobKind::Sheep, _ => MobKind::Chicken }+                    };+                    let pos = vec3(sx, gy as f32 + 1.0, sz);+                    let seed = rng ^ (bx as u32).wrapping_mul(2654435761) ^ (bz as u32).wrapping_mul(40503);+                    state.mobs.push(Mob::new(kind, pos, seed));+                }+                state.spawn_rng = rng;+            }+        }+        let (entity_verts, entity_indices) = build_entity_mesh(&state.mobs);+         if let Some(renderer) = state.renderer.as_mut() {             if state.needs_resize {                 let w = state.width; let h = state.height;@@ -267,6 +318,7 @@ pub fn tick_and_render() {             let underwater = if state.chunks.get_block_world(eb.0, eb.1, eb.2) == 12 { 1.0 } else { 0.0 };             unsafe {                 renderer.update_ubo(view_proj, state.player.pos, time, underwater);+                renderer.upload_entity_mesh(&entity_verts, &entity_indices);                 let _ = renderer.draw_frame();             }         }@@ -297,6 +349,7 @@ fn publish_ui(state: &EngineState) {         "on_ground": state.player.on_ground,         "time": format!("{:.1}s", (Instant::now() - state.start_time).as_secs_f32()),         "meshes": state.renderer.as_ref().map(|r| r.gpu_meshes.len()).unwrap_or(0),+        "mobs": state.mobs.len(),         "drawn": state.renderer.as_ref().map(|r| r.drawn_sections).unwrap_or(0),         "gpu": state.renderer.as_ref().map(|r| {             let p = r.pass_ms;
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.rsnew file mode 100644index 0000000000..18e8017357--- /dev/null+++ b/games/voxels/src/main/rust/src/entity.rs@@ -0,0 +1,229 @@+// Mobs: simple entities with wander/chase AI, gravity + block collision, and skinned box-model+// rendering into the entity atlas (see texture_atlas::load_entity_atlas_bin / build_entity_atlas.py).+use glam::Vec3;+use crate::vulkan::buffers::Vertex;+use crate::texture_atlas::{ENTITY_ATLAS_W, ENTITY_CELL};++const ATLAS: f32 = ENTITY_ATLAS_W as f32;+const CELL: f32 = ENTITY_CELL as f32;+const PX: f32 = 1.0 / 16.0; // one skin pixel in blocks++#[derive(Clone, Copy, PartialEq, Eq)]+pub enum MobKind { Pig, Cow, Sheep, Chicken, Creeper, Zombie }++// A model part: an axis-aligned box textured from the skin.+struct Part {+    size: [f32; 3], // pixels (w, h, d)+    pos: [f32; 3],  // centre in blocks, feet at y=0, y up+    uv: [f32; 2],   // skin-space origin (pixels)+    x_rot: f32,     // static rotation about X (radians) around `pos`+    leg: f32,       // walk-swing phase sign (0 = not animated); rotates about the part's top+}++const fn p(size: [f32;3], pos: [f32;3], uv: [f32;2], x_rot: f32, leg: f32) -> Part { Part{size,pos,uv,x_rot,leg} }+const HP: f32 = std::f32::consts::FRAC_PI_2;++// Quadruped (pig/cow/sheep): head, laid-down body, four legs.+static QUAD: &[Part] = &[+    p([8.,8.,8.],   [0.0, 0.70, -0.44], [0.,0.],   0.0, 0.0),+    p([10.,16.,8.], [0.0, 0.56, 0.06],  [28.,8.],  HP,  0.0),+    p([4.,6.,4.],   [-0.16, 0.1875, -0.22], [0.,16.], 0.0,  1.0),+    p([4.,6.,4.],   [0.16, 0.1875, -0.22],  [0.,16.], 0.0, -1.0),+    p([4.,6.,4.],   [-0.16, 0.1875, 0.28],  [0.,16.], 0.0, -1.0),+    p([4.,6.,4.],   [0.16, 0.1875, 0.28],   [0.,16.], 0.0,  1.0),+];+// Biped (zombie): head, body, two legs, two arms.+static BIPED: &[Part] = &[+    p([8.,8.,8.],   [0.0, 1.50, 0.0], [0.,0.],   0.0, 0.0),+    p([8.,12.,4.],  [0.0, 1.125, 0.0], [16.,16.], 0.0, 0.0),+    p([4.,12.,4.],  [-0.125, 0.375, 0.0], [0.,16.],  0.0,  1.0),+    p([4.,12.,4.],  [0.125, 0.375, 0.0],  [0.,16.],  0.0, -1.0),+    p([4.,12.,4.],  [-0.375, 1.125, 0.0], [40.,16.], 0.0, -1.0),+    p([4.,12.,4.],  [0.375, 1.125, 0.0],  [40.,16.], 0.0,  1.0),+];+// Creeper: head, tall body, four short legs.+static CREEPER: &[Part] = &[+    p([8.,8.,8.],  [0.0, 1.375, 0.0], [0.,0.],   0.0, 0.0),+    p([8.,12.,4.], [0.0, 0.75, 0.0],  [16.,16.], 0.0, 0.0),+    p([4.,6.,4.],  [-0.125, 0.1875, -0.125], [0.,16.], 0.0,  1.0),+    p([4.,6.,4.],  [0.125, 0.1875, -0.125],  [0.,16.], 0.0, -1.0),+    p([4.,6.,4.],  [-0.125, 0.1875, 0.125],  [0.,16.], 0.0, -1.0),+    p([4.,6.,4.],  [0.125, 0.1875, 0.125],   [0.,16.], 0.0,  1.0),+];+// Chicken: small body, head, two thin legs.+static CHICKEN: &[Part] = &[+    p([6.,8.,6.],  [0.0, 0.38, 0.0],  [0.,9.],  0.0, 0.0),+    p([4.,6.,3.],  [0.0, 0.62, -0.18], [0.,0.], 0.0, 0.0),+    p([2.,5.,2.],  [-0.09, 0.15, 0.0], [26.,2.], 0.0,  1.0),+    p([2.,5.,2.],  [0.09, 0.15, 0.0],  [26.,2.], 0.0, -1.0),+];++impl MobKind {+    fn cell(self) -> u32 { match self { MobKind::Pig=>0, MobKind::Cow=>1, MobKind::Sheep=>2, MobKind::Chicken=>3, MobKind::Creeper=>4, MobKind::Zombie=>5 } }+    pub fn hostile(self) -> bool { matches!(self, MobKind::Creeper | MobKind::Zombie) }+    fn speed(self) -> f32 { match self { MobKind::Chicken=>1.6, MobKind::Creeper=>1.5, MobKind::Zombie=>1.7, _=>1.15 } }+    fn parts(self) -> &'static [Part] {+        match self {+            MobKind::Pig | MobKind::Cow | MobKind::Sheep => QUAD,+            MobKind::Zombie => BIPED,+            MobKind::Creeper => CREEPER,+            MobKind::Chicken => CHICKEN,+        }+    }+}++pub struct Mob {+    pub kind: MobKind,+    pub pos: Vec3,+    pub vel: Vec3,+    pub yaw: f32,+    target_yaw: f32,+    wander: f32,+    anim: f32,+    on_ground: bool,+    rng: u32,+}++fn xorshift(s: &mut u32) -> f32 {+    let mut x = *s; x ^= x << 13; x ^= x >> 17; x ^= x << 5; *s = x;+    (x >> 8) as f32 / 16_777_216.0 // [0,1)+}++impl Mob {+    pub fn new(kind: MobKind, pos: Vec3, seed: u32) -> Self {+        Mob { kind, pos, vel: Vec3::ZERO, yaw: 0.0, target_yaw: 0.0, wander: 0.0, anim: 0.0, on_ground: false, rng: seed | 1 }+    }++    pub fn tick(&mut self, dt: f32, player: Vec3, solid: &dyn Fn(i32, i32, i32) -> bool) {+        self.wander -= dt;+        let to_player = player - self.pos;+        let pdist = to_player.length();+        if self.wander <= 0.0 {+            self.wander = 1.5 + xorshift(&mut self.rng) * 3.0;+            if self.kind.hostile() && pdist < 22.0 {+                self.target_yaw = to_player.x.atan2(-to_player.z); // face the player+            } else {+                self.target_yaw = (xorshift(&mut self.rng) - 0.5) * std::f32::consts::TAU;+            }+            // Occasionally idle (stand still).+            if !self.kind.hostile() && xorshift(&mut self.rng) < 0.3 { self.wander = 1.0; self.target_yaw = self.yaw; }+        }+        // Ease yaw toward the target.+        let mut dyaw = self.target_yaw - self.yaw;+        while dyaw > std::f32::consts::PI { dyaw -= std::f32::consts::TAU; }+        while dyaw < -std::f32::consts::PI { dyaw += std::f32::consts::TAU; }+        self.yaw += dyaw.clamp(-3.0 * dt, 3.0 * dt);++        let chasing = self.kind.hostile() && pdist < 22.0;+        let idle = !chasing && (self.target_yaw - self.yaw).abs() < 0.05 && self.wander < 1.05 && !self.kind.hostile();+        let speed = if idle { 0.0 } else { self.kind.speed() * if chasing { 1.25 } else { 1.0 } };+        // Model front is -Z; rotating (0,0,-1) by yaw gives (sin, 0, -cos).+        let fwd = Vec3::new(self.yaw.sin(), 0.0, -self.yaw.cos());++        // Gravity.+        self.vel.y -= 24.0 * dt;+        self.vel.y = self.vel.y.max(-40.0);++        let at = |x: f32, y: f32, z: f32| solid(x.floor() as i32, y.floor() as i32, z.floor() as i32);+        let r = 0.3;+        // Horizontal move per axis, blocked by walls, with a 1-block auto step-up on the ground.+        let dx = fwd.x * speed * dt;+        if dx != 0.0 {+            let nx = self.pos.x + dx + r * dx.signum();+            if !at(nx, self.pos.y + 0.2, self.pos.z) && !at(nx, self.pos.y + 1.0, self.pos.z) {+                self.pos.x += dx;+            } else if self.on_ground && !at(nx, self.pos.y + 1.2, self.pos.z) && !at(nx, self.pos.y + 2.0, self.pos.z) {+                self.pos.x += dx; self.pos.y += 1.0;+            }+        }+        let dz = fwd.z * speed * dt;+        if dz != 0.0 {+            let nz = self.pos.z + dz + r * dz.signum();+            if !at(self.pos.x, self.pos.y + 0.2, nz) && !at(self.pos.x, self.pos.y + 1.0, nz) {+                self.pos.z += dz;+            } else if self.on_ground && !at(self.pos.x, self.pos.y + 1.2, nz) && !at(self.pos.x, self.pos.y + 2.0, nz) {+                self.pos.z += dz; self.pos.y += 1.0;+            }+        }+        // Vertical: fall until a block is underfoot.+        self.pos.y += self.vel.y * dt;+        self.on_ground = false;+        if self.vel.y <= 0.0 && at(self.pos.x, self.pos.y - 0.05, self.pos.z) {+            self.pos.y = self.pos.y.floor() + 1.0;+            self.vel.y = 0.0;+            self.on_ground = true;+        }+        // Hostiles hop toward the player over small ledges.+        if chasing && self.on_ground && speed > 0.0 && at(self.pos.x + fwd.x * 0.4, self.pos.y + 0.1, self.pos.z + fwd.z * 0.4) {+            self.vel.y = 8.0;+        }+        self.anim += speed * dt * 5.5;+    }++    fn append_mesh(&self, verts: &mut Vec<Vertex>, indices: &mut Vec<u32>) {+        let col = (self.kind.cell() % 4) as f32 * CELL;+        let row = (self.kind.cell() / 4) as f32 * CELL;+        let (yc, ys) = (self.yaw.cos(), self.yaw.sin());+        for part in self.kind.parts() {+            let swing = if part.leg != 0.0 { self.anim.sin() * 0.55 * part.leg } else { 0.0 };+            let xr = part.x_rot + swing;+            let (hx, hy, hz) = (part.size[0]*PX*0.5, part.size[1]*PX*0.5, part.size[2]*PX*0.5);+            let center = Vec3::new(part.pos[0], part.pos[1], part.pos[2]);+            // Legs swing about their top; static-rotated parts rotate about their centre.+            let pivot_y = if part.leg != 0.0 { center.y + hy } else { center.y };+            let (xc, xs) = (xr.cos(), xr.sin());+            // Skin-space box unwrap (pixels) for the 6 faces in order +X,-X,+Y,-Y,+Z,-Z.+            let (w, h, d) = (part.size[0], part.size[1], part.size[2]);+            let (u, v) = (part.uv[0], part.uv[1]);+            let rects = [+                [u, v+d, u+d, v+d+h],               // +X east+                [u+d+w, v+d, u+2.0*d+w, v+d+h],      // -X west+                [u+d, v, u+d+w, v+d],               // +Y up+                [u+d+w, v, u+d+2.0*w, v+d],          // -Y down+                [u+2.0*d+w, v+d, u+2.0*d+2.0*w, v+d+h], // +Z south (back)+                [u+d, v+d, u+d+w, v+d+h],           // -Z north (front)+            ];+            // Face corners (CCW) as (x,y,z) multipliers of half-extents.+            let faces: [[[f32;3];4];6] = [+                [[1.,-1.,-1.],[1.,1.,-1.],[1.,1.,1.],[1.,-1.,1.]],   // +X+                [[-1.,-1.,1.],[-1.,1.,1.],[-1.,1.,-1.],[-1.,-1.,-1.]], // -X+                [[-1.,1.,-1.],[-1.,1.,1.],[1.,1.,1.],[1.,1.,-1.]],   // +Y+                [[-1.,-1.,1.],[-1.,-1.,-1.],[1.,-1.,-1.],[1.,-1.,1.]], // -Y+                [[1.,-1.,1.],[1.,1.,1.],[-1.,1.,1.],[-1.,-1.,1.]],   // +Z+                [[-1.,-1.,-1.],[-1.,1.,-1.],[1.,1.,-1.],[1.,-1.,-1.]], // -Z+            ];+            let normals = [[1.,0.,0.],[-1.,0.,0.],[0.,1.,0.],[0.,-1.,0.],[0.,0.,1.],[0.,0.,-1.]];+            for f in 0..6 {+                let base = verts.len() as u32;+                let rect = rects[f];+                let uvc = [[rect[0],rect[3]],[rect[0],rect[1]],[rect[2],rect[1]],[rect[2],rect[3]]];+                // Transform normal (x-rot then yaw).+                let mut nrm = normals[f];+                { let (ny, nz) = (nrm[1]*xc - nrm[2]*xs, nrm[1]*xs + nrm[2]*xc); nrm[1]=ny; nrm[2]=nz;+                  let (nx, nz2) = (nrm[0]*yc - nrm[2]*ys, nrm[0]*ys + nrm[2]*yc); nrm[0]=nx; nrm[2]=nz2; }+                for c in 0..4 {+                    let m = faces[f][c];+                    let mut wp = Vec3::new(center.x + m[0]*hx, center.y + m[1]*hy, center.z + m[2]*hz);+                    // x-rotation about pivot.+                    let (dy, dz) = (wp.y - pivot_y, wp.z - center.z);+                    wp.y = pivot_y + dy*xc - dz*xs;+                    wp.z = center.z + dy*xs + dz*xc;+                    // yaw about Y through the mob origin.+                    let (rx, rz) = (wp.x*yc - wp.z*ys, wp.x*ys + wp.z*yc);+                    wp = Vec3::new(rx, wp.y, rz) + self.pos;+                    let uv = [(col + uvc[c][0]) / ATLAS, (row + uvc[c][1]) / ATLAS];+                    verts.push(Vertex { pos: [wp.x, wp.y, wp.z], uv, color: [1.0,1.0,1.0], ao: 1.0, tile_idx: 0.0, normal: nrm });+                }+                indices.extend_from_slice(&[base, base+1, base+2, base, base+2, base+3]);+            }+        }+    }+}++// Build one vertex/index buffer for all mobs.+pub fn build_entity_mesh(mobs: &[Mob]) -> (Vec<Vertex>, Vec<u32>) {+    let mut verts = Vec::new();+    let mut indices = Vec::new();+    for m in mobs { m.append_mesh(&mut verts, &mut indices); }+    (verts, indices)+}
games/voxels/src/main/rust/src/lib.rs
diff --git a/games/voxels/src/main/rust/src/lib.rs b/games/voxels/src/main/rust/src/lib.rsindex e91cf6428b..c01afff4f5 100644--- a/games/voxels/src/main/rust/src/lib.rs+++ b/games/voxels/src/main/rust/src/lib.rs@@ -1,4 +1,5 @@ pub mod world;+pub mod entity; pub mod player; pub mod raycast; pub mod input;
games/voxels/src/main/rust/src/texture_atlas.rs
diff --git a/games/voxels/src/main/rust/src/texture_atlas.rs b/games/voxels/src/main/rust/src/texture_atlas.rsindex 9134f20be7..fc1e959699 100644--- a/games/voxels/src/main/rust/src/texture_atlas.rs+++ b/games/voxels/src/main/rust/src/texture_atlas.rs@@ -1,11 +1,11 @@ use ash::vk; use crate::vulkan::buffers::AllocatedBuffer; -pub const ATLAS_TILES_PER_ROW: u32 = 8;-pub const ATLAS_TILE_ROWS: u32 = 8;+pub const ATLAS_TILES_PER_ROW: u32 = 16;+pub const ATLAS_TILE_ROWS: u32 = 16; pub const TILE_SIZE: u32 = 16;-pub const ATLAS_W: u32 = ATLAS_TILES_PER_ROW * TILE_SIZE; // 128-pub const ATLAS_H: u32 = ATLAS_TILE_ROWS * TILE_SIZE;     // 128+pub const ATLAS_W: u32 = ATLAS_TILES_PER_ROW * TILE_SIZE; // 256+pub const ATLAS_H: u32 = ATLAS_TILE_ROWS * TILE_SIZE;     // 256  pub struct TextureAtlas {     pub image: vk::Image,@@ -22,11 +22,24 @@ impl TextureAtlas {         command_pool: vk::CommandPool,         queue: vk::Queue,         atlas_pixels: &[u8],+    ) -> Result<Self, String> {+        Self::new_sized(instance, device, phys, command_pool, queue, ATLAS_W, ATLAS_H, atlas_pixels)+    }+    // Generic RGBA sampled texture of arbitrary size (used for the block atlas and the entity atlas).+    pub unsafe fn new_sized(+        instance: &ash::Instance,+        device: &ash::Device,+        phys: vk::PhysicalDevice,+        command_pool: vk::CommandPool,+        queue: vk::Queue,+        atlas_w: u32,+        atlas_h: u32,+        atlas_pixels: &[u8],     ) -> Result<Self, String> {         let img_info = vk::ImageCreateInfo::default()             .image_type(vk::ImageType::TYPE_2D)             .format(vk::Format::R8G8B8A8_SRGB)-            .extent(vk::Extent3D { width: ATLAS_W, height: ATLAS_H, depth: 1 })+            .extent(vk::Extent3D { width: atlas_w, height: atlas_h, depth: 1 })             .mip_levels(1).array_layers(1)             .samples(vk::SampleCountFlags::TYPE_1)             .tiling(vk::ImageTiling::OPTIMAL)@@ -51,7 +64,7 @@ impl TextureAtlas {         device.begin_command_buffer(cmd, &begin).map_err(|e| format!("begin atlas cmd failed: {e:?}"))?;         let barrier_to_transfer = vk::ImageMemoryBarrier::default().old_layout(vk::ImageLayout::UNDEFINED).new_layout(vk::ImageLayout::TRANSFER_DST_OPTIMAL).image(image).subresource_range(vk::ImageSubresourceRange { aspect_mask: vk::ImageAspectFlags::COLOR, base_mip_level: 0, level_count: 1, base_array_layer: 0, layer_count: 1 }).src_access_mask(vk::AccessFlags::empty()).dst_access_mask(vk::AccessFlags::TRANSFER_WRITE);         device.cmd_pipeline_barrier(cmd, vk::PipelineStageFlags::TOP_OF_PIPE, vk::PipelineStageFlags::TRANSFER, vk::DependencyFlags::empty(), &[], &[], std::slice::from_ref(&barrier_to_transfer));-        let region = vk::BufferImageCopy::default().image_subresource(vk::ImageSubresourceLayers { aspect_mask: vk::ImageAspectFlags::COLOR, mip_level: 0, base_array_layer: 0, layer_count: 1 }).image_extent(vk::Extent3D { width: ATLAS_W, height: ATLAS_H, depth: 1 });+        let region = vk::BufferImageCopy::default().image_subresource(vk::ImageSubresourceLayers { aspect_mask: vk::ImageAspectFlags::COLOR, mip_level: 0, base_array_layer: 0, layer_count: 1 }).image_extent(vk::Extent3D { width: atlas_w, height: atlas_h, depth: 1 });         device.cmd_copy_buffer_to_image(cmd, staging.buffer, image, vk::ImageLayout::TRANSFER_DST_OPTIMAL, std::slice::from_ref(&region));         let barrier_to_shader = vk::ImageMemoryBarrier::default().old_layout(vk::ImageLayout::TRANSFER_DST_OPTIMAL).new_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL).image(image).subresource_range(vk::ImageSubresourceRange { aspect_mask: vk::ImageAspectFlags::COLOR, base_mip_level: 0, level_count: 1, base_array_layer: 0, layer_count: 1 }).src_access_mask(vk::AccessFlags::TRANSFER_WRITE).dst_access_mask(vk::AccessFlags::SHADER_READ);         device.cmd_pipeline_barrier(cmd, vk::PipelineStageFlags::TRANSFER, vk::PipelineStageFlags::FRAGMENT_SHADER, vk::DependencyFlags::empty(), &[], &[], std::slice::from_ref(&barrier_to_shader));@@ -85,3 +98,13 @@ pub fn load_atlas_bin() -> Vec<u8> {         fallback     } }++// Entity (mob) skin atlas: 4x4 grid of 64px cells; cell index = row*4 + col matches MobKind order.+pub const ENTITY_ATLAS_W: u32 = 256;+pub const ENTITY_ATLAS_H: u32 = 256;+pub const ENTITY_CELL: u32 = 64;+pub fn load_entity_atlas_bin() -> Vec<u8> {+    let maybe: &[u8] = include_bytes!("../shaders/entity_atlas.bin");+    let expect = (ENTITY_ATLAS_W * ENTITY_ATLAS_H * 4) as usize;+    if maybe.len() == expect { maybe.to_vec() } else { vec![255u8; expect] }+}
games/voxels/src/main/rust/src/vulkan/pipeline.rs
diff --git a/games/voxels/src/main/rust/src/vulkan/pipeline.rs b/games/voxels/src/main/rust/src/vulkan/pipeline.rsindex 5a834a5fa8..08dc846c7e 100644--- a/games/voxels/src/main/rust/src/vulkan/pipeline.rs+++ b/games/voxels/src/main/rust/src/vulkan/pipeline.rs@@ -5,6 +5,8 @@ const BLOCK_FRAG_SPV: &[u8] = include_bytes!("../../shaders/block.frag.spv"); const SKY_VERT_SPV: &[u8] = include_bytes!("../../shaders/sky.vert.spv"); const SKY_FRAG_SPV: &[u8] = include_bytes!("../../shaders/sky.frag.spv"); const CLOUD_FRAG_SPV: &[u8] = include_bytes!("../../shaders/cloud.frag.spv");+const ENTITY_VERT_SPV: &[u8] = include_bytes!("../../shaders/entity.vert.spv");+const ENTITY_FRAG_SPV: &[u8] = include_bytes!("../../shaders/entity.frag.spv"); const SHADOW_VERT_SPV: &[u8] = include_bytes!("../../shaders/shadow.vert.spv"); const WATER_VERT_SPV: &[u8] = include_bytes!("../../shaders/water.vert.spv"); const WATER_FRAG_SPV: &[u8] = include_bytes!("../../shaders/water.frag.spv");@@ -17,6 +19,7 @@ pub struct Pipelines {     pub pipeline: vk::Pipeline,     pub sky_pipeline: vk::Pipeline,     pub cloud_pipeline: vk::Pipeline,+    pub entity_pipeline: vk::Pipeline,     pub shadow_pipeline: vk::Pipeline,     pub water_pipeline: vk::Pipeline,     pub post_layout: vk::PipelineLayout,@@ -29,26 +32,29 @@ pub struct Pipelines { } impl Pipelines {     // Classic Vulkan 1.0 RenderPass path - no KHR_dynamic_rendering, avoids Unable to load cmd_begin_rendering-    pub unsafe fn new(device: &ash::Device, render_pass: vk::RenderPass, shadow_render_pass: vk::RenderPass, composite_rp: vk::RenderPass, post_rp: vk::RenderPass, post_desc_layout: vk::DescriptorSetLayout, ubo_buffer: vk::Buffer, ubo_size: u64, atlas_view: vk::ImageView, atlas_sampler: vk::Sampler, shadow_view: vk::ImageView, shadow_sampler: vk::Sampler) -> Result<Self, String> {+    pub unsafe fn new(device: &ash::Device, render_pass: vk::RenderPass, shadow_render_pass: vk::RenderPass, composite_rp: vk::RenderPass, post_rp: vk::RenderPass, post_desc_layout: vk::DescriptorSetLayout, ubo_buffer: vk::Buffer, ubo_size: u64, atlas_view: vk::ImageView, atlas_sampler: vk::Sampler, shadow_view: vk::ImageView, shadow_sampler: vk::Sampler, entity_view: vk::ImageView, entity_sampler: vk::Sampler) -> Result<Self, String> {         let bindings = [             vk::DescriptorSetLayoutBinding::default().binding(0).descriptor_type(vk::DescriptorType::UNIFORM_BUFFER).descriptor_count(1).stage_flags(vk::ShaderStageFlags::VERTEX | vk::ShaderStageFlags::FRAGMENT),             vk::DescriptorSetLayoutBinding::default().binding(1).descriptor_type(vk::DescriptorType::COMBINED_IMAGE_SAMPLER).descriptor_count(1).stage_flags(vk::ShaderStageFlags::FRAGMENT),             vk::DescriptorSetLayoutBinding::default().binding(2).descriptor_type(vk::DescriptorType::COMBINED_IMAGE_SAMPLER).descriptor_count(1).stage_flags(vk::ShaderStageFlags::FRAGMENT),+            vk::DescriptorSetLayoutBinding::default().binding(3).descriptor_type(vk::DescriptorType::COMBINED_IMAGE_SAMPLER).descriptor_count(1).stage_flags(vk::ShaderStageFlags::FRAGMENT),         ];         let dsl = device.create_descriptor_set_layout(&vk::DescriptorSetLayoutCreateInfo::default().bindings(&bindings), None).map_err(|e| format!("dsl {e:?}"))?;         let layouts = [dsl];         let layout = device.create_pipeline_layout(&vk::PipelineLayoutCreateInfo::default().set_layouts(&layouts), None).map_err(|e| format!("layout {e:?}"))?;-        let pool_sizes = [vk::DescriptorPoolSize::default().ty(vk::DescriptorType::UNIFORM_BUFFER).descriptor_count(2), vk::DescriptorPoolSize::default().ty(vk::DescriptorType::COMBINED_IMAGE_SAMPLER).descriptor_count(4)];+        let pool_sizes = [vk::DescriptorPoolSize::default().ty(vk::DescriptorType::UNIFORM_BUFFER).descriptor_count(2), vk::DescriptorPoolSize::default().ty(vk::DescriptorType::COMBINED_IMAGE_SAMPLER).descriptor_count(6)];         let pool = device.create_descriptor_pool(&vk::DescriptorPoolCreateInfo::default().pool_sizes(&pool_sizes).max_sets(2), None).map_err(|e| format!("pool {e:?}"))?;         let sets = device.allocate_descriptor_sets(&vk::DescriptorSetAllocateInfo::default().descriptor_pool(pool).set_layouts(&layouts)).map_err(|e| format!("alloc {e:?}"))?;         let set = sets[0];         let buf_info = vk::DescriptorBufferInfo::default().buffer(ubo_buffer).offset(0).range(ubo_size);         let img_info = vk::DescriptorImageInfo::default().image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL).image_view(atlas_view).sampler(atlas_sampler);         let shadow_info = vk::DescriptorImageInfo::default().image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL).image_view(shadow_view).sampler(shadow_sampler);+        let entity_info = vk::DescriptorImageInfo::default().image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL).image_view(entity_view).sampler(entity_sampler);         let writes = [             vk::WriteDescriptorSet::default().dst_set(set).dst_binding(0).descriptor_type(vk::DescriptorType::UNIFORM_BUFFER).buffer_info(std::slice::from_ref(&buf_info)),             vk::WriteDescriptorSet::default().dst_set(set).dst_binding(1).descriptor_type(vk::DescriptorType::COMBINED_IMAGE_SAMPLER).image_info(std::slice::from_ref(&img_info)),-            vk::WriteDescriptorSet::default().dst_set(set).dst_binding(2).descriptor_type(vk::DescriptorType::COMBINED_IMAGE_SAMPLER).image_info(std::slice::from_ref(&shadow_info))+            vk::WriteDescriptorSet::default().dst_set(set).dst_binding(2).descriptor_type(vk::DescriptorType::COMBINED_IMAGE_SAMPLER).image_info(std::slice::from_ref(&shadow_info)),+            vk::WriteDescriptorSet::default().dst_set(set).dst_binding(3).descriptor_type(vk::DescriptorType::COMBINED_IMAGE_SAMPLER).image_info(std::slice::from_ref(&entity_info)),         ];         device.update_descriptor_sets(&writes, &[]);         let vert_mod = Self::create_module(device, BLOCK_VERT_SPV)?;@@ -114,6 +120,22 @@ impl Pipelines {         device.destroy_shader_module(cloud_vert_mod, None);         device.destroy_shader_module(cloud_frag_mod, None); +        // Entity pipeline: mob box models, opaque (alpha-tested in the shader), depth-tested + written,+        // same block vertex format + descriptor set (samples the entity atlas at binding 3).+        let entity_vert_mod = Self::create_module(device, ENTITY_VERT_SPV)?;+        let entity_frag_mod = Self::create_module(device, ENTITY_FRAG_SPV)?;+        let entity_stages = [+            vk::PipelineShaderStageCreateInfo::default().stage(vk::ShaderStageFlags::VERTEX).module(entity_vert_mod).name(&entry),+            vk::PipelineShaderStageCreateInfo::default().stage(vk::ShaderStageFlags::FRAGMENT).module(entity_frag_mod).name(&entry)+        ];+        let entity_ds = vk::PipelineDepthStencilStateCreateInfo::default().depth_test_enable(true).depth_write_enable(true).depth_compare_op(vk::CompareOp::LESS);+        let entity_att = vk::PipelineColorBlendAttachmentState::default().color_write_mask(vk::ColorComponentFlags::RGBA).blend_enable(false);+        let entity_cb = vk::PipelineColorBlendStateCreateInfo::default().attachments(std::slice::from_ref(&entity_att));+        let entity_pi = vk::GraphicsPipelineCreateInfo::default().stages(&entity_stages).vertex_input_state(&vi).input_assembly_state(&ia).viewport_state(&vp_state).rasterization_state(&raster).multisample_state(&ms).depth_stencil_state(&entity_ds).color_blend_state(&entity_cb).dynamic_state(&dyn_state).layout(layout).render_pass(render_pass).subpass(0);+        let entity_pipes = device.create_graphics_pipelines(vk::PipelineCache::null(), std::slice::from_ref(&entity_pi), None).map_err(|(_, e)| format!("entity pipe {e:?}"))?;+        device.destroy_shader_module(entity_vert_mod, None);+        device.destroy_shader_module(entity_frag_mod, None);+         // Shadow pipeline: depth-only, renders terrain from the sun into the shadow render pass. No         // fragment shader / color attachment; depth bias reduces shadow acne.         let shadow_vert_mod = Self::create_module(device, SHADOW_VERT_SPV)?;@@ -173,7 +195,7 @@ impl Pipelines {         device.destroy_shader_module(blur_mod, None);         device.destroy_shader_module(composite_mod, None); -        Ok(Self{layout, pipeline: pipes[0], sky_pipeline: sky_pipes[0], cloud_pipeline: cloud_pipes[0], shadow_pipeline: shadow_pipes[0], water_pipeline: water_pipes[0], post_layout, bright_pipeline, blur_pipeline, composite_pipeline, descriptor_set_layout: dsl, descriptor_pool: pool, descriptor_set: set})+        Ok(Self{layout, pipeline: pipes[0], sky_pipeline: sky_pipes[0], cloud_pipeline: cloud_pipes[0], entity_pipeline: entity_pipes[0], shadow_pipeline: shadow_pipes[0], water_pipeline: water_pipes[0], post_layout, bright_pipeline, blur_pipeline, composite_pipeline, descriptor_set_layout: dsl, descriptor_pool: pool, descriptor_set: set})     }     unsafe fn create_module(device: &ash::Device, spv: &[u8]) -> Result<vk::ShaderModule, String> {         let code = unsafe { std::slice::from_raw_parts(spv.as_ptr() as *const u32, spv.len()/4) };@@ -183,6 +205,7 @@ impl Pipelines {         device.destroy_pipeline(self.pipeline, None);         device.destroy_pipeline(self.sky_pipeline, None);         device.destroy_pipeline(self.cloud_pipeline, None);+        device.destroy_pipeline(self.entity_pipeline, None);         device.destroy_pipeline(self.shadow_pipeline, None);         device.destroy_pipeline(self.water_pipeline, None);         device.destroy_pipeline(self.bright_pipeline, None);
games/voxels/src/main/rust/src/vulkan/renderer.rs
diff --git a/games/voxels/src/main/rust/src/vulkan/renderer.rs b/games/voxels/src/main/rust/src/vulkan/renderer.rsindex 49f0a5f98f..6d39efc999 100644--- a/games/voxels/src/main/rust/src/vulkan/renderer.rs+++ b/games/voxels/src/main/rust/src/vulkan/renderer.rs@@ -8,6 +8,10 @@ use crate::vulkan::pipeline::Pipelines; use crate::vulkan::buffers::{AllocatedBuffer, Vertex as VulkanVertex, UboData}; use crate::texture_atlas::TextureAtlas; +// Capacity of the per-frame mob mesh buffers (~a few hundred mobs worth of boxes).+const MAX_ENTITY_VERTS: usize = 24000;+const MAX_ENTITY_INDICES: usize = 36000;+ pub struct ChunkGpuMesh {     pub vertex_buffer: AllocatedBuffer,     pub index_buffer: AllocatedBuffer,@@ -38,6 +42,10 @@ pub struct VulkanRenderer {     pub ctx: VulkanContext,     pub swapchain: Swapchain,     pub atlas: TextureAtlas,+    pub entity_atlas: TextureAtlas,+    pub entity_vbuf: AllocatedBuffer,+    pub entity_ibuf: AllocatedBuffer,+    pub entity_index_count: u32,     pub shadow: crate::vulkan::shadow::ShadowMap,     pub postfx: crate::vulkan::postfx::PostFx,     pub pipelines: Pipelines,@@ -73,10 +81,15 @@ impl VulkanRenderer {         let command_pool = device.create_command_pool(&pool_info, None).map_err(|e| format!("pool {e:?}"))?;         let atlas_pixels = crate::texture_atlas::load_atlas_bin();         let atlas = unsafe { TextureAtlas::new(&instance, &device, phys, command_pool, ctx.queue, &atlas_pixels)? };+        let entity_pixels = crate::texture_atlas::load_entity_atlas_bin();+        let entity_atlas = unsafe { TextureAtlas::new_sized(&instance, &device, phys, command_pool, ctx.queue, crate::texture_atlas::ENTITY_ATLAS_W, crate::texture_atlas::ENTITY_ATLAS_H, &entity_pixels)? };+        // Dynamic host-visible buffers for the per-frame mob mesh.+        let entity_vbuf = unsafe { AllocatedBuffer::new(&instance, &device, phys, (MAX_ENTITY_VERTS * std::mem::size_of::<VulkanVertex>()) as u64, vk::BufferUsageFlags::VERTEX_BUFFER, vk::MemoryPropertyFlags::HOST_VISIBLE | vk::MemoryPropertyFlags::HOST_COHERENT)? };+        let entity_ibuf = unsafe { AllocatedBuffer::new(&instance, &device, phys, (MAX_ENTITY_INDICES * 4) as u64, vk::BufferUsageFlags::INDEX_BUFFER, vk::MemoryPropertyFlags::HOST_VISIBLE | vk::MemoryPropertyFlags::HOST_COHERENT)? };         let shadow = unsafe { crate::vulkan::shadow::ShadowMap::new(&instance, &device, phys)? };         let postfx = unsafe { crate::vulkan::postfx::PostFx::new(&instance, &device, phys, &swapchain, vk::Format::D32_SFLOAT)? };         let ubo_buffer = unsafe { AllocatedBuffer::new(&instance, &device, phys, ubo_size, vk::BufferUsageFlags::UNIFORM_BUFFER, vk::MemoryPropertyFlags::HOST_VISIBLE | vk::MemoryPropertyFlags::HOST_COHERENT)? };-        let pipelines = unsafe { Pipelines::new(&device, postfx.main_rp, shadow.render_pass, swapchain.render_pass, postfx.post_rp, postfx.desc_layout, ubo_buffer.buffer, ubo_size, atlas.view, atlas.sampler, shadow.view, shadow.sampler)? };+        let pipelines = unsafe { Pipelines::new(&device, postfx.main_rp, shadow.render_pass, swapchain.render_pass, postfx.post_rp, postfx.desc_layout, ubo_buffer.buffer, ubo_size, atlas.view, atlas.sampler, shadow.view, shadow.sampler, entity_atlas.view, entity_atlas.sampler)? };         let alloc_info = vk::CommandBufferAllocateInfo::default().command_pool(command_pool).level(vk::CommandBufferLevel::PRIMARY).command_buffer_count(swapchain.images.len() as u32);         let command_buffers = device.allocate_command_buffers(&alloc_info).map_err(|e| format!("alloc cmd {e:?}"))?;         let sem_info = vk::SemaphoreCreateInfo::default();@@ -92,7 +105,7 @@ impl VulkanRenderer {         let img_count = swapchain.images.len();         let query_pool = device.create_query_pool(&vk::QueryPoolCreateInfo::default().query_type(vk::QueryType::TIMESTAMP).query_count(img_count as u32 * 5), None).map_err(|e| format!("query pool {e:?}"))?;         let ts_period = ctx.device_properties.limits.timestamp_period;-        Ok(Self { ctx, swapchain, atlas, shadow, postfx, pipelines, command_pool, command_buffers, image_available, render_finished, in_flight_fences, ubo_buffer, ubo_data: UboData::default(), queued_meshes: HashMap::new(), gpu_meshes: HashMap::new(), current_frame: 0, frame_count: 0, width, height, query_pool, ts_period, ts_written: vec![false; img_count], pass_ms: [0.0;4], drawn_sections: 0 })+        Ok(Self { ctx, swapchain, atlas, entity_atlas, entity_vbuf, entity_ibuf, entity_index_count: 0, shadow, postfx, pipelines, command_pool, command_buffers, image_available, render_finished, in_flight_fences, ubo_buffer, ubo_data: UboData::default(), queued_meshes: HashMap::new(), gpu_meshes: HashMap::new(), current_frame: 0, frame_count: 0, width, height, query_pool, ts_period, ts_written: vec![false; img_count], pass_ms: [0.0;4], drawn_sections: 0 })     }     pub unsafe fn resize(&mut self, width: u32, height: u32) -> Result<(), String> {         if width==0 || height==0 { return Ok(()); }@@ -109,6 +122,17 @@ impl VulkanRenderer {     pub unsafe fn enqueue_mesh(&mut self, chunk_x: i32, sec_y: i32, chunk_z: i32, mesh: Option<MeshData>) {         self.queued_meshes.insert((chunk_x, sec_y, chunk_z), mesh);     }+    // Replace the mob mesh for this frame (host-visible buffers, clamped to capacity).+    pub unsafe fn upload_entity_mesh(&mut self, verts: &[VulkanVertex], indices: &[u32]) {+        let nv = verts.len().min(MAX_ENTITY_VERTS);+        let ni = indices.len().min(MAX_ENTITY_INDICES);+        if nv == 0 || ni == 0 { self.entity_index_count = 0; return; }+        let vbytes = std::slice::from_raw_parts(verts.as_ptr() as *const u8, nv * std::mem::size_of::<VulkanVertex>());+        let ibytes = std::slice::from_raw_parts(indices.as_ptr() as *const u8, ni * 4);+        self.entity_vbuf.upload(&self.ctx.device, vbytes);+        self.entity_ibuf.upload(&self.ctx.device, ibytes);+        self.entity_index_count = ni as u32;+    }     pub unsafe fn process_pending_uploads(&mut self) -> Result<(), String> {         let mut processed=0;         let keys: Vec<_> = self.queued_meshes.keys().copied().collect();@@ -256,6 +280,14 @@ impl VulkanRenderer {                 device.cmd_bind_index_buffer(cmd, gpu_mesh.index_buffer.buffer, 0, vk::IndexType::UINT32);                 device.cmd_draw_indexed(cmd, gpu_mesh.index_count, 1, 0, 0, 0);             }+            // Mobs (opaque, depth-tested) using the entity atlas.+            if self.entity_index_count > 0 {+                device.cmd_bind_pipeline(cmd, vk::PipelineBindPoint::GRAPHICS, self.pipelines.entity_pipeline);+                let offs = [0u64];+                device.cmd_bind_vertex_buffers(cmd, 0, std::slice::from_ref(&self.entity_vbuf.buffer), &offs);+                device.cmd_bind_index_buffer(cmd, self.entity_ibuf.buffer, 0, vk::IndexType::UINT32);+                device.cmd_draw_indexed(cmd, self.entity_index_count, 1, 0, 0, 0);+            }             device.cmd_bind_pipeline(cmd, vk::PipelineBindPoint::GRAPHICS, self.pipelines.sky_pipeline);             device.cmd_draw(cmd, 3, 1, 0, 0);             // Volumetric clouds: depth-tested layer at fixed altitude, blended over sky + terrain.@@ -349,6 +381,9 @@ impl VulkanRenderer {         for &f in &self.in_flight_fences { self.ctx.device.destroy_fence(f, None); }         self.ctx.device.destroy_command_pool(self.command_pool, None);         self.ctx.device.destroy_query_pool(self.query_pool, None);+        self.entity_vbuf.destroy(&self.ctx.device);+        self.entity_ibuf.destroy(&self.ctx.device);+        self.entity_atlas.destroy(&self.ctx.device);         self.atlas.destroy(&self.ctx.device);         self.shadow.destroy(&self.ctx.device);         self.pipelines.destroy(&self.ctx.device);
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 f513a06288..a913f39cb6 100644--- a/games/voxels/src/main/rust/src/world/block.rs+++ b/games/voxels/src/main/rust/src/world/block.rs@@ -41,9 +41,54 @@ pub enum Block {     Bookshelf = 33,     CraftingTable = 34,     Furnace = 35,+    RedSand = 36,+    RedSandstone = 37,+    Sandstone = 38,+    Podzol = 39,+    CoarseDirt = 40,+    Mycelium = 41,+    PackedIce = 42,+    Ice = 43,+    BlueIce = 44,+    Mud = 45,+    RootedDirt = 46,+    DarkOakLog = 47,+    DarkOakLeaves = 48,+    DarkOakPlanks = 49,+    AcaciaLog = 50,+    JungleLog = 51,+    JunglePlanks = 52,+    GraniteBricks = 53,+    DeepslateBricks = 54,+    NetherBricks = 55,+    EndStoneBricks = 56,+    CobbledDeepslate = 57,+    HayBlock = 58,+    Farmland = 59,+    PackedDirt = 60,+    TubeCoral = 61,+    BrainCoral = 62,+    BubbleCoral = 63,+    FireCoral = 64,+    HornCoral = 65,+    Kelp = 66,+    SeaLantern = 67,+    Prismarine = 68,+    DarkPrismarine = 69,+    Dripstone = 70,+    MossBlock = 71,+    Sculk = 72,+    Amethyst = 73,+    Calcite = 74,+    Tuff = 75,+    Magma = 76,+    Glowstone = 77,+    Obsidian = 78,+    Clay = 79,+    AzaleaLeaves = 80, } -pub const MAX_BLOCK_ID: u8 = 35;+pub const MAX_BLOCK_ID: u8 = 80;  impl Block {     pub fn from_id(id: u8) -> Self {@@ -53,7 +98,7 @@ impl Block {     pub fn is_air(self) -> bool { matches!(self, Self::Air) }     pub fn is_solid(self) -> bool { !matches!(self, Self::Air | Self::Water | Self::Glass) }     pub fn is_transparent(self) -> bool {-        matches!(self, Self::Air | Self::Glass | Self::Leaves | Self::Water | Self::BirchLeaves | Self::SpruceLeaves)+        matches!(self, Self::Air | Self::Glass | Self::Leaves | Self::Water | Self::BirchLeaves | Self::SpruceLeaves | Self::DarkOakLeaves | Self::AzaleaLeaves)     }     pub fn is_opaque(self) -> bool { !self.is_transparent() } @@ -101,6 +146,51 @@ impl Block {             Self::Bookshelf => 10,             Self::CraftingTable => 39,             Self::Furnace => 42,+            Self::RedSand => 64,+            Self::RedSandstone => 66,+            Self::Sandstone => 68,+            Self::Podzol => 70,+            Self::CoarseDirt => 72,+            Self::Mycelium => 73,+            Self::PackedIce => 74,+            Self::Ice => 75,+            Self::BlueIce => 76,+            Self::Mud => 77,+            Self::RootedDirt => 78,+            Self::DarkOakLog => 80,+            Self::DarkOakLeaves => 81,+            Self::DarkOakPlanks => 82,+            Self::AcaciaLog => 84,+            Self::JungleLog => 86,+            Self::JunglePlanks => 87,+            Self::GraniteBricks => 88,+            Self::DeepslateBricks => 89,+            Self::NetherBricks => 90,+            Self::EndStoneBricks => 91,+            Self::CobbledDeepslate => 92,+            Self::HayBlock => 94,+            Self::Farmland => 95,+            Self::PackedDirt => 96,+            Self::TubeCoral => 97,+            Self::BrainCoral => 98,+            Self::BubbleCoral => 99,+            Self::FireCoral => 100,+            Self::HornCoral => 101,+            Self::Kelp => 102,+            Self::SeaLantern => 103,+            Self::Prismarine => 104,+            Self::DarkPrismarine => 105,+            Self::Dripstone => 106,+            Self::MossBlock => 107,+            Self::Sculk => 108,+            Self::Amethyst => 109,+            Self::Calcite => 110,+            Self::Tuff => 111,+            Self::Magma => 112,+            Self::Glowstone => 113,+            Self::Obsidian => 114,+            Self::Clay => 115,+            Self::AzaleaLeaves => 116,         }     }     pub fn tile_bottom(self) -> u32 {@@ -112,6 +202,10 @@ impl Block {             Self::Bookshelf => 10,             Self::CraftingTable => 10,             Self::Furnace => 43,+            Self::Sandstone => 69,+            Self::Podzol => 1,+            Self::Mycelium => 1,+            Self::Farmland => 1,             _ => self.tile_top(),         }     }@@ -124,6 +218,14 @@ impl Block {             Self::Bookshelf => 38,             Self::CraftingTable => 40,             Self::Furnace => 43,+            Self::RedSandstone => 65,+            Self::Sandstone => 67,+            Self::Podzol => 71,+            Self::DarkOakLog => 79,+            Self::AcaciaLog => 83,+            Self::JungleLog => 85,+            Self::HayBlock => 93,+            Self::Farmland => 1,             _ => self.tile_top(),         }     }@@ -132,6 +234,7 @@ impl Block {             Self::Leaves => [0.42, 0.72, 0.33],             Self::BirchLeaves => [0.55, 0.72, 0.35],             Self::SpruceLeaves => [0.32, 0.55, 0.34],+            Self::DarkOakLeaves => [0.27, 0.45, 0.20],             Self::Water => [0.6, 0.8, 1.0],             _ => [1.0, 1.0, 1.0],         }@@ -141,15 +244,18 @@ impl Block {     } } -// Atlas is 8 tiles wide x 8 tall (128x128). Tiles 0..15 = base blocks, 16 = grass side overlay,-// 17.. = extra blocks. GRASS_SIDE_TILE is a shader sentinel (dirt + tinted overlay composite).-pub const ATLAS_COLS: f32 = 8.0;-pub const ATLAS_ROWS: f32 = 8.0;+// Atlas is 16 tiles wide x 16 tall (256x256). Tiles 0..15 = base blocks, 16 = grass side overlay,+// 17..63 = the original extra blocks, 64.. = the biome/expansion blocks. GRASS_SIDE_TILE is a shader+// sentinel (dirt + tinted overlay composite).+pub const ATLAS_COLS: f32 = 16.0;+pub const ATLAS_ROWS: f32 = 16.0; pub const GRASS_SIDE_OVERLAY: u32 = 16;-pub const GRASS_SIDE_TILE: u32 = 100;+// Shader sentinel (dirt + tinted overlay composite). Kept far above any real tile index so the+// atlas can use tiles up to ~999.+pub const GRASS_SIDE_TILE: u32 = 1000; pub fn tile_uv(tile_index: u32) -> (f32,f32,f32,f32) {-    let tx = (tile_index % 8) as f32;-    let ty = (tile_index / 8) as f32;+    let tx = (tile_index % 16) as f32;+    let ty = (tile_index / 16) as f32;     let sx = 1.0 / ATLAS_COLS;     let sy = 1.0 / ATLAS_ROWS;     (tx*sx, ty*sy, (tx+1.0)*sx, (ty+1.0)*sy)
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 b4d1f0ef4c..1f2360944b 100644--- a/games/voxels/src/main/rust/src/world/generator.rs+++ b/games/voxels/src/main/rust/src/world/generator.rs@@ -5,7 +5,17 @@ use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher};  #[derive(Clone, Copy, PartialEq, Eq)]-pub enum Biome { Plains, Forest, Desert, Snowy, Mountain }+pub enum Biome {+    Plains, SunflowerPlains, Meadow,+    Forest, BirchForest, DarkForest, FlowerForest,+    Taiga, SnowyTaiga,+    Savanna, Jungle, SparseJungle,+    Swamp, MangroveSwamp,+    Desert, Badlands,+    SnowyPlains, IceSpikes, MushroomFields,+    WindsweptHills, Grove, SnowySlopes,+    JaggedPeaks, FrozenPeaks, StonyPeaks,+}  pub struct TerrainGen {     perlin_height: Perlin,@@ -29,25 +39,88 @@ impl TerrainGen {     // same low-frequency biome noise the terrain height uses, plus a humidity sample, so the ground     // colour shifts smoothly between cool-lush, warm-lush and dry regions.     pub fn grass_tint(&self, wx: f64, wz: f64) -> [f32; 3] {-        let temp = (self.perlin_biome.get([wx * 0.0015, wz * 0.0015]) as f32 * 0.5 + 0.5).clamp(0.0, 1.0);-        let humid = (self.perlin_biome.get([wx * 0.0015 + 137.0, wz * 0.0015 - 91.0]) as f32 * 0.5 + 0.5).clamp(0.0, 1.0);-        let lerp3 = |a: [f32; 3], b: [f32; 3], t: f32| [a[0] + (b[0]-a[0])*t, a[1] + (b[1]-a[1])*t, a[2] + (b[2]-a[2])*t];-        let cold = [0.46, 0.62, 0.42]; // cool blue-green-        let lush = [0.40, 0.68, 0.28]; // temperate plains-        let dry  = [0.74, 0.72, 0.36]; // warm/dry yellow-green-        let warm = lerp3(dry, lush, humid);-        lerp3(cold, warm, temp)+        use Biome::*;+        match self.biome_at(wx, wz, self.height_at(wx, wz)) {+            Savanna => [0.74, 0.68, 0.32],                              // dry gold-green+            Jungle | SparseJungle | MangroveSwamp => [0.30, 0.66, 0.18], // vivid tropical+            Swamp => [0.42, 0.48, 0.27],                                // murky+            DarkForest => [0.26, 0.48, 0.20],                           // deep shade+            Desert | Badlands => [0.66, 0.64, 0.34],+            Taiga | SnowyTaiga | SnowyPlains | SnowySlopes | Grove | FrozenPeaks => [0.50, 0.62, 0.48],+            _ => {+                // Temperate default: smooth temperature x humidity blend.+                let temp = (self.perlin_biome.get([wx * 0.0015, wz * 0.0015]) as f32 * 0.5 + 0.5).clamp(0.0, 1.0);+                let humid = (self.perlin_biome.get([wx * 0.0015 + 137.0, wz * 0.0015 - 91.0]) as f32 * 0.5 + 0.5).clamp(0.0, 1.0);+                let lerp3 = |a: [f32; 3], b: [f32; 3], t: f32| [a[0] + (b[0]-a[0])*t, a[1] + (b[1]-a[1])*t, a[2] + (b[2]-a[2])*t];+                let cold = [0.46, 0.62, 0.42];+                let lush = [0.40, 0.68, 0.28];+                let dry  = [0.74, 0.72, 0.36];+                let warm = lerp3(dry, lush, humid);+                lerp3(cold, warm, temp)+            }+        }     }-    // Classify a column into a biome from temperature/humidity noise, with high elevation overriding-    // to Mountain. Same low-frequency biome noise as the grass tint so colour and terrain agree.+    // Classify a column into a biome from temperature/humidity/variant noise plus elevation. Mountain+    // bands take over at height; lowlands split by a Whittaker-style temp x humidity grid, with a+    // low-frequency "variant" noise selecting rarer sub-biomes (ice spikes, flower forest, etc.).     pub fn biome_at(&self, wx: f64, wz: f64, h: i32) -> Biome {-        if h > 104 { return Biome::Mountain; }         let temp = (self.perlin_biome.get([wx * 0.0015, wz * 0.0015]) as f32 * 0.5 + 0.5).clamp(0.0, 1.0);         let humid = (self.perlin_biome.get([wx * 0.0015 + 137.0, wz * 0.0015 - 91.0]) as f32 * 0.5 + 0.5).clamp(0.0, 1.0);-        if temp > 0.68 && humid < 0.45 { Biome::Desert }-        else if temp < 0.30 { Biome::Snowy }-        else if humid > 0.60 { Biome::Forest }-        else { Biome::Plains }+        let variant = (self.perlin_detail.get([wx * 0.004 + 53.0, wz * 0.004 - 17.0]) as f32 * 0.5 + 0.5).clamp(0.0, 1.0);+        // High mountains.+        if h > 118 {+            if temp < 0.35 { return Biome::FrozenPeaks; }+            if temp > 0.66 { return Biome::StonyPeaks; }+            return Biome::JaggedPeaks;+        }+        if h > 98 {+            if temp < 0.34 { return Biome::SnowySlopes; }+            if humid > 0.5 { return Biome::Grove; }+            return Biome::WindsweptHills;+        }+        // Lowlands by temperature band.+        if temp < 0.28 {+            if variant > 0.86 { return Biome::IceSpikes; }+            if humid > 0.55 { return Biome::SnowyTaiga; }+            return Biome::SnowyPlains;+        } else if temp > 0.72 {+            if humid < 0.28 { return if variant > 0.72 { Biome::Badlands } else { Biome::Desert }; }+            if humid > 0.60 { return if variant > 0.5 { Biome::Jungle } else { Biome::SparseJungle }; }+            return Biome::Savanna;+        } else {+            if humid < 0.30 { return Biome::Savanna; }+            if humid > 0.78 { return if variant > 0.7 { Biome::MushroomFields } else if temp > 0.5 { Biome::MangroveSwamp } else { Biome::Swamp }; }+            if humid > 0.55 { return if variant > 0.78 { Biome::DarkForest } else if variant < 0.25 { Biome::Taiga } else { Biome::Forest }; }+            // Plains band with variants.+            if variant > 0.88 { return Biome::SunflowerPlains; }+            if variant > 0.72 { return Biome::FlowerForest; }+            if variant < 0.14 { return Biome::BirchForest; }+            if variant < 0.30 { return Biome::Meadow; }+            return Biome::Plains;+        }+    }+    // Surface + subsurface block for a biome at surface height `h` (before the sea/beach override).+    fn surface_blocks(&self, biome: Biome, h: usize, wx: f64, wz: f64) -> (u8, u8) {+        use Biome::*;+        match biome {+            Desert => (6, 38),                       // sand / sandstone+            Badlands => (36, 37),                    // red sand / red sandstone+            SnowyPlains | SnowySlopes | Grove => (11, 2), // snow / dirt+            SnowyTaiga => (11, 2),+            IceSpikes => (11, 42),                   // snow / packed ice+            FrozenPeaks => (42, 42),                 // packed ice+            JaggedPeaks => if h > 124 { (11, 1) } else { (1, 1) }, // snow cap / bare rock+            StonyPeaks => (1, 1),+            WindsweptHills => (3, 1),                // grass over stone+            MushroomFields => (41, 2),               // mycelium / dirt+            Swamp | MangroveSwamp => (45, 45),       // mud+            Taiga => {+                // Patches of podzol/coarse dirt among the grass.+                let n = self.perlin_detail.get([wx * 0.09, wz * 0.09]);+                if n > 0.35 { (39, 2) } else if n < -0.5 { (40, 40) } else { (3, 2) }+            }+            _ => (3, 2),                             // grass / dirt (plains, forests, savanna, jungle)+        }     }     // Plant a simple tree: a trunk of `log` topped with a `leaf` canopy. Shared by all wooded biomes.     fn plant_tree(&self, chunk: &mut Chunk, dx: usize, dz: usize, h: usize, log: u8, leaf: u8, trunk_h: usize) {@@ -83,10 +156,28 @@ impl TerrainGen {         base.clamp(12.0, 128.0) as i32     }     pub fn cave_at(&self, x: f64, y: f64, z: f64) -> bool {-        if y < 10.0 || y > 90.0 { return false; }-        let v = self.perlin_cave.get([x * 0.07, y * 0.08, z * 0.07]);-        let v2 = self.perlin_cave.get([x * 0.15 + 100.0, y * 0.15, z * 0.15]) * 0.5;-        (v + v2) > 0.58+        if y < 6.0 || y > 112.0 { return false; }+        // Spaghetti tunnels: two independent noise fields both near zero carve winding 1D tubes+        // (Perlin-worm approximation), giving long connected passages instead of isolated blobs.+        let n1 = self.perlin_cave.get([x * 0.021 + 11.0, y * 0.030, z * 0.021]).abs();+        let n2 = self.perlin_cave.get([x * 0.021 - 7.0, y * 0.030 + 50.0, z * 0.021]).abs();+        let width = 0.055 + 0.03 * (self.perlin_detail.get([x * 0.01, z * 0.01]) * 0.5 + 0.5);+        if n1 < width && n2 < width { return true; }+        // Cheese caverns: larger open rooms, concentrated in the lower half of the world.+        let cheese = self.perlin_cave.get([x * 0.045, y * 0.055, z * 0.045]);+        let depth_bias = ((60.0 - y) / 55.0).clamp(0.0, 1.0) as f64; // more/bigger caverns deeper+        cheese > (0.70 - 0.16 * depth_bias)+    }+    // Underground biome for cave decoration, from depth + humidity.+    fn cave_kind(&self, wx: f64, wz: f64, y: i32) -> u8 {+        if y < 20 { return 0; } // deep dark+        let humid = self.perlin_biome.get([wx * 0.0015 + 137.0, wz * 0.0015 - 91.0]);+        if humid > 0.15 { 1 } else { 2 } // 1 = lush, 2 = dripstone+    }+    // Ocean temperature class: 0 frozen, 1 cold, 2 lukewarm, 3 warm.+    fn ocean_kind(&self, wx: f64, wz: f64) -> u8 {+        let t = (self.perlin_biome.get([wx * 0.0015, wz * 0.0015]) as f32 * 0.5 + 0.5).clamp(0.0, 1.0);+        if t < 0.28 { 0 } else if t < 0.5 { 1 } else if t < 0.72 { 2 } else { 3 }     }     pub fn fill_chunk(&self, chunk: &mut Chunk) {         let (ox, oz) = chunk.pos.world_origin();@@ -109,21 +200,18 @@ impl TerrainGen {                     chunk.set_block(dx, y, dz, 1);                 }             }-            // Subsurface band just under the surface: sand in deserts, stone on mountains, else dirt.-            let sub: u8 = match biome { Biome::Desert => 6, Biome::Mountain => 1, _ => 2 };+            let (surface_top, sub) = self.surface_blocks(biome, h, wx, wz);+            // Subsurface band just under the surface.             for y in stone_top..h.saturating_sub(1) {                 if !self.cave_at(wx, y as f64, wz) {                     chunk.set_block(dx, y, dz, sub);                 }             }             if h > 0 && !self.cave_at(wx, h as f64, wz) {-                // Surface block by biome; underwater/beach columns are always sand.-                let surface: u8 = if h < 62 { 6 } else { match biome {-                    Biome::Desert => 6,                                   // sand-                    Biome::Snowy => 11,                                   // snow-                    Biome::Mountain => if h > 118 { 11 } else if h > 108 { 1 } else { 3 }, // snow cap / bare rock / grass-                    _ => 3,                                               // grass-                }};+                // Beaches: sand where the ground meets the sea (snowy biomes get snowy beaches).+                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 };                 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); }             }@@ -139,32 +227,139 @@ impl TerrainGen {             let mut hasher = DefaultHasher::new();             (ox+dx as i32, oz+dz as i32, self.seed).hash(&mut hasher);             let r = hasher.finish() % 1000;+            let alt = (hasher.finish() >> 8) % 2 == 0;             let th = 4 + (hasher.finish() % 4) as usize;+            use Biome::*;+            let grassy = surf == 3;             match biome {-                Biome::Desert => {-                    // Sparse cacti-like columns of cactus... none available, so rare surface rocks.-                    if surf == 6 && r < 4 { let y = h + 1; if y < CHUNK_HEIGHT { chunk.set_block(dx, y, dz, 8); } }+                Desert => { if surf == 6 && r < 4 { let y = h + 1; if y < CHUNK_HEIGHT { chunk.set_block(dx, y, dz, 8); } } }+                Badlands => { /* barren red terrain */ }+                SnowyPlains => { if surf == 11 && r < 4 { self.plant_tree(chunk, dx, dz, h, 29, 31, th); } }+                SnowyTaiga => { if surf == 11 && r < 40 { self.plant_tree(chunk, dx, dz, h, 29, 31, th + 1); } }+                IceSpikes => {+                    // Tall spikes of packed ice.+                    if surf == 11 && r < 12 {+                        let sh = 4 + (hasher.finish() % 8) as usize;+                        for ty in 1..=sh { let y = h + ty; if y < CHUNK_HEIGHT { chunk.set_block(dx, y, dz, 42); } }+                    }                 }-                Biome::Snowy => {-                    if surf == 11 && r < 22 { self.plant_tree(chunk, dx, dz, h, 29, 31, th + 1); } // spruce+                Taiga => { if (surf == 3 || surf == 39 || surf == 40) && r < 55 { self.plant_tree(chunk, dx, dz, h, 29, 31, th + 1); } }+                Forest => { if grassy && r < 65 { if alt { self.plant_tree(chunk, dx, dz, h, 26, 28, th); } else { self.plant_tree(chunk, dx, dz, h, 4, 5, th); } } }+                BirchForest => { if grassy && r < 70 { self.plant_tree(chunk, dx, dz, h, 26, 28, th + 1); } }+                DarkForest => { if grassy && r < 90 { self.plant_tree(chunk, dx, dz, h, 47, 48, th); } } // dense dark oak+                FlowerForest => { if grassy && r < 18 { self.plant_tree(chunk, dx, dz, h, 4, 5, th); } }+                Savanna => { if grassy && r < 12 { self.plant_tree(chunk, dx, dz, h, 50, 5, th.min(5)); } } // acacia (oak leaves)+                Jungle => { if grassy && r < 85 { self.plant_tree(chunk, dx, dz, h, 51, 5, th + 3); } }     // tall jungle+                SparseJungle => { if grassy && r < 22 { self.plant_tree(chunk, dx, dz, h, 51, 5, th + 2); } }+                Swamp => { if grassy && r < 8 { self.plant_tree(chunk, dx, dz, h, 4, 5, th); } }+                MangroveSwamp => { if surf == 45 && r < 20 { self.plant_tree(chunk, dx, dz, h, 51, 5, th); } }+                MushroomFields => { if surf == 41 && r < 3 { let y = h + 1; if y < CHUNK_HEIGHT { chunk.set_block(dx, y, dz, 5); } } }+                Meadow => { if grassy && r == 3 { self.plant_tree(chunk, dx, dz, h, 4, 5, th); } }+                Grove => { if surf == 11 && r < 30 { self.plant_tree(chunk, dx, dz, h, 29, 31, th); } }+                WindsweptHills => { if grassy && r < 6 { self.plant_tree(chunk, dx, dz, h, 29, 31, th); } }+                SnowySlopes | JaggedPeaks | FrozenPeaks | StonyPeaks => { /* bare peaks */ }+                Plains | SunflowerPlains => {+                    if grassy {+                        if r == 3 { let y = h + 1; if y < CHUNK_HEIGHT { chunk.set_block(dx, y, dz, 8); } }+                        else if r < 10 { self.plant_tree(chunk, dx, dz, h, 4, 5, th); }+                    }                 }-                Biome::Forest => {-                    if surf == 3 && r < 65 {-                        if (hasher.finish() >> 8) % 2 == 0 { self.plant_tree(chunk, dx, dz, h, 26, 28, th); } // birch-                        else { self.plant_tree(chunk, dx, dz, h, 4, 5, th); }                                 // oak+            }+        }}+        // --- Cave decoration: dress cave floors/ceilings by underground biome. ---+        for dz in 0..CHUNK_SIZE { for dx in 0..CHUNK_SIZE {+            let wx = (ox + dx as i32) as f64;+            let wz = (oz + dz as i32) as f64;+            let top = (heightmap[dz][dx] as usize).min(CHUNK_HEIGHT - 1);+            let mut y = 7usize;+            while y + 1 < top {+                let here = chunk.get_block(dx, y, dz);+                let above = chunk.get_block(dx, y + 1, dz);+                if here == 1 && above == 0 {+                    // Cave floor.+                    let kind = self.cave_kind(wx, wz, y as i32);+                    let mut hasher = DefaultHasher::new();+                    (ox + dx as i32, y as i32, oz + dz as i32, self.seed ^ 0x5EED).hash(&mut hasher);+                    let r = hasher.finish() % 100;+                    match kind {+                        0 => { if r < 22 { chunk.set_block(dx, y, dz, 72); } if r == 5 { chunk.set_block(dx, y + 1, dz, 77); } } // sculk / rare glowstone+                        1 => { if r < 40 { chunk.set_block(dx, y, dz, 71); } if r < 6 { chunk.set_block(dx, y + 1, dz, 80); } if r == 7 { chunk.set_block(dx, y + 1, dz, 77); } } // moss / azalea / glow+                        _ => { if r < 25 { chunk.set_block(dx, y, dz, 70); } } // dripstone+                    }+                } else if here == 0 && above == 1 {+                    // Cave ceiling: hanging dripstone in dry caves.+                    if self.cave_kind(wx, wz, y as i32) == 2 {+                        let mut hasher = DefaultHasher::new();+                        (ox + dx as i32, y as i32, oz + dz as i32, self.seed ^ 0xBEEF).hash(&mut hasher);+                        if hasher.finish() % 100 < 12 { chunk.set_block(dx, y, dz, 70); }                     }                 }-                Biome::Mountain => {-                    if surf == 3 && r < 8 { self.plant_tree(chunk, dx, dz, h, 29, 31, th); } // sparse spruce+                y += 1;+            }+        }}+        // --- Ocean floor: coral reefs / kelp by water temperature (survives the later water fill). ---+        for dz in 0..CHUNK_SIZE { for dx in 0..CHUNK_SIZE {+            let h = heightmap[dz][dx] as usize;+            if h + 1 >= Self::SEA_LEVEL { continue; }+            let floor = chunk.get_block(dx, h, dz);+            if floor != 6 && floor != 2 && floor != 1 { continue; }+            let wx = (ox + dx as i32) as f64;+            let wz = (oz + dz as i32) as f64;+            let kind = self.ocean_kind(wx, wz);+            let mut hasher = DefaultHasher::new();+            (ox + dx as i32, oz + dz as i32, self.seed ^ 0x0CEA).hash(&mut hasher);+            let r = hasher.finish() % 1000;+            let y = h + 1;+            match kind {+                3 => { // warm: coral reef+                    if r < 90 {+                        let coral = 61 + ((hasher.finish() >> 8) % 5) as u8;+                        chunk.set_block(dx, y, dz, coral);+                        if r < 20 && y + 1 < Self::SEA_LEVEL { chunk.set_block(dx, y + 1, dz, coral); }+                    } else if r < 96 { chunk.set_block(dx, y, dz, 67); } // sea lantern                 }-                Biome::Plains => {-                    if surf == 3 {-                        if r == 3 { let y = h + 1; if y < CHUNK_HEIGHT { chunk.set_block(dx, y, dz, 8); } } // scattered rock-                        else if r < 12 { self.plant_tree(chunk, dx, dz, h, 4, 5, th); }                     // sparse oak+                1 | 2 => { // kelp forests+                    if r < 120 {+                        let kh = 2 + (hasher.finish() % 5) as usize;+                        for k in 0..kh { let yy = y + k; if yy < Self::SEA_LEVEL { chunk.set_block(dx, yy, dz, 66); } }                     }                 }+                _ => {}             }         }}+        // --- Small single-chunk surface structures. ---+        {+            let ax = ox + 8; let az = oz + 8;+            let sh_top = self.height_at(ax as f64, az as f64) as usize;+            let biome = self.biome_at(ax as f64, az as f64, sh_top as i32);+            let mut hasher = DefaultHasher::new();+            (chunk.pos.0, chunk.pos.1, self.seed ^ 0x57AC).hash(&mut hasher);+            let sr = hasher.finish() % 100;+            let (bx, bz) = (8usize, 8usize);+            match biome {+                Biome::Taiga | Biome::SnowyTaiga | Biome::Grove | Biome::WindsweptHills if sr < 8 => {+                    // Mossy boulder.+                    let cy = sh_top + 1;+                    for ddx in -1i32..=1 { for ddy in 0i32..=2 { for ddz in -1i32..=1 {+                        if ddx.abs() + ddy + ddz.abs() > 3 { continue; }+                        let (x, y, z) = (bx as i32 + ddx, cy as i32 + ddy, bz as i32 + ddz);+                        if x < 0 || x >= 16 || z < 0 || z >= 16 || y < 0 || y as usize >= CHUNK_HEIGHT { continue; }+                        chunk.set_block(x as usize, y as usize, z as usize, 15);+                    }}}+                }+                Biome::Desert if sr < 10 => {+                    // Desert well: 3x3 sandstone rim with a water centre.+                    let cy = sh_top;+                    for ddx in -1i32..=1 { for ddz in -1i32..=1 {+                        let (x, z) = (bx as i32 + ddx, bz as i32 + ddz);+                        if x < 0 || x >= 16 || z < 0 || z >= 16 { continue; }+                        let id = if ddx == 0 && ddz == 0 { 12 } else { 38 };+                        chunk.set_block(x as usize, cy, z as usize, id);+                    }}+                }+                _ => {}+            }+        }         chunk.generated = true;         chunk.mesh_dirty = true;     }@@ -178,10 +373,17 @@ impl TerrainGen {     pub fn ensure_water(&self, chunk: &mut Chunk) {         let (ox, oz) = chunk.pos.world_origin();         for dz in 0..CHUNK_SIZE { for dx in 0..CHUNK_SIZE {-            let h = self.height_at((ox + dx as i32) as f64, (oz + dz as i32) as f64) as usize;+            let wx = (ox + dx as i32) as f64;+            let wz = (oz + dz as i32) as f64;+            let h = self.height_at(wx, wz) as usize;             if h >= Self::SEA_LEVEL { continue; }+            // Frozen oceans get a solid ice cap at the surface instead of open water.+            let frozen = self.ocean_kind(wx, wz) == 0;             for y in (h + 1)..=Self::SEA_LEVEL {-                if y < CHUNK_HEIGHT && chunk.get_block(dx, y, dz) == 0 { chunk.set_block(dx, y, dz, 12); }+                if y < CHUNK_HEIGHT && chunk.get_block(dx, y, dz) == 0 {+                    let id = if frozen && y == Self::SEA_LEVEL { 43 } else { 12 };+                    chunk.set_block(dx, y, dz, id);+                }             }         }}     }