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.

64 lines
1.6KB

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