A stable modding interface between Techblox and mods https://mod.exmods.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BlockColor.cs 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using Unity.Mathematics;
  3. namespace GamecraftModdingAPI.Blocks
  4. {
  5. public struct BlockColor
  6. {
  7. public BlockColors Color;
  8. public byte Darkness;
  9. public byte Index;
  10. public BlockColor(byte index)
  11. {
  12. if (index == byte.MaxValue)
  13. {
  14. Color = BlockColors.Default;
  15. Darkness = 0;
  16. }
  17. else
  18. {
  19. if (index > 99)
  20. throw new ArgumentOutOfRangeException(nameof(index), "Invalid color index. Must be 0-90 or 255.");
  21. Color = (BlockColors) (index % 10);
  22. Darkness = (byte) (index / 10);
  23. }
  24. Index = index;
  25. }
  26. public BlockColor(BlockColors color, byte darkness)
  27. {
  28. if (darkness > 9)
  29. throw new ArgumentOutOfRangeException(nameof(darkness), "Darkness must be 0-9 where 0 is default.");
  30. Color = color;
  31. Darkness = darkness;
  32. if (color == BlockColors.Default) Index = byte.MaxValue;
  33. else Index = (byte) (darkness * 10 + color);
  34. }
  35. public float4 RGBA => Block.BlockEngine.ConvertBlockColor(Index);
  36. public override string ToString()
  37. {
  38. return $"{nameof(Color)}: {Color}, {nameof(Darkness)}: {Darkness}";
  39. }
  40. }
  41. /// <summary>
  42. /// Preset block colours
  43. /// </summary>
  44. public enum BlockColors
  45. {
  46. Default = byte.MaxValue,
  47. White = 0,
  48. Pink,
  49. Purple,
  50. Blue,
  51. Aqua,
  52. Green,
  53. Lime,
  54. Yellow,
  55. Orange,
  56. Red
  57. }
  58. }