Changes to AssemblyRecipe to support OreDict
- Moved AssemblyRecipes to Init phase in BuildCraftTransport so that the OreDictionary is completed by then - Added new AssemblyRecipe constructor that can take ore tag strings paired with a desired stack size - Changed pipe wires over to new constructor
This commit is contained in:
parent
b37f33c104
commit
26572907bc
2 changed files with 83 additions and 16 deletions
|
@ -313,32 +313,24 @@ public class BuildCraftTransport {
|
||||||
redPipeWire.setUnlocalizedName("redPipeWire");
|
redPipeWire.setUnlocalizedName("redPipeWire");
|
||||||
LanguageRegistry.addName(redPipeWire, "Red Pipe Wire");
|
LanguageRegistry.addName(redPipeWire, "Red Pipe Wire");
|
||||||
CoreProxy.proxy.registerItem(redPipeWire);
|
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);
|
Property bluePipeWireId = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_ITEM, "bluePipeWire.id", DefaultProps.BLUE_PIPE_WIRE);
|
||||||
bluePipeWire = new ItemBuildCraft(bluePipeWireId.getInt()).setPassSneakClick(true);
|
bluePipeWire = new ItemBuildCraft(bluePipeWireId.getInt()).setPassSneakClick(true);
|
||||||
bluePipeWire.setUnlocalizedName("bluePipeWire");
|
bluePipeWire.setUnlocalizedName("bluePipeWire");
|
||||||
LanguageRegistry.addName(bluePipeWire, "Blue Pipe Wire");
|
LanguageRegistry.addName(bluePipeWire, "Blue Pipe Wire");
|
||||||
CoreProxy.proxy.registerItem(bluePipeWire);
|
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);
|
Property greenPipeWireId = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_ITEM, "greenPipeWire.id", DefaultProps.GREEN_PIPE_WIRE);
|
||||||
greenPipeWire = new ItemBuildCraft(greenPipeWireId.getInt()).setPassSneakClick(true);
|
greenPipeWire = new ItemBuildCraft(greenPipeWireId.getInt()).setPassSneakClick(true);
|
||||||
greenPipeWire.setUnlocalizedName("greenPipeWire");
|
greenPipeWire.setUnlocalizedName("greenPipeWire");
|
||||||
LanguageRegistry.addName(greenPipeWire, "Green Pipe Wire");
|
LanguageRegistry.addName(greenPipeWire, "Green Pipe Wire");
|
||||||
CoreProxy.proxy.registerItem(greenPipeWire);
|
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);
|
Property yellowPipeWireId = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_ITEM, "yellowPipeWire.id", DefaultProps.YELLOW_PIPE_WIRE);
|
||||||
yellowPipeWire = new ItemBuildCraft(yellowPipeWireId.getInt()).setPassSneakClick(true);
|
yellowPipeWire = new ItemBuildCraft(yellowPipeWireId.getInt()).setPassSneakClick(true);
|
||||||
yellowPipeWire.setUnlocalizedName("yellowPipeWire");
|
yellowPipeWire.setUnlocalizedName("yellowPipeWire");
|
||||||
LanguageRegistry.addName(yellowPipeWire, "Yellow Pipe Wire");
|
LanguageRegistry.addName(yellowPipeWire, "Yellow Pipe Wire");
|
||||||
CoreProxy.proxy.registerItem(yellowPipeWire);
|
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);
|
Property pipeGateId = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_ITEM, "pipeGate.id", DefaultProps.GATE_ID);
|
||||||
pipeGate = new ItemGate(pipeGateId.getInt(), 0);
|
pipeGate = new ItemGate(pipeGateId.getInt(), 0);
|
||||||
|
@ -365,9 +357,6 @@ public class BuildCraftTransport {
|
||||||
filteredBufferBlock = new BlockFilteredBuffer(filteredBufferId.getInt());
|
filteredBufferBlock = new BlockFilteredBuffer(filteredBufferId.getInt());
|
||||||
CoreProxy.proxy.registerBlock(filteredBufferBlock.setUnlocalizedName("filteredBufferBlock"));
|
CoreProxy.proxy.registerBlock(filteredBufferBlock.setUnlocalizedName("filteredBufferBlock"));
|
||||||
CoreProxy.proxy.addName(filteredBufferBlock, "Filtered Buffer");
|
CoreProxy.proxy.addName(filteredBufferBlock, "Filtered Buffer");
|
||||||
|
|
||||||
AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[]{new ItemStack(pipeStructureCobblestone)}, 1000, new ItemStack(plugItem, 8)));
|
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
BuildCraftCore.mainConfiguration.save();
|
BuildCraftCore.mainConfiguration.save();
|
||||||
}
|
}
|
||||||
|
@ -449,6 +438,17 @@ public class BuildCraftTransport {
|
||||||
|
|
||||||
//Facade turning helper
|
//Facade turning helper
|
||||||
GameRegistry.addRecipe(facadeItem.new FacadeRecipe());
|
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
|
@EventHandler
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package buildcraft.api.recipes;
|
package buildcraft.api.recipes;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
public class AssemblyRecipe {
|
public class AssemblyRecipe {
|
||||||
|
|
||||||
|
@ -11,34 +13,99 @@ public class AssemblyRecipe {
|
||||||
public final ItemStack output;
|
public final ItemStack output;
|
||||||
public final float energy;
|
public final float energy;
|
||||||
|
|
||||||
|
public final Object[] inputOreDict;
|
||||||
|
|
||||||
public AssemblyRecipe(ItemStack[] input, int energy, ItemStack output) {
|
public AssemblyRecipe(ItemStack[] input, int energy, ItemStack output) {
|
||||||
this.input = input;
|
this.input = input;
|
||||||
this.output = output;
|
this.output = output;
|
||||||
this.energy = energy;
|
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<ItemStack> oreListWithStackSize = new ArrayList<ItemStack>();
|
||||||
|
|
||||||
|
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<ItemStack>)recipeItem).get(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canBeDone(ItemStack[] items) {
|
public boolean canBeDone(ItemStack[] items) {
|
||||||
|
|
||||||
for (ItemStack in : input) {
|
for (Object in : inputOreDict) {
|
||||||
|
|
||||||
if (in == null) {
|
if (in == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int found = 0; // Amount of ingredient found in inventory
|
int found = 0; // Amount of ingredient found in inventory
|
||||||
|
int expected = in instanceof ItemStack ? ((ItemStack)in).stackSize: in instanceof ArrayList ? ((ArrayList<ItemStack>)in).get(0).stackSize: 1;
|
||||||
|
|
||||||
for (ItemStack item : items) {
|
for (ItemStack item : items) {
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.isItemEqual(in)) {
|
if (in instanceof ItemStack) {
|
||||||
found += item.stackSize; // Adds quantity of stack to amount
|
if (item.isItemEqual((ItemStack)in)) {
|
||||||
// found
|
found += item.stackSize; // Adds quantity of stack to amount found
|
||||||
|
}
|
||||||
|
} else if (in instanceof ArrayList) {
|
||||||
|
for (ItemStack oreItem : (ArrayList<ItemStack>)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
|
return false; // Return false if the amount of ingredient found
|
||||||
// is not enough
|
// is not enough
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue