27 lines
713 B
C#
27 lines
713 B
C#
using VoxelEngine.World.Blocks;
|
|
|
|
namespace VoxelEngine.World;
|
|
|
|
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 BlockRegistry()
|
|
{
|
|
// Index by id. Order does not matter; slot = block.Id.
|
|
IBlock[] blocks = new IBlock[] { this.Air, this.Stone, this.Dirt, this.Grass };
|
|
this._byId = new IBlock[blocks.Length];
|
|
foreach (IBlock block in blocks)
|
|
{
|
|
this._byId[block.Id] = block;
|
|
}
|
|
}
|
|
|
|
public IBlock Get(ushort id) => this._byId[id];
|
|
}
|