CookingPotColorMixer.java 6.3 KB

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