diff --git a/VoxelEngine.Tests/BlockRegistryTests.cs b/VoxelEngine.Tests/BlockRegistryTests.cs index 612993a..4217cca 100644 --- a/VoxelEngine.Tests/BlockRegistryTests.cs +++ b/VoxelEngine.Tests/BlockRegistryTests.cs @@ -49,4 +49,26 @@ public class BlockRegistryTests Assert.Equal((ushort)2, registry.Dirt.Id); Assert.Equal((ushort)3, registry.Grass.Id); } + + [Fact] + public void SandAndSnow_AreOpaque_WaterIsOpaque() + { + var registry = new BlockRegistry(); + Assert.True(registry.Get(4).IsOpaque); // Sand + Assert.True(registry.Get(5).IsOpaque); // Snow + Assert.True(registry.Get(6).IsOpaque); // Water (single-pass renderer => opaque) + } + + [Fact] + public void Registry_ResolvesAllSevenBlocks() + { + var registry = new BlockRegistry(); + Assert.Equal("Air", registry.Get(0).Name); + Assert.Equal("Stone", registry.Get(1).Name); + Assert.Equal("Dirt", registry.Get(2).Name); + Assert.Equal("Grass", registry.Get(3).Name); + Assert.Equal("Sand", registry.Get(4).Name); + Assert.Equal("Snow Block", registry.Get(5).Name); + Assert.Equal("Water", registry.Get(6).Name); + } } diff --git a/World/Blocks/BlockIds.txt b/World/Blocks/BlockIds.txt new file mode 100644 index 0000000..e69de29 diff --git a/World/Blocks/BlockRegistry.cs b/World/Blocks/BlockRegistry.cs index 69e9905..40b3b31 100644 --- a/World/Blocks/BlockRegistry.cs +++ b/World/Blocks/BlockRegistry.cs @@ -8,11 +8,15 @@ public sealed class BlockRegistry public StoneBlock Stone { get; } = new(); public DirtBlock Dirt { get; } = new(); public GrassBlock Grass { get; } = new(); + public SandBlock Sand { get; } = new(); + public SnowBlock Snow { get; } = new(); + public WaterBlock Water { get; } = new(); public BlockRegistry() { // Index by id. Order does not matter; slot = block.Id. - IBlock[] blocks = new IBlock[] { this.Air, this.Stone, this.Dirt, this.Grass }; + IBlock[] blocks = new IBlock[] + { this.Air, this.Stone, this.Dirt, this.Grass, this.Sand, this.Snow, this.Water }; this._byId = new IBlock[blocks.Length]; foreach (IBlock block in blocks) { diff --git a/World/Blocks/SandBlock.cs b/World/Blocks/SandBlock.cs new file mode 100644 index 0000000..b46a607 --- /dev/null +++ b/World/Blocks/SandBlock.cs @@ -0,0 +1,10 @@ +namespace VoxelEngine.World.Blocks; + +public class SandBlock : IBlock +{ + public ushort Id => 4; + public string Name => "Sand"; + public bool IsOpaque => true; + public bool IsSolid => true; + public TileCoord GetTextureTile(BlockFace face) => new(2, 1); +} \ No newline at end of file diff --git a/World/Blocks/SnowBlock.cs b/World/Blocks/SnowBlock.cs new file mode 100644 index 0000000..eccbf49 --- /dev/null +++ b/World/Blocks/SnowBlock.cs @@ -0,0 +1,16 @@ +namespace VoxelEngine.World.Blocks; + +public class SnowBlock : IBlock +{ + public ushort Id => 5; + public string Name => "Snow Block"; + public bool IsOpaque => true; + public bool IsSolid => true; + + public TileCoord GetTextureTile(BlockFace face) => face switch + { + BlockFace.Top => new TileCoord(2, 0), + BlockFace.Bottom => new TileCoord(0, 0), + _ => new TileCoord(3, 0) + }; +} \ No newline at end of file diff --git a/World/Blocks/WaterBlock.cs b/World/Blocks/WaterBlock.cs new file mode 100644 index 0000000..e6e4cdf --- /dev/null +++ b/World/Blocks/WaterBlock.cs @@ -0,0 +1,6 @@ +namespace VoxelEngine.World.Blocks; + +public class WaterBlock +{ + +} \ No newline at end of file