Files
VoxelEngine/World/Blocks/BlockRegistry.cs

29 lines
867 B
C#

namespace VoxelEngine.World.Blocks;
public sealed class BlockRegistry
{
private readonly IBlock[] _byId;
public AirBlock Air { get; } = new();
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, this.Sand, this.Snow, this.Water };
this._byId = new IBlock[blocks.Length];
foreach (IBlock block in blocks)
{
this._byId[block.Id] = block;
}
}
public IBlock Get(ushort id) => this._byId[id];
}