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.7KB

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