ModTextFormatting.java 4.4 KB

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