Make BlockColor.Index a property and other fixes

This commit is contained in:
Norbi Peti 2020-10-02 17:06:06 +02:00
parent abbb83da26
commit 4701b3577d
2 changed files with 6 additions and 6 deletions

View file

@ -7,7 +7,10 @@ namespace GamecraftModdingAPI.Blocks
{
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)
{
@ -23,8 +26,6 @@ namespace GamecraftModdingAPI.Blocks
Color = (BlockColors) (index % 10);
Darkness = (byte) (index / 10);
}
Index = index;
}
public BlockColor(BlockColors color, byte darkness)
@ -33,8 +34,6 @@ namespace GamecraftModdingAPI.Blocks
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);

View file

@ -31,9 +31,9 @@ namespace GamecraftModdingAPI.Blocks
set
{
if (value == null) value = "";
BlockEngine.SetBlockInfo(this, (ref TextBlockDataStruct tbds, string val) =>
{
if (val == null) val = "";
tbds.textCurrent.Set(val);
tbds.textStored.Set(val);
}, value);
@ -51,6 +51,7 @@ namespace GamecraftModdingAPI.Blocks
set
{
if (value == null) value = "";
BlockEngine.SetBlockInfo(this, (ref TextBlockDataStruct tbds, string val) =>
tbds.textBlockID.Set(val), value);
BlockEngine.SetBlockInfo(this,