package com.enderio.core.common.util;

import com.enderio.core.EnderCore;

import net.minecraft.item.ItemDye;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;

public enum DyeColor {

  BLACK,
  RED,
  GREEN,
  BROWN,
  BLUE,
  PURPLE,
  CYAN,
  SILVER,
  GRAY,
  PINK,
  LIME,
  YELLOW,
  LIGHT_BLUE,
  MAGENTA,
  ORANGE,
  WHITE;

  public static final String[] DYE_ORE_NAMES = { "dyeBlack", "dyeRed", "dyeGreen", "dyeBrown", "dyeBlue", "dyePurple", "dyeCyan", "dyeLightGray", "dyeGray",
      "dyePink", "dyeLime", "dyeYellow", "dyeLightBlue", "dyeMagenta", "dyeOrange", "dyeWhite" };

  public static final String[] DYE_ORE_UNLOCAL_NAMES = {

  "item.fireworksCharge.black", "item.fireworksCharge.red", "item.fireworksCharge.green", "item.fireworksCharge.brown", "item.fireworksCharge.blue",
      "item.fireworksCharge.purple", "item.fireworksCharge.cyan", "item.fireworksCharge.silver", "item.fireworksCharge.gray", "item.fireworksCharge.pink",
      "item.fireworksCharge.lime", "item.fireworksCharge.yellow", "item.fireworksCharge.lightBlue", "item.fireworksCharge.magenta",
      "item.fireworksCharge.orange", "item.fireworksCharge.white"

  };

  public static DyeColor getNext(DyeColor col) {
    int ord = col.ordinal() + 1;
    if (ord >= DyeColor.values().length) {
      ord = 0;
    }
    return DyeColor.values()[ord];
  }

  public static DyeColor getColorFromDye(ItemStack dye) {
    if (dye == null) {
      return null;
    }
    int oreId = OreDictionary.getOreID(dye);
    if (oreId < 0) {
      return null;
    }
    for (int i = 0; i < DYE_ORE_NAMES.length; i++) {
      String dyeName = DYE_ORE_NAMES[i];
      if (OreDictionary.getOreID(dyeName) == oreId) {
        return DyeColor.values()[i];
      }
    }
    return null;
  }

  public static DyeColor fromIndex(int index) {
    return DyeColor.values()[index];
  }

  private DyeColor() {
  }

  public int getColor() {
    return ItemDye.field_150922_c[ordinal()];
  }

  public String getName() {
    return ItemDye.field_150921_b[ordinal()];
  }

  public String getLocalisedName() {
    return EnderCore.lang.localizeExact(DYE_ORE_UNLOCAL_NAMES[ordinal()], false);
  }

  @Override
  public String toString() {
    return getName();
  }

}
@@ -1485,22 +1485,25 @@
 %0A    int
+%5B%5D
  oreI
-d
+Ds
  = OreDi
@@ -1523,61 +1523,16 @@
 reID
+s
 (dye);%0A
-    if (oreId %3C 0) %7B%0A      return null;%0A    %7D%0A
     
@@ -1590,25 +1590,43 @@
     
-Str
 in
-g
+t
  dye
-Name = 
+ID = OreDictionary.getOreID(
 DYE_
@@ -1637,24 +1637,25 @@
 NAMES%5Bi%5D
+)
 ;%0A      
 if (OreD
@@ -1650,43 +1650,52 @@
     
-if (OreDictionary.getOreID(dyeName)
+for (int oreId : oreIDs) %7B%0A        if (dyeID
  == 
@@ -1699,24 +1699,26 @@
 == oreId) %7B%0A
+  
         retu
@@ -1742,16 +1742,26 @@
 s()%5Bi%5D;%0A
+        %7D%0A
       %7D%0A

Fix for setting conduit channel color with a dye item in hand