TechbloxModdingAPI/GamecraftModdingAPI/Blocks/BlockColor.cs

64 lines
1.6 KiB
C#
Raw Normal View History

using System;
using Unity.Mathematics;
namespace GamecraftModdingAPI.Blocks
2020-01-03 00:14:26 +00:00
{
public struct BlockColor
{
public BlockColors Color;
public byte Darkness;
public byte Index => Color == BlockColors.Default
? byte.MaxValue
: (byte) (Darkness * 10 + Color);
public BlockColor(byte index)
{
if (index == byte.MaxValue)
{
Color = BlockColors.Default;
Darkness = 0;
}
else
{
if (index > 99)
throw new ArgumentOutOfRangeException(nameof(index), "Invalid color index. Must be 0-90 or 255.");
Color = (BlockColors) (index % 10);
Darkness = (byte) (index / 10);
}
}
public BlockColor(BlockColors color, byte darkness)
{
if (darkness > 9)
throw new ArgumentOutOfRangeException(nameof(darkness), "Darkness must be 0-9 where 0 is default.");
Color = color;
Darkness = darkness;
}
public float4 RGBA => Block.BlockEngine.ConvertBlockColor(Index);
public override string ToString()
{
return $"{nameof(Color)}: {Color}, {nameof(Darkness)}: {Darkness}";
}
}
2020-01-04 00:54:35 +00:00
/// <summary>
/// Preset block colours
/// </summary>
2020-01-03 00:14:26 +00:00
public enum BlockColors
{
Default = byte.MaxValue,
White = 0,
Pink,
Purple,
Blue,
Aqua,
Green,
Lime,
Yellow,
Orange,
Red
}
}