NorbiPeti
3929144171
# Conflicts: # GamecraftModdingAPI/Block.cs # GamecraftModdingAPI/GamecraftModdingAPI.csproj
69 lines
No EOL
1.8 KiB
C#
69 lines
No EOL
1.8 KiB
C#
using System;
|
|
using Unity.Mathematics;
|
|
|
|
namespace GamecraftModdingAPI.Blocks
|
|
{
|
|
public struct BlockColor
|
|
{
|
|
public BlockColors Color;
|
|
public byte Darkness;
|
|
public byte Index;
|
|
|
|
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);
|
|
}
|
|
|
|
Index = index;
|
|
}
|
|
|
|
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;
|
|
if (color == BlockColors.Default) Index = byte.MaxValue;
|
|
else Index = (byte) (darkness * 10 + color);
|
|
}
|
|
|
|
public float4 RGBA => Block.BlockEngine.ConvertBlockColor(Index);
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"{nameof(Color)}: {Color}, {nameof(Darkness)}: {Darkness}";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Preset block colours
|
|
/// </summary>
|
|
public enum BlockColors
|
|
{
|
|
Default = byte.MaxValue,
|
|
White = 0,
|
|
Pink,
|
|
Purple,
|
|
Blue,
|
|
Aqua,
|
|
Green,
|
|
Lime,
|
|
Yellow,
|
|
Orange,
|
|
Red
|
|
}
|
|
} |