feat(blocks): add ore block scaffolding (Coal, Iron, Gold, Diamond)
This commit is contained in:
@@ -71,4 +71,36 @@ public class BlockRegistryTests
|
||||
Assert.Equal("Snow Block", registry.Get(5).Name);
|
||||
Assert.Equal("Water", registry.Get(6).Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Registry_ResolvesOreBlocks_ByStableIds()
|
||||
{
|
||||
var registry = new BlockRegistry();
|
||||
|
||||
Assert.Equal("Coal Ore", registry.Get(7).Name);
|
||||
Assert.Equal("Iron Ore", registry.Get(8).Name);
|
||||
Assert.Equal("Gold Ore", registry.Get(9).Name);
|
||||
Assert.Equal("Diamond Ore", registry.Get(10).Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Ores_AreOpaqueAndSolid()
|
||||
{
|
||||
var registry = new BlockRegistry();
|
||||
foreach (ushort id in new ushort[] { 7, 8, 9, 10 })
|
||||
{
|
||||
Assert.True(registry.Get(id).IsOpaque, $"ore id {id} should be opaque");
|
||||
Assert.True(registry.Get(id).IsSolid, $"ore id {id} should be solid");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NamedOreAccessors_MatchIds()
|
||||
{
|
||||
var registry = new BlockRegistry();
|
||||
Assert.Equal((ushort)7, registry.CoalOre.Id);
|
||||
Assert.Equal((ushort)8, registry.IronOre.Id);
|
||||
Assert.Equal((ushort)9, registry.GoldOre.Id);
|
||||
Assert.Equal((ushort)10, registry.DiamondOre.Id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,12 +11,18 @@ public sealed class BlockRegistry
|
||||
public SandBlock Sand { get; } = new();
|
||||
public SnowBlock Snow { get; } = new();
|
||||
public WaterBlock Water { get; } = new();
|
||||
public CoalOreBlock CoalOre { get; } = new();
|
||||
public IronOreBlock IronOre { get; } = new();
|
||||
public GoldOreBlock GoldOre { get; } = new();
|
||||
public DiamondOreBlock DiamondOre { 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, this.Sand, this.Snow, this.Water };
|
||||
{
|
||||
this.Air, this.Stone, this.Dirt, this.Grass, this.Sand, this.Snow, this.Water,
|
||||
this.CoalOre, this.IronOre, this.GoldOre, this.DiamondOre,
|
||||
};
|
||||
this._byId = new IBlock[blocks.Length];
|
||||
foreach (IBlock block in blocks)
|
||||
{
|
||||
|
||||
10
World/Blocks/CoalOreBlock.cs
Normal file
10
World/Blocks/CoalOreBlock.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace VoxelEngine.World.Blocks;
|
||||
|
||||
public sealed class CoalOreBlock : IBlock
|
||||
{
|
||||
public ushort Id => 7;
|
||||
public string Name => "Coal Ore";
|
||||
public bool IsOpaque => true;
|
||||
public bool IsSolid => true;
|
||||
public TileCoord GetTextureTile(BlockFace face) => new(0, 0); // placeholder
|
||||
}
|
||||
10
World/Blocks/DiamondOreBlock.cs
Normal file
10
World/Blocks/DiamondOreBlock.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace VoxelEngine.World.Blocks;
|
||||
|
||||
public sealed class DiamondOreBlock : IBlock
|
||||
{
|
||||
public ushort Id => 10;
|
||||
public string Name => "Diamond Ore";
|
||||
public bool IsOpaque => true;
|
||||
public bool IsSolid => true;
|
||||
public TileCoord GetTextureTile(BlockFace face) => new(0, 0); // placeholder
|
||||
}
|
||||
10
World/Blocks/GoldOreBlock.cs
Normal file
10
World/Blocks/GoldOreBlock.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace VoxelEngine.World.Blocks;
|
||||
|
||||
public sealed class GoldOreBlock : IBlock
|
||||
{
|
||||
public ushort Id => 9;
|
||||
public string Name => "Gold Ore";
|
||||
public bool IsOpaque => true;
|
||||
public bool IsSolid => true;
|
||||
public TileCoord GetTextureTile(BlockFace face) => new(0, 0); // placeholder
|
||||
}
|
||||
10
World/Blocks/IronOreBlock.cs
Normal file
10
World/Blocks/IronOreBlock.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace VoxelEngine.World.Blocks;
|
||||
|
||||
public sealed class IronOreBlock : IBlock
|
||||
{
|
||||
public ushort Id => 8;
|
||||
public string Name => "Iron Ore";
|
||||
public bool IsOpaque => true;
|
||||
public bool IsSolid => true;
|
||||
public TileCoord GetTextureTile(BlockFace face) => new(0, 0); // placeholder
|
||||
}
|
||||
Reference in New Issue
Block a user