53 lines
2.2 KiB
C#
53 lines
2.2 KiB
C#
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<byte, BlockData> Blocks = new Dictionary<byte, BlockData>();
|
|
|
|
// 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!
|
|
|
|
// 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)));
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|
|
}
|