|
@@ -0,0 +1,187 @@
|
|
|
+package me.km.blocks;
|
|
|
+
|
|
|
+import java.awt.Color;
|
|
|
+import java.util.LinkedList;
|
|
|
+import net.minecraft.item.Item;
|
|
|
+import net.minecraft.item.ItemStack;
|
|
|
+import net.minecraft.item.ItemFishFood;
|
|
|
+
|
|
|
+public class CauldronColorMixer
|
|
|
+{
|
|
|
+ public final static Color DEFAULT = new Color(47, 67, 244);
|
|
|
+
|
|
|
+ private final static Color POISON = new Color(0, 128, 43);
|
|
|
+
|
|
|
+ private final static Color PUMPKIN = new Color(197, 120, 23, 255);
|
|
|
+ private final static Color APPLE = new Color(195, 30, 38);
|
|
|
+ private final static Color APPLE_GOLDEN = new Color(164, 149, 56);
|
|
|
+ private final static Color BEEF_RAW = new Color(155, 48, 42);
|
|
|
+ private final static Color BEETROOT = new Color(144, 86, 69);
|
|
|
+ private final static Color BEETROOT_SEEDS = new Color(229, 221, 210);
|
|
|
+ //private final static Color BLAZE_POWDER = new Color(183, 100, 15);
|
|
|
+ private final static Color CARROT = new Color(144, 121, 29);
|
|
|
+ private final static Color CARROT_GOLDEN = new Color(129, 104, 26);
|
|
|
+ private final static Color CHICKEN_RAW = new Color(191, 148, 135);
|
|
|
+ private final static Color FISH_CLOWNFISH_RAW = new Color(216, 170, 143, 255);
|
|
|
+ private final static Color FISH_COD_RAW = new Color(163, 180, 180);
|
|
|
+ private final static Color FISH_SALMON_RAW = new Color(207, 188, 186, 255);
|
|
|
+ //private final static Color MAGMA_CREAM = new Color(168, 118, 55);
|
|
|
+ private final static Color MELON = new Color(155, 90, 46);
|
|
|
+ private final static Color MELON_SPECKLED = new Color(173, 114, 62);
|
|
|
+ private final static Color MUTTON_RAW = new Color(175, 60, 53);
|
|
|
+ private final static Color NETHER_WART = new Color(115, 27, 34, 255);
|
|
|
+ private final static Color PORKCHOP_RAW = new Color(202, 114, 114);
|
|
|
+ private final static Color POTATO = new Color(206, 169, 91);
|
|
|
+ private final static Color RABBIT_FOOT = new Color(169, 130, 86);
|
|
|
+ private final static Color RABBIT_RAW = new Color(213, 170, 155);
|
|
|
+ private final static Color SEEDS_MELON = new Color(57, 48, 23);
|
|
|
+ private final static Color SEEDS_PUMPKIN = new Color(201, 199, 146);
|
|
|
+ private final static Color SEEDS_WHEAT = new Color(61, 134, 27);
|
|
|
+ private final static Color SPIDER_EYE_FERMENTED = new Color(117, 44, 54);
|
|
|
+ private final static Color SUGAR = new Color(185, 185, 195);
|
|
|
+ //private final static Color WHEAT = new Color(122, 125, 36);
|
|
|
+
|
|
|
+ private LinkedList<ItemStack> items;
|
|
|
+ private LinkedList<Color> colors;
|
|
|
+ private Color cachedColor;
|
|
|
+
|
|
|
+ public CauldronColorMixer()
|
|
|
+ {
|
|
|
+ items = new LinkedList<>();
|
|
|
+ colors = new LinkedList<>();
|
|
|
+ reset();
|
|
|
+ }
|
|
|
+
|
|
|
+ public final void reset(Color c)
|
|
|
+ {
|
|
|
+ cachedColor = c;
|
|
|
+ colors.clear();
|
|
|
+ items.clear();
|
|
|
+ }
|
|
|
+
|
|
|
+ public final void reset()
|
|
|
+ {
|
|
|
+ reset(DEFAULT);
|
|
|
+ }
|
|
|
+
|
|
|
+ public LinkedList<ItemStack> getItems()
|
|
|
+ {
|
|
|
+ return items;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Color getItemColor(ItemStack stack)
|
|
|
+ {
|
|
|
+ switch(Item.getIdFromItem(stack.getItem()))
|
|
|
+ {
|
|
|
+ case 86: return PUMPKIN;
|
|
|
+ case 260: return APPLE;
|
|
|
+ case 295: return SEEDS_WHEAT;
|
|
|
+ //case 296: return WHEAT;
|
|
|
+ case 319: return PORKCHOP_RAW;
|
|
|
+ case 322: return APPLE_GOLDEN;
|
|
|
+ case 349:
|
|
|
+ switch(ItemFishFood.FishType.byItemStack(stack))
|
|
|
+ {
|
|
|
+ case CLOWNFISH:
|
|
|
+ return FISH_CLOWNFISH_RAW;
|
|
|
+ case COD:
|
|
|
+ return FISH_COD_RAW;
|
|
|
+ case PUFFERFISH:
|
|
|
+ return POISON;
|
|
|
+ case SALMON:
|
|
|
+ return FISH_SALMON_RAW;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 353: return SUGAR;
|
|
|
+ case 360: return MELON;
|
|
|
+ case 361: return SEEDS_PUMPKIN;
|
|
|
+ case 362: return SEEDS_MELON;
|
|
|
+ case 363: return BEEF_RAW;
|
|
|
+ case 365: return CHICKEN_RAW;
|
|
|
+ case 372: return NETHER_WART;
|
|
|
+ case 394: // poison potato
|
|
|
+ case 375: return POISON; // spider eye
|
|
|
+ case 376: return SPIDER_EYE_FERMENTED;
|
|
|
+ //case 377: return BLAZE_POWDER;
|
|
|
+ //case 378: return MAGMA_CREAM;
|
|
|
+ case 382: return MELON_SPECKLED;
|
|
|
+ case 391: return CARROT;
|
|
|
+ case 392: return POTATO;
|
|
|
+ case 396: return CARROT_GOLDEN;
|
|
|
+ case 411: return RABBIT_RAW;
|
|
|
+ case 414: return RABBIT_FOOT;
|
|
|
+ case 423: return MUTTON_RAW;
|
|
|
+ case 434: return BEETROOT;
|
|
|
+ case 435: return BEETROOT_SEEDS;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean addColor(ItemStack stack)
|
|
|
+ {
|
|
|
+ Color c = getItemColor(stack);
|
|
|
+ if(c == null)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ colors.add(c);
|
|
|
+ ItemStack copy = stack.copy();
|
|
|
+ copy.setCount(1);
|
|
|
+ items.add(copy);
|
|
|
+ cachedColor = mixColors();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void cache()
|
|
|
+ {
|
|
|
+ if(items.isEmpty())
|
|
|
+ {
|
|
|
+ colors.clear();
|
|
|
+ cachedColor = DEFAULT;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(colors.size() != items.size())
|
|
|
+ {
|
|
|
+ colors.clear();
|
|
|
+ Color c;
|
|
|
+ for(ItemStack stack : items)
|
|
|
+ {
|
|
|
+ c = getItemColor(stack);
|
|
|
+ if(c != null)
|
|
|
+ {
|
|
|
+ colors.add(c);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ cachedColor = mixColors();
|
|
|
+ }
|
|
|
+
|
|
|
+ public Color getMixedColor()
|
|
|
+ {
|
|
|
+ return cachedColor;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Color mixColors()
|
|
|
+ {
|
|
|
+ int alpha = 0;
|
|
|
+ int red = 0;
|
|
|
+ int green = 0;
|
|
|
+ int blue = 0;
|
|
|
+ for(Color c : colors)
|
|
|
+ {
|
|
|
+ alpha += c.getAlpha();
|
|
|
+ red += c.getRed();
|
|
|
+ green += c.getGreen();
|
|
|
+ blue += c.getBlue();
|
|
|
+ }
|
|
|
+ if(!colors.isEmpty())
|
|
|
+ {
|
|
|
+ int size = colors.size();
|
|
|
+ alpha /= size;
|
|
|
+ red /= size;
|
|
|
+ green /= size;
|
|
|
+ blue /= size;
|
|
|
+ }
|
|
|
+ return new Color(red, green, blue, alpha);
|
|
|
+ }
|
|
|
+}
|