diff --git a/src/main/java/resonantinduction/ClientProxy.java b/src/main/java/resonantinduction/ClientProxy.java index 81218e31..aebbf439 100644 --- a/src/main/java/resonantinduction/ClientProxy.java +++ b/src/main/java/resonantinduction/ClientProxy.java @@ -50,7 +50,6 @@ public class ClientProxy extends CommonProxy @Override public void postInit() { - ItemDust.computeColors(); } @Override diff --git a/src/main/java/resonantinduction/ResonantInduction.java b/src/main/java/resonantinduction/ResonantInduction.java index 937502db..e5ad73a4 100644 --- a/src/main/java/resonantinduction/ResonantInduction.java +++ b/src/main/java/resonantinduction/ResonantInduction.java @@ -326,7 +326,7 @@ public class ResonantInduction } /** Auto-gen dusts */ - ItemDust.postInit(); + ItemDust.generateDusts(); ResonantInduction.proxy.postInit(); /** Inject new furnace tile class */ diff --git a/src/main/java/resonantinduction/api/MachineRecipes.java b/src/main/java/resonantinduction/api/MachineRecipes.java index 0804d913..5adba3ef 100644 --- a/src/main/java/resonantinduction/api/MachineRecipes.java +++ b/src/main/java/resonantinduction/api/MachineRecipes.java @@ -1,68 +1,65 @@ package resonantinduction.api; import java.util.HashMap; -import java.util.List; import java.util.Map; import net.minecraft.item.ItemStack; - -import resonantinduction.api.RecipeUtils.*; +import resonantinduction.api.RecipeUtils.ItemStackResource; +import resonantinduction.api.RecipeUtils.OreDictResource; +import resonantinduction.api.RecipeUtils.Resource; public final class MachineRecipes { - public static enum RecipeType - { - GRINDER, - SAWMILL, - SMELTER, - FURNACE, - ROLLER, - BLAST_FURNACE, - METAL_FORMER; - } - - private final Map> recipes = new HashMap>(); - - public static final MachineRecipes INSTANCE = new MachineRecipes(); - - private MachineRecipes() - { - for (RecipeType machine : RecipeType.values()) - { - this.recipes.put(machine, new HashMap()); - } - } - - public void addRecipe(RecipeType machine, Resource[] input, Resource[] output) - { - this.recipes.get(machine).put(input, output); - } - - public void removeRecipe(RecipeType machine, Resource[] input) - { - this.recipes.get(machine).remove(input); - } - - public MapgetRecipes(RecipeType machine) - { - return new HashMap(this.recipes.get(machine)); - } - - public Map> getRecipes() - { - return new HashMap>(this.recipes); - } - - public Resource[] getRecipe(RecipeType machine, ItemStack primary, ItemStack... secondary) - { - Resource[] input = new Resource[secondary.length +1]; - input[0] = new ItemStackResource(primary); - for (int i = 0; i < secondary.length; i++) - { - input[i+1] = new ItemStackResource(secondary[i]); - } - - return this.getRecipes(machine).get(input); - } + public static enum RecipeType + { + GRINDER, SAWMILL, SMELTER, FURNACE, ROLLER, BLAST_FURNACE, METAL_FORMER; + } + + private final Map> recipes = new HashMap>(); + + public static final MachineRecipes INSTANCE = new MachineRecipes(); + + private MachineRecipes() + { + for (RecipeType machine : RecipeType.values()) + { + this.recipes.put(machine, new HashMap()); + } + } + + public void addRecipe(RecipeType machine, Resource[] input, Resource[] output) + { + this.recipes.get(machine).put(input, output); + } + + public void addRecipe(RecipeType machine, ItemStack input, ItemStack output) + { + this.addRecipe(machine, new ItemStackResource[] { new ItemStackResource(input) }, new ItemStackResource[] { new ItemStackResource(output) }); + } + + public void addRecipe(RecipeType machine, String input, ItemStack output) + { + this.addRecipe(machine, new OreDictResource[] { new OreDictResource(input) }, new ItemStackResource[] { new ItemStackResource(output) }); + } + + public void removeRecipe(RecipeType machine, Resource[] input) + { + this.recipes.get(machine).remove(input); + } + + public Map getRecipes(RecipeType machine) + { + return new HashMap(this.recipes.get(machine)); + } + + public Map> getRecipes() + { + return new HashMap>(this.recipes); + } + + public Resource[] getRecipe(RecipeType machine, ItemStack... inputs) + { + return this.getRecipes(machine).get(inputs); + } } diff --git a/src/main/java/resonantinduction/api/RecipeUtils.java b/src/main/java/resonantinduction/api/RecipeUtils.java index fe3699a8..088c0b55 100644 --- a/src/main/java/resonantinduction/api/RecipeUtils.java +++ b/src/main/java/resonantinduction/api/RecipeUtils.java @@ -6,121 +6,100 @@ import net.minecraftforge.oredict.OreDictionary; public class RecipeUtils { - public static abstract class Resource - { - public final boolean hasChance; - public final float chance; - - protected Resource() - { - this.hasChance = false; - this.chance = 100; - } - - protected Resource(float chance) - { - this.hasChance = true; - this.chance = chance; - } - - public abstract boolean isEqual(ItemStack is); - public abstract boolean isEqual(FluidStack fs); - - public boolean hasChance() - { - return this.hasChance; - } + public static abstract class Resource + { + public final boolean hasChance; + public final float chance; - public float getChance() - { - return this.chance; - } - } - - public static class ItemStackResource extends Resource - { - public final ItemStack itemStack; + protected Resource() + { + this.hasChance = false; + this.chance = 100; + } - public ItemStackResource(ItemStack is) - { - super(); - this.itemStack = is; - } - - public ItemStackResource(ItemStack is, float chance) - { - super(chance); - this.itemStack = is; - } + protected Resource(float chance) + { + this.hasChance = true; + this.chance = chance; + } - @Override - public boolean isEqual(ItemStack is) - { - return is.equals(this.itemStack); - } + public boolean hasChance() + { + return this.hasChance; + } - @Override - public boolean isEqual(FluidStack fs) - { - return false; - } - } - - public static class OreDictResource extends Resource - { - public final String name; + public float getChance() + { + return this.chance; + } + } - public OreDictResource(String s) - { - super(); - this.name = s; - } - - public OreDictResource(String s, float chance) - { - super(chance); - this.name = s; - } + public static class ItemStackResource extends Resource + { + public final ItemStack itemStack; - @Override - public boolean isEqual(ItemStack is) - { - return OreDictionary.getOres(this.name).contains(is); - } + public ItemStackResource(ItemStack is) + { + super(); + this.itemStack = is; + } - @Override - public boolean isEqual(FluidStack fs) - { - return false; - } - } - - public static class FluidStackResource extends Resource - { - public final FluidStack fluidStack; + public ItemStackResource(ItemStack is, float chance) + { + super(chance); + this.itemStack = is; + } - public FluidStackResource(FluidStack fs) - { - super(); - this.fluidStack = fs; - } - - public FluidStackResource(FluidStack fs, float chance) - { - super(chance); - this.fluidStack = fs; - } - - @Override - public boolean isEqual(ItemStack is) - { - return false; - } + @Override + public boolean equals(Object obj) + { + return (obj instanceof ItemStack) ? ((ItemStack) obj).equals(this.itemStack) : false; + } + } - @Override - public boolean isEqual(FluidStack fs) - { - return fs.isFluidEqual(this.fluidStack); - } - } + public static class OreDictResource extends Resource + { + public final String name; + + public OreDictResource(String s) + { + super(); + this.name = s; + } + + public OreDictResource(String s, float chance) + { + super(chance); + this.name = s; + } + + @Override + public boolean equals(Object obj) + { + return (obj instanceof ItemStack) ? OreDictionary.getOres(this.name).contains(((ItemStack) obj)) : false; + } + } + + public static class FluidStackResource extends Resource + { + public final FluidStack fluidStack; + + public FluidStackResource(FluidStack fs) + { + super(); + this.fluidStack = fs; + } + + public FluidStackResource(FluidStack fs, float chance) + { + super(chance); + this.fluidStack = fs; + } + + @Override + public boolean equals(Object obj) + { + return (obj instanceof FluidStack) ? ((FluidStack) obj).equals(obj) : false; + } + } } diff --git a/src/main/java/resonantinduction/machine/grinder/ItemDust.java b/src/main/java/resonantinduction/machine/grinder/ItemDust.java index 0e39a0e7..f234f45c 100644 --- a/src/main/java/resonantinduction/machine/grinder/ItemDust.java +++ b/src/main/java/resonantinduction/machine/grinder/ItemDust.java @@ -24,6 +24,8 @@ import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary.OreRegisterEvent; import resonantinduction.ResonantInduction; +import resonantinduction.api.MachineRecipes; +import resonantinduction.api.MachineRecipes.RecipeType; import resonantinduction.api.OreDetectionBlackList; import resonantinduction.core.base.ItemBase; import calclavia.lib.Calclavia; @@ -40,7 +42,7 @@ import cpw.mods.fml.relauncher.SideOnly; */ public class ItemDust extends ItemBase { - public static final Set ingotNames = new HashSet(); + public static final Set materialNames = new HashSet(); public static final Set dusts = new HashSet(); public static final HashMap ingotColors = new HashMap(); @@ -66,11 +68,11 @@ public class ItemDust extends ItemBase if (evt.Name.startsWith("ingot")) { String ingotName = evt.Name.replace("ingot", ""); - + if (OreDetectionBlackList.isIngotBlackListed("ingot" + ingotName) || OreDetectionBlackList.isOreBlackListed("ore" + ingotName)) return; - - ingotNames.add(ingotName.toLowerCase()); + + materialNames.add(ingotName.toLowerCase()); } } @@ -81,16 +83,23 @@ public class ItemDust extends ItemBase computeColors(); } - public static void postInit() - { - for (String ingotName : ingotNames) + public static void generateDusts() + { + for (String materialName : materialNames) { - String name = ingotName.substring(0, 1).toUpperCase() + ingotName.substring(1); - - if (OreDictionary.getOres("dust" + name).size() == 0 && OreDictionary.getOres("ore" + name).size() > 0) + String name = materialName.substring(0, 1).toUpperCase() + materialName.substring(1); + + if (OreDictionary.getOres("ore" + name).size() > 0) { - dusts.add(getStackFromDust(ingotName)); - OreDictionary.registerOre("dust" + name, getStackFromDust(ingotName)); + if (OreDictionary.getOres("dust" + name).size() == 0) + { + dusts.add(getStackFromDust(materialName)); + OreDictionary.registerOre("dust" + name, getStackFromDust(materialName)); + + } + + // Add to machine recipes + MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER, "ore" + name, OreDictionary.getOres("dust" + name).get(0)); } } } @@ -98,7 +107,7 @@ public class ItemDust extends ItemBase @SideOnly(Side.CLIENT) public static void computeColors() { - for (String ingotName : ingotNames) + for (String ingotName : materialNames) { LinkedList colorCodes = new LinkedList(); @@ -114,14 +123,14 @@ public class ItemDust extends ItemBase Method o = ReflectionHelper.findMethod(Item.class, theIngot, new String[] { "getIconString", "func_" + "111208_A" }); String iconString; - + try { iconString = (String) o.invoke(theIngot); } catch (ReflectiveOperationException e1) { - //e1.printStackTrace(); + // e1.printStackTrace(); break; } @@ -146,7 +155,7 @@ public class ItemDust extends ItemBase } catch (IOException e) { - //e.printStackTrace(); + // e.printStackTrace(); } } if (colorCodes.size() > 0) diff --git a/src/main/java/resonantinduction/machine/grinder/TileGrinderWheel.java b/src/main/java/resonantinduction/machine/grinder/TileGrinderWheel.java index 42fdcd32..7b427b2f 100644 --- a/src/main/java/resonantinduction/machine/grinder/TileGrinderWheel.java +++ b/src/main/java/resonantinduction/machine/grinder/TileGrinderWheel.java @@ -59,7 +59,7 @@ public class TileGrinderWheel extends TileElectrical } public boolean canGrind(ItemStack itemStack) - { + {System.out.println(MachineRecipes.INSTANCE.getRecipe(RecipeType.GRINDER, itemStack)); return MachineRecipes.INSTANCE.getRecipe(RecipeType.GRINDER, itemStack) == null ? false : MachineRecipes.INSTANCE.getRecipe(RecipeType.GRINDER, itemStack).length > 0; }