using Godot; using System.Collections.Generic; namespace IslaApocalypse.Core { public static class BlockRegistry { // A dictionary holding all the block types in the game, searchable by their byte ID public static readonly Dictionary Blocks = new Dictionary(); // Hardcoded IDs for easy reference in code public const byte AIR = 0; public const byte BEDROCK = 1; public const byte STONE = 2; public const byte DIRT = 3; public const byte SAND = 4; public const byte GRASS_TROPICAL = 5; public const byte GRASS_JUNGLE = 6; public const byte GRASS_PARADISE = 7; public const byte SNOW = 8; public const byte WASTELAND_DIRT = 9; public const byte ASPHALT = 10; // For our roads! // Water (terrain-water task 13). Wire-safe to add: block IDs are NEVER // serialized — the blueprint's section table (BLUEPRINT_FORMAT.md) stores // heights, biome ordinals and water data, never block IDs, and chunks are // not persisted yet. So this ID is a runtime-only value and appending to // the table cannot invalidate a .dat. // // NOTE this block is not placed into ChunkData.BlockIDs by the terrain // path. Terrain is a Marching-Cubes iso-surface over a density field, and // writing WATER into that field would FUSE the water into the terrain // surface rather than lay a sheet on top of it. Water is its own mesh // (ChunkRenderer). The entry exists so water has a real identity in the // registry — a name and a colour — for the renderer and for whatever // later needs to ask "what is this". public const byte WATER = 11; // This static constructor runs automatically the first time the registry is accessed static BlockRegistry() { // ID 0 is ALWAYS Air in voxel engines. Blocks.Add(AIR, new BlockData(AIR, "Air", false, Colors.Transparent)); // The Foundation Blocks Blocks.Add(BEDROCK, new BlockData(BEDROCK, "Bedrock", true, new Color(0.1f, 0.1f, 0.1f))); Blocks.Add(STONE, new BlockData(STONE, "Stone", true, new Color(0.5f, 0.5f, 0.5f))); Blocks.Add(DIRT, new BlockData(DIRT, "Dirt", true, new Color(0.4f, 0.3f, 0.2f))); Blocks.Add(SAND, new BlockData(SAND, "Sand", true, new Color(0.8f, 0.7f, 0.4f))); // The Biome Surface Blocks Blocks.Add(GRASS_TROPICAL, new BlockData(GRASS_TROPICAL, "Tropical Grass", true, new Color(0.2f, 0.6f, 0.2f))); Blocks.Add(GRASS_JUNGLE, new BlockData(GRASS_JUNGLE, "Jungle Grass", true, new Color(0.1f, 0.4f, 0.1f))); Blocks.Add(GRASS_PARADISE, new BlockData(GRASS_PARADISE, "Paradise Grass", true, new Color(0.4f, 0.8f, 0.4f))); Blocks.Add(SNOW, new BlockData(SNOW, "Snow", true, new Color(0.9f, 0.9f, 0.9f))); Blocks.Add(WASTELAND_DIRT, new BlockData(WASTELAND_DIRT, "Wasteland Dirt", true, new Color(0.5f, 0.2f, 0.5f))); // Infrastructure Blocks.Add(ASPHALT, new BlockData(ASPHALT, "Asphalt", true, new Color(0.15f, 0.15f, 0.15f))); // Water — not solid (you can move through it), shallow-water colour as the // registry's representative value; the renderer shades by depth from there. Blocks.Add(WATER, new BlockData(WATER, "Water", false, new Color(0.24f, 0.55f, 0.62f))); } public static BlockData GetBlock(byte id) { if (Blocks.TryGetValue(id, out BlockData data)) return data; return Blocks[AIR]; // Safe fallback so the game doesn't crash if an ID is missing } } }