diff --git a/common/buildcraft/BuildCraftTransport.java b/common/buildcraft/BuildCraftTransport.java index 309cd3fe..94b33b1a 100644 --- a/common/buildcraft/BuildCraftTransport.java +++ b/common/buildcraft/BuildCraftTransport.java @@ -313,32 +313,24 @@ public class BuildCraftTransport { redPipeWire.setUnlocalizedName("redPipeWire"); LanguageRegistry.addName(redPipeWire, "Red Pipe Wire"); CoreProxy.proxy.registerItem(redPipeWire); - AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[]{new ItemStack(Item.dyePowder, 1, 1), new ItemStack(Item.redstone, 1), - new ItemStack(Item.ingotIron, 1)}, 500, new ItemStack(redPipeWire, 8))); Property bluePipeWireId = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_ITEM, "bluePipeWire.id", DefaultProps.BLUE_PIPE_WIRE); bluePipeWire = new ItemBuildCraft(bluePipeWireId.getInt()).setPassSneakClick(true); bluePipeWire.setUnlocalizedName("bluePipeWire"); LanguageRegistry.addName(bluePipeWire, "Blue Pipe Wire"); CoreProxy.proxy.registerItem(bluePipeWire); - AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[]{new ItemStack(Item.dyePowder, 1, 4), new ItemStack(Item.redstone, 1), - new ItemStack(Item.ingotIron, 1)}, 500, new ItemStack(bluePipeWire, 8))); Property greenPipeWireId = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_ITEM, "greenPipeWire.id", DefaultProps.GREEN_PIPE_WIRE); greenPipeWire = new ItemBuildCraft(greenPipeWireId.getInt()).setPassSneakClick(true); greenPipeWire.setUnlocalizedName("greenPipeWire"); LanguageRegistry.addName(greenPipeWire, "Green Pipe Wire"); CoreProxy.proxy.registerItem(greenPipeWire); - AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[]{new ItemStack(Item.dyePowder, 1, 2), new ItemStack(Item.redstone, 1), - new ItemStack(Item.ingotIron, 1)}, 500, new ItemStack(greenPipeWire, 8))); Property yellowPipeWireId = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_ITEM, "yellowPipeWire.id", DefaultProps.YELLOW_PIPE_WIRE); yellowPipeWire = new ItemBuildCraft(yellowPipeWireId.getInt()).setPassSneakClick(true); yellowPipeWire.setUnlocalizedName("yellowPipeWire"); LanguageRegistry.addName(yellowPipeWire, "Yellow Pipe Wire"); CoreProxy.proxy.registerItem(yellowPipeWire); - AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[]{new ItemStack(Item.dyePowder, 1, 11), new ItemStack(Item.redstone, 1), - new ItemStack(Item.ingotIron, 1)}, 500, new ItemStack(yellowPipeWire, 8))); Property pipeGateId = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_ITEM, "pipeGate.id", DefaultProps.GATE_ID); pipeGate = new ItemGate(pipeGateId.getInt(), 0); @@ -365,9 +357,6 @@ public class BuildCraftTransport { filteredBufferBlock = new BlockFilteredBuffer(filteredBufferId.getInt()); CoreProxy.proxy.registerBlock(filteredBufferBlock.setUnlocalizedName("filteredBufferBlock")); CoreProxy.proxy.addName(filteredBufferBlock, "Filtered Buffer"); - - AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[]{new ItemStack(pipeStructureCobblestone)}, 1000, new ItemStack(plugItem, 8))); - } finally { BuildCraftCore.mainConfiguration.save(); } @@ -449,6 +438,17 @@ public class BuildCraftTransport { //Facade turning helper GameRegistry.addRecipe(facadeItem.new FacadeRecipe()); + + // Assembly table recipes, moved from PreInit phase to Init, all mods should be done adding to the OreDictionary by now + AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new Object[]{"dyeRed", 1, new ItemStack(Item.redstone, 1), + new ItemStack(Item.ingotIron, 1)}, 500, new ItemStack(redPipeWire, 8))); + AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new Object[]{"dyeBlue", 1, new ItemStack(Item.redstone, 1), + new ItemStack(Item.ingotIron, 1)}, 500, new ItemStack(bluePipeWire, 8))); + AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new Object[]{"dyeGreen", 1, new ItemStack(Item.redstone, 1), + new ItemStack(Item.ingotIron, 1)}, 500, new ItemStack(greenPipeWire, 8))); + AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new Object[]{"dyeYellow", 1, new ItemStack(Item.redstone, 1), + new ItemStack(Item.ingotIron, 1)}, 500, new ItemStack(yellowPipeWire, 8))); + AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[]{new ItemStack(pipeStructureCobblestone)}, 1000, new ItemStack(plugItem, 8))); } @EventHandler diff --git a/common/buildcraft/api/recipes/AssemblyRecipe.java b/common/buildcraft/api/recipes/AssemblyRecipe.java index 573db282..b3abbdbc 100644 --- a/common/buildcraft/api/recipes/AssemblyRecipe.java +++ b/common/buildcraft/api/recipes/AssemblyRecipe.java @@ -1,7 +1,9 @@ package buildcraft.api.recipes; +import java.util.ArrayList; import java.util.LinkedList; import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; public class AssemblyRecipe { @@ -11,34 +13,99 @@ public class AssemblyRecipe { public final ItemStack output; public final float energy; + public final Object[] inputOreDict; + public AssemblyRecipe(ItemStack[] input, int energy, ItemStack output) { this.input = input; this.output = output; this.energy = energy; + this.inputOreDict = input; + } + + /** This version of AssemblyRecipe supports the OreDictionary + * + * @param input Object[] containing either an ItemStack, or a paired string and integer(ex: "dyeBlue", 1) + * @param energy MJ cost to produce + * @param output resulting ItemStack + */ + public AssemblyRecipe(Object[] input, int energy, ItemStack output) { + this.output = output; + this.energy = energy; + + this.inputOreDict = new Object[input.length]; + + int count = 0; + for (int idx = 0; idx < input.length; idx++) { + if (input[idx] == null) { + continue; + } + + ItemStack in; + + if (input[idx] instanceof ItemStack) { + inputOreDict[idx] = input[idx]; + count++; + } else if (input[idx] instanceof String) { + ArrayList oreListWithStackSize = new ArrayList(); + + for (ItemStack oreItem : OreDictionary.getOres((String)input[idx])) { + ItemStack sizeAdjustedOreItem = oreItem.copy(); + + //Desired recipe stacksize is on next index + sizeAdjustedOreItem.stackSize = (int)input[idx + 1]; + + oreListWithStackSize.add(sizeAdjustedOreItem); + } + + inputOreDict[idx++] = oreListWithStackSize; + count++; + } + } + + // create the recipe item array + this.input = new ItemStack[count]; + count = 0; + for(Object recipeItem : inputOreDict) { + if (recipeItem == null) { + continue; + } + + // since the API recipe item array is an ItemStack, just grab the first item from the OreDict list + this.input[count++] = recipeItem instanceof ItemStack ? (ItemStack)recipeItem: ((ArrayList)recipeItem).get(0); + } } public boolean canBeDone(ItemStack[] items) { - for (ItemStack in : input) { + for (Object in : inputOreDict) { if (in == null) { continue; } int found = 0; // Amount of ingredient found in inventory + int expected = in instanceof ItemStack ? ((ItemStack)in).stackSize: in instanceof ArrayList ? ((ArrayList)in).get(0).stackSize: 1; for (ItemStack item : items) { if (item == null) { continue; } - if (item.isItemEqual(in)) { - found += item.stackSize; // Adds quantity of stack to amount - // found + if (in instanceof ItemStack) { + if (item.isItemEqual((ItemStack)in)) { + found += item.stackSize; // Adds quantity of stack to amount found + } + } else if (in instanceof ArrayList) { + for (ItemStack oreItem : (ArrayList)in) { + if(OreDictionary.itemMatches(oreItem, item, true)) { + found += item.stackSize; + break; + } + } } } - if (found < in.stackSize) + if (found < expected) return false; // Return false if the amount of ingredient found // is not enough }