ModTextFormatting.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package me.ktcm;
  2. import java.util.Locale;
  3. import javax.annotation.Nullable;
  4. import net.minecraftforge.api.distmarker.Dist;
  5. import net.minecraftforge.api.distmarker.OnlyIn;
  6. public enum ModTextFormatting {
  7. BLACK("BLACK", '0', 0, 0),
  8. DARK_BLUE("DARK_BLUE", '1', 1, 170),
  9. DARK_GREEN("DARK_GREEN", '2', 2, 43520),
  10. DARK_AQUA("DARK_AQUA", '3', 3, 43690),
  11. DARK_RED("DARK_RED", '4', 4, 11141120),
  12. DARK_PURPLE("DARK_PURPLE", '5', 5, 11141290),
  13. GOLD("GOLD", '6', 6, 16755200),
  14. GRAY("GRAY", '7', 7, 11184810),
  15. DARK_GRAY("DARK_GRAY", '8', 8, 5592405),
  16. BLUE("BLUE", '9', 9, 5592575),
  17. GREEN("GREEN", 'a', 10, 5635925),
  18. AQUA("AQUA", 'b', 11, 5636095),
  19. RED("RED", 'c', 12, 16733525),
  20. LIGHT_PURPLE("LIGHT_PURPLE", 'd', 13, 16733695),
  21. YELLOW("YELLOW", 'e', 14, 16777045),
  22. WHITE("WHITE", 'f', 15, 16777215),
  23. // start of new colors
  24. // http://chir.ag/projects/name-that-color/
  25. DARK_BROWN("DARK_BROWN", 'g', 16, buildColor(0.4f, 0.2f, 0.0f)),
  26. LIGHT_BROWN("LIGHT_BROWN", 'h', 17, buildColor(0.6f, 0.4f, 0.2f)),
  27. MIDNIGHT_BLUE("MIDNIGHT_BLUE", 'i', 18, buildColor(0.0f, 0.2f, 0.4f)),
  28. BAHAMA_BLUE("BAHAMA_BLUE", 'j', 19, buildColor(0.0f, 0.4f, 0.6f)),
  29. LIMEADE("LIMEADE", 'p', 20, buildColor(0.4f, 0.6f, 0.0f)),
  30. PISTACHIO("PISTACHIO", 'q', 21, buildColor(0.6f, 0.8f, 0.0f)),
  31. AZURE_RADIANCE("AZURE_RADIANCE", 's', 22, buildColor(0.0f, 0.6f, 1.0f)),
  32. MALIBU("MALIBU", 't', 23, buildColor(0.4f, 0.8f, 1.0f)),
  33. OREGON("OREGON", 'u', 24, buildColor(0.6f, 0.2f, 0.0f)),
  34. TENN("TENN", 'v', 25, buildColor(0.8f, 0.4f, 0.0f)),
  35. BUDDHA_GOLD("BUDDHA_GOLD", 'w', 26, buildColor(0.4f, 0.0f, 0.4f)),
  36. SUPERNOVA("SUPERNOVA", 'x', 27, buildColor(0.6f, 0.0f, 0.8f)),
  37. POMPADOUR("POMPADOUR", 'y', 28, buildColor(0.8f, 0.6f, 0.0f)),
  38. ELECTRIC_VIOLET("ELECTRIC_VIOLET", 'z', 29, buildColor(1.0f, 0.8f, 0.0f)),
  39. // end of new colors
  40. OBFUSCATED("OBFUSCATED", 'k', true),
  41. BOLD("BOLD", 'l', true),
  42. STRIKETHROUGH("STRIKETHROUGH", 'm', true),
  43. UNDERLINE("UNDERLINE", 'n', true),
  44. ITALIC("ITALIC", 'o', true),
  45. RESET("RESET", 'r', -1, null);
  46. private static int buildColor(float r, float g, float b) {
  47. int ir = (int) (255 * r);
  48. int ig = (int) (255 * g);
  49. int ib = (int) (255 * b);
  50. return (ir << 16) | (ig << 8) | (ib);
  51. }
  52. private final String name;
  53. private final char formattingCode;
  54. private final boolean fancyStyling;
  55. private final String controlString;
  56. private final int colorIndex;
  57. @Nullable
  58. private final Integer color;
  59. private ModTextFormatting(String formattingName, char formattingCodeIn, int index, @Nullable Integer colorCode) {
  60. this(formattingName, formattingCodeIn, false, index, colorCode);
  61. }
  62. private ModTextFormatting(String formattingName, char formattingCodeIn, boolean fancyStylingIn) {
  63. this(formattingName, formattingCodeIn, fancyStylingIn, -1, (Integer) null);
  64. }
  65. private ModTextFormatting(String formattingName, char formattingCodeIn, boolean fancyStylingIn, int index, @Nullable Integer colorCode) {
  66. this.name = formattingName;
  67. this.formattingCode = formattingCodeIn;
  68. this.fancyStyling = fancyStylingIn;
  69. this.colorIndex = index;
  70. this.color = colorCode;
  71. this.controlString = "\u00a7" + formattingCodeIn;
  72. }
  73. @Nullable
  74. @OnlyIn(Dist.CLIENT)
  75. public Integer func_211163_e() {
  76. return this.color;
  77. }
  78. @Nullable
  79. @OnlyIn(Dist.CLIENT)
  80. public Integer getColor() {
  81. return this.color;
  82. }
  83. @OnlyIn(Dist.CLIENT)
  84. public boolean func_211166_f() // isNormalStyle
  85. {
  86. return !this.fancyStyling;
  87. }
  88. @OnlyIn(Dist.CLIENT)
  89. public boolean isNormalStyle() {
  90. return !this.fancyStyling;
  91. }
  92. @Nullable
  93. @OnlyIn(Dist.CLIENT)
  94. public static ModTextFormatting fromFormattingCode(char formattingCodeIn) {
  95. return func_211165_a(formattingCodeIn);
  96. }
  97. @Nullable
  98. @OnlyIn(Dist.CLIENT)
  99. public static ModTextFormatting func_211165_a(char formattingCodeIn) {
  100. char c0 = Character.toString(formattingCodeIn).toLowerCase(Locale.ROOT).charAt(0);
  101. for(ModTextFormatting textformatting : values()) {
  102. if(textformatting.formattingCode == c0) {
  103. return textformatting;
  104. }
  105. }
  106. return null;
  107. }
  108. }