CookingPotColorMixer.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. package me.km.blocks.cookingpot;
  2. import java.awt.Color;
  3. import java.util.LinkedList;
  4. import net.minecraft.item.Items;
  5. import net.minecraft.item.Item;
  6. import net.minecraft.item.ItemStack;
  7. public class CookingPotColorMixer {
  8. public final static Color DEFAULT = new Color(47, 67, 244);
  9. private final static Color POISON = new Color(0, 128, 43);
  10. private final static Color PUMPKIN = new Color(197, 120, 23, 255);
  11. private final static Color APPLE = new Color(195, 30, 38);
  12. private final static Color APPLE_GOLDEN = new Color(164, 149, 56);
  13. private final static Color BEEF_RAW = new Color(155, 48, 42);
  14. private final static Color BEETROOT = new Color(144, 86, 69);
  15. private final static Color BEETROOT_SEEDS = new Color(229, 221, 210);
  16. //private final static Color BLAZE_POWDER = new Color(183, 100, 15);
  17. private final static Color CARROT = new Color(144, 121, 29);
  18. private final static Color CARROT_GOLDEN = new Color(129, 104, 26);
  19. private final static Color CHICKEN_RAW = new Color(191, 148, 135);
  20. private final static Color FISH_CLOWNFISH_RAW = new Color(216, 170, 143, 255);
  21. private final static Color FISH_COD_RAW = new Color(163, 180, 180);
  22. private final static Color FISH_SALMON_RAW = new Color(207, 188, 186, 255);
  23. //private final static Color MAGMA_CREAM = new Color(168, 118, 55);
  24. private final static Color MELON = new Color(155, 90, 46);
  25. private final static Color MELON_SPECKLED = new Color(173, 114, 62);
  26. private final static Color MUTTON_RAW = new Color(175, 60, 53);
  27. private final static Color NETHER_WART = new Color(115, 27, 34, 255);
  28. private final static Color PORKCHOP_RAW = new Color(202, 114, 114);
  29. private final static Color POTATO = new Color(206, 169, 91);
  30. private final static Color RABBIT_FOOT = new Color(169, 130, 86);
  31. private final static Color RABBIT_RAW = new Color(213, 170, 155);
  32. private final static Color SEEDS_MELON = new Color(57, 48, 23);
  33. private final static Color SEEDS_PUMPKIN = new Color(201, 199, 146);
  34. private final static Color SEEDS_WHEAT = new Color(61, 134, 27);
  35. private final static Color SPIDER_EYE_FERMENTED = new Color(117, 44, 54);
  36. private final static Color SUGAR = new Color(185, 185, 195);
  37. //private final static Color WHEAT = new Color(122, 125, 36);
  38. private final LinkedList<ItemStack> items;
  39. private final LinkedList<Color> colors;
  40. private Color cachedColor;
  41. public CookingPotColorMixer() {
  42. items = new LinkedList<>();
  43. colors = new LinkedList<>();
  44. reset();
  45. }
  46. public final void reset(Color c) {
  47. cachedColor = c;
  48. colors.clear();
  49. items.clear();
  50. }
  51. public final void reset() {
  52. reset(DEFAULT);
  53. }
  54. public LinkedList<ItemStack> getItems() {
  55. return items;
  56. }
  57. public Color getItemColor(ItemStack stack) {
  58. Item item = stack.getItem();
  59. if(item == Items.PUMPKIN) {
  60. return PUMPKIN;
  61. } else if(item == Items.APPLE) {
  62. return APPLE;
  63. } else if(item == Items.GOLDEN_APPLE) {
  64. return APPLE_GOLDEN;
  65. } else if(item == Items.BEETROOT_SEEDS) {
  66. return BEETROOT_SEEDS;
  67. } else if(item == Items.MELON_SEEDS) {
  68. return SEEDS_MELON;
  69. } else if(item == Items.PUMPKIN_SEEDS) {
  70. return SEEDS_PUMPKIN;
  71. } else if(item == Items.WHEAT_SEEDS) {
  72. return SEEDS_WHEAT;
  73. } else if(item == Items.PORKCHOP) {
  74. return PORKCHOP_RAW;
  75. } else if(item == Items.BEEF) {
  76. return BEEF_RAW;
  77. } else if(item == Items.TROPICAL_FISH) {
  78. return FISH_CLOWNFISH_RAW;
  79. } else if(item == Items.COD) {
  80. return FISH_COD_RAW;
  81. } else if(item == Items.PUFFERFISH) {
  82. return POISON;
  83. } else if(item == Items.SALMON) {
  84. return FISH_SALMON_RAW;
  85. } else if(item == Items.SUGAR) {
  86. return SUGAR;
  87. } else if(item == Items.MELON_SLICE) {
  88. return MELON;
  89. } else if(item == Items.GLISTERING_MELON_SLICE) {
  90. return MELON_SPECKLED;
  91. } else if(item == Items.CHICKEN) {
  92. return CHICKEN_RAW;
  93. } else if(item == Items.SPIDER_EYE) {
  94. return POISON;
  95. } else if(item == Items.POISONOUS_POTATO) {
  96. return POISON;
  97. } else if(item == Items.RABBIT_FOOT) {
  98. return RABBIT_FOOT;
  99. } else if(item == Items.NETHER_WART) {
  100. return NETHER_WART;
  101. } else if(item == Items.FERMENTED_SPIDER_EYE) {
  102. return SPIDER_EYE_FERMENTED;
  103. } else if(item == Items.GOLDEN_CARROT) {
  104. return CARROT_GOLDEN;
  105. } else if(item == Items.CARROT) {
  106. return CARROT;
  107. } else if(item == Items.RABBIT) {
  108. return RABBIT_RAW;
  109. } else if(item == Items.POTATO) {
  110. return POTATO;
  111. } else if(item == Items.MUTTON) {
  112. return MUTTON_RAW;
  113. } else if(item == Items.BEETROOT) {
  114. return BEETROOT;
  115. }
  116. return null;
  117. }
  118. public void addColor(ItemStack stack, Color c) {
  119. colors.add(c);
  120. ItemStack copy = stack.copy();
  121. copy.setCount(1);
  122. items.add(copy);
  123. cachedColor = mixColors();
  124. }
  125. public void cache() {
  126. if(items.isEmpty()) {
  127. colors.clear();
  128. cachedColor = DEFAULT;
  129. return;
  130. }
  131. if(colors.size() != items.size()) {
  132. colors.clear();
  133. Color c;
  134. for(ItemStack stack : items) {
  135. c = getItemColor(stack);
  136. if(c != null) {
  137. colors.add(c);
  138. }
  139. }
  140. }
  141. cachedColor = mixColors();
  142. }
  143. public Color getMixedColor() {
  144. return cachedColor;
  145. }
  146. private Color mixColors() {
  147. int alpha = 0;
  148. int red = 0;
  149. int green = 0;
  150. int blue = 0;
  151. for(Color c : colors) {
  152. alpha += c.getAlpha();
  153. red += c.getRed();
  154. green += c.getGreen();
  155. blue += c.getBlue();
  156. }
  157. if(!colors.isEmpty()) {
  158. int size = colors.size();
  159. alpha /= size;
  160. red /= size;
  161. green /= size;
  162. blue /= size;
  163. }
  164. return new Color(red, green, blue, alpha);
  165. }
  166. }