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

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