summaryrefslogtreecommitdiff
path: root/ihl/recipes
diff options
context:
space:
mode:
authorFoghrye4 <foghrye4@gmail.com>2016-04-11 19:44:54 +0300
committerFoghrye4 <foghrye4@gmail.com>2016-04-11 19:44:54 +0300
commit05c78126859231a68e199dc34613689bd0978e2f (patch)
tree050bea104a18c72905095d29f31bec2935a27a24 /ihl/recipes
Initial commit
Diffstat (limited to 'ihl/recipes')
-rw-r--r--ihl/recipes/IRecipeInputFluid.java12
-rw-r--r--ihl/recipes/IronWorkbenchRecipe.java182
-rw-r--r--ihl/recipes/RecipeInputDie.java98
-rw-r--r--ihl/recipes/RecipeInputFluidDictionary.java43
-rw-r--r--ihl/recipes/RecipeInputFluidStack.java41
-rw-r--r--ihl/recipes/RecipeInputObjectInstance.java46
-rw-r--r--ihl/recipes/RecipeInputOreDictionaryList.java149
-rw-r--r--ihl/recipes/RecipeInputWire.java87
-rw-r--r--ihl/recipes/RecipeOutputItemStack.java65
-rw-r--r--ihl/recipes/UniversalRecipeInput.java305
-rw-r--r--ihl/recipes/UniversalRecipeManager.java229
-rw-r--r--ihl/recipes/UniversalRecipeOutput.java145
12 files changed, 1402 insertions, 0 deletions
diff --git a/ihl/recipes/IRecipeInputFluid.java b/ihl/recipes/IRecipeInputFluid.java
new file mode 100644
index 0000000..8faf15d
--- /dev/null
+++ b/ihl/recipes/IRecipeInputFluid.java
@@ -0,0 +1,12 @@
+package ihl.recipes;
+
+import java.util.List;
+
+import net.minecraft.item.ItemStack;
+import net.minecraftforge.fluids.FluidStack;
+
+public interface IRecipeInputFluid {
+ public boolean matches(FluidStack subject);
+ public int getAmount();
+ public List<FluidStack> getInputs();
+}
diff --git a/ihl/recipes/IronWorkbenchRecipe.java b/ihl/recipes/IronWorkbenchRecipe.java
new file mode 100644
index 0000000..8ecb8df
--- /dev/null
+++ b/ihl/recipes/IronWorkbenchRecipe.java
@@ -0,0 +1,182 @@
+package ihl.recipes;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import net.minecraft.item.ItemStack;
+import ic2.api.recipe.IRecipeInput;
+import ic2.api.recipe.RecipeInputItemStack;
+import ic2.api.recipe.RecipeInputOreDict;
+import ihl.interfaces.IWire;
+import ihl.utils.IHLUtils;
+
+public class IronWorkbenchRecipe {
+ public List<ItemStack> workspaceElements=new ArrayList<ItemStack>();
+ public List<IRecipeInput> tools=new ArrayList<IRecipeInput>();
+ public List<IRecipeInput> materials=new ArrayList<IRecipeInput>();
+ public List<ItemStack> outputs = new ArrayList<ItemStack>();
+
+ public IronWorkbenchRecipe(List tools1, List materials1, List<ItemStack> output1_1)
+ {
+ if(tools1!=null)
+ {
+ Iterator iTools1 = tools1.iterator();
+ while(iTools1.hasNext())
+ {
+ Object tool = iTools1.next();
+ if(tool instanceof ItemStack)
+ {
+ ItemStack stack = (ItemStack) tool;
+ String oreDictName = IHLUtils.getFirstOreDictNameExcludingTagAny(stack);
+ if(!oreDictName.isEmpty() && oreDictName.length()>3)
+ {
+ tools.add(new RecipeInputOreDict(oreDictName));
+ }
+ else
+ {
+ tools.add(new RecipeInputItemStack(stack));
+ }
+ }
+ else
+ {
+ tools.add((IRecipeInput) tool);
+ }
+ }
+ }
+ Iterator iMaterials1 = materials1.iterator();
+ while(iMaterials1.hasNext())
+ {
+ Object material = iMaterials1.next();
+ if(material instanceof ItemStack)
+ {
+ ItemStack stack = (ItemStack) material;
+ String oreDictName = IHLUtils.getFirstOreDictNameExcludingTagAny(stack);
+ if(stack.getItem() instanceof IWire)
+ {
+ materials.add(new RecipeInputWire(stack));
+ }
+ else if(!oreDictName.isEmpty() && oreDictName.length()>3)
+ {
+ materials.add(new RecipeInputOreDict(oreDictName,stack.stackSize));
+ }
+ else
+ {
+ materials.add(new RecipeInputItemStack(stack));
+ }
+ }
+ else
+ {
+ materials.add((IRecipeInput) material);
+ }
+
+ }
+ this.outputs.addAll(output1_1);
+ if(tools.size()>8 || materials.size()>12)
+ {
+ throw new IllegalArgumentException("Iron workbench recipe cannot contain more than 8 tools or more than 12 materials!");
+ }
+ }
+
+ public IronWorkbenchRecipe(List asList, List asList2, List<ItemStack> asList3, List<ItemStack> workspaceElements1) {
+ this(asList, asList2, asList3);
+ this.workspaceElements.addAll(workspaceElements1);
+ }
+
+ public boolean isCanBeCrafted(List<ItemStack> tools1, List<ItemStack> materials1, List<ItemStack> workspaceElements1)
+ {
+ if(workspaceElements!=null && !workspaceElements.isEmpty())
+ {
+ if(workspaceElements1==null||workspaceElements1.isEmpty())
+ {
+ return false;
+ }
+ Iterator<ItemStack> i1 = workspaceElements.iterator();
+ while(i1.hasNext())
+ {
+ ItemStack tool = i1.next();
+ if(!this.isItemStackInList(tool, workspaceElements1))
+ {
+ return false;
+ }
+ }
+ }
+
+ if(tools!=null && !tools.isEmpty())
+ {
+ if(tools1==null||tools1.isEmpty())
+ {
+ return false;
+ }
+ Iterator<IRecipeInput> i1 = tools.iterator();
+ while(i1.hasNext())
+ {
+ IRecipeInput tool = i1.next();
+ if(!this.isItemStackInList(tool, tools1))
+ {
+ return false;
+ }
+ }
+ }
+ if(materials!=null && !materials.isEmpty())
+ {
+ Iterator<IRecipeInput> i1 = materials.iterator();
+ while(i1.hasNext())
+ {
+ IRecipeInput material = i1.next();
+ if(!this.isItemStackInList(material, materials1))
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ private boolean isItemStackInList(IRecipeInput tool, List<ItemStack> tools1) {
+ Iterator<ItemStack> it = tools1.iterator();
+ while(it.hasNext())
+ {
+ ItemStack tool2 = it.next();
+ if(tool.matches(tool2))
+ {
+ if(tool2.getItem() instanceof IWire)
+ {
+ if(IHLUtils.getWireLength(tool2)>=tool.getAmount())
+ {
+ return true;
+ }
+ }
+ else if(tool2.stackSize>=tool.getAmount())
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private boolean isItemStackInList(ItemStack tool, List<ItemStack> tools1)
+ {
+ Iterator<ItemStack> it = tools1.iterator();
+ while(it.hasNext())
+ {
+ ItemStack tool2 = it.next();
+ if(IHLUtils.isItemStacksIsEqual(tool,tool2,true))
+ {
+ if(tool2.getItem() instanceof IWire)
+ {
+ if(IHLUtils.getWireLength(tool2)>=IHLUtils.getWireLength(tool))
+ {
+ return true;
+ }
+ }
+ else if(tool2.stackSize>=tool.stackSize)
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+}
diff --git a/ihl/recipes/RecipeInputDie.java b/ihl/recipes/RecipeInputDie.java
new file mode 100644
index 0000000..c8356ca
--- /dev/null
+++ b/ihl/recipes/RecipeInputDie.java
@@ -0,0 +1,98 @@
+package ihl.recipes;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import ic2.api.recipe.IRecipeInput;
+import ihl.interfaces.IWire;
+import ihl.items_blocks.FlexibleCableItem;
+import ihl.utils.IHLUtils;
+import net.minecraft.item.ItemStack;
+
+public class RecipeInputDie implements IRecipeInput
+{
+ public final ItemStack input;
+ public final int transverseSection;
+
+ public RecipeInputDie(String string, int transverseSection)
+ {
+ this(IHLUtils.getItemStackWithTag(string, "transverseSection", transverseSection));
+ }
+
+ public RecipeInputDie(ItemStack itemStack)
+ {
+ input=itemStack;
+ transverseSection=itemStack.stackTagCompound.getInteger("transverseSection");
+ }
+
+ @Override
+ public boolean matches(ItemStack subject)
+ {
+ return subject.getItem() == this.input.getItem() && (subject.getItemDamage() == this.input.getItemDamage() || this.input.getItemDamage() == 32767);
+ }
+
+ @Override
+ public int getAmount()
+ {
+ return 1;
+ }
+
+ @Override
+ public List<ItemStack> getInputs()
+ {
+ return Arrays.asList(new ItemStack[] {this.input});
+ }
+
+ @Override
+ public String toString()
+ {
+ ItemStack stack = this.input.copy();
+ return "RInputDice<" + stack + ">";
+ }
+
+ public List<ItemStack> transformOutput(ItemStack matchedItemStack, List<ItemStack> outputs)
+ {
+ List<ItemStack> newOutputs = new ArrayList();
+ int misTS = matchedItemStack.stackTagCompound.getInteger("transverseSection");
+ ItemStack material;
+ for(ItemStack material1:outputs)
+ {
+ if(material1.getItem() instanceof IWire)
+ {
+ material=material1.copy();
+ int length = material.stackTagCompound.getInteger("length");
+ length = length * transverseSection / misTS;
+ material.stackTagCompound.setInteger("length", length);
+ material.stackTagCompound.setInteger("fullLength", length);
+ material.stackTagCompound.setInteger("transverseSection", misTS);
+ newOutputs.add(material);
+ }
+ else
+ {
+ newOutputs.add(material1);
+ }
+ }
+ return newOutputs;
+ }
+
+ public int transformOutput(ItemStack matchedItemStack, ItemStack material)
+ {
+ int consumeAmountMultiplier=1;
+ int misTS = matchedItemStack.stackTagCompound.getInteger("transverseSection");
+ if(misTS<=transverseSection)
+ {
+ int length = material.stackTagCompound.getInteger("length");
+ length = length * transverseSection / misTS;
+ material.stackTagCompound.setInteger("length", length);
+ material.stackTagCompound.setInteger("fullLength", length);
+ }
+ else
+ {
+ consumeAmountMultiplier=misTS/transverseSection+1;
+ }
+ material.stackTagCompound.setInteger("transverseSection", misTS);
+ return consumeAmountMultiplier;
+ }
+}
+
diff --git a/ihl/recipes/RecipeInputFluidDictionary.java b/ihl/recipes/RecipeInputFluidDictionary.java
new file mode 100644
index 0000000..46c51eb
--- /dev/null
+++ b/ihl/recipes/RecipeInputFluidDictionary.java
@@ -0,0 +1,43 @@
+package ihl.recipes;
+
+import java.util.Arrays;
+import java.util.List;
+
+import net.minecraft.item.ItemStack;
+import net.minecraftforge.fluids.Fluid;
+import net.minecraftforge.fluids.FluidStack;
+import ic2.api.recipe.IRecipeInput;
+import ihl.IHLMod;
+
+public class RecipeInputFluidDictionary implements IRecipeInputFluid
+{
+ private final String input;
+ private final int amount;
+ public RecipeInputFluidDictionary(String input1, int amount1)
+ {
+ this.input=input1;
+ this.amount=amount1;
+ }
+
+ @Override
+ public boolean matches(FluidStack subject)
+ {
+ if(subject==null)
+ {
+ return false;
+ }
+ String fName = IHLMod.fluidDictionary.getFluidName(subject.getFluid());
+ return fName==null?false:fName.equals(input);
+ }
+
+ @Override
+ public int getAmount() {
+ return amount;
+ }
+
+ @Override
+ public List<FluidStack> getInputs() {
+ return IHLMod.fluidDictionary.getFluids(input);
+ }
+
+}
diff --git a/ihl/recipes/RecipeInputFluidStack.java b/ihl/recipes/RecipeInputFluidStack.java
new file mode 100644
index 0000000..a7b5d0e
--- /dev/null
+++ b/ihl/recipes/RecipeInputFluidStack.java
@@ -0,0 +1,41 @@
+package ihl.recipes;
+
+import java.util.Arrays;
+import java.util.List;
+
+import net.minecraft.item.ItemStack;
+import net.minecraftforge.fluids.Fluid;
+import net.minecraftforge.fluids.FluidStack;
+import ic2.api.recipe.IRecipeInput;
+
+public class RecipeInputFluidStack implements IRecipeInputFluid
+{
+ private final Fluid fluid;
+ private final int amount;
+ public RecipeInputFluidStack(FluidStack fstack)
+ {
+ this.fluid=fstack.getFluid();
+ this.amount=fstack.amount;
+ }
+
+ @Override
+ public boolean matches(FluidStack subject)
+ {
+ if(subject==null || subject.getFluid()==null)
+ {
+ return false;
+ }
+ return fluid.getName().equals(subject.getFluid().getName());
+ }
+
+ @Override
+ public int getAmount() {
+ return amount;
+ }
+
+ @Override
+ public List<FluidStack> getInputs() {
+ return Arrays.asList(new FluidStack[] {new FluidStack(fluid,amount)});
+ }
+
+}
diff --git a/ihl/recipes/RecipeInputObjectInstance.java b/ihl/recipes/RecipeInputObjectInstance.java
new file mode 100644
index 0000000..eeadc5c
--- /dev/null
+++ b/ihl/recipes/RecipeInputObjectInstance.java
@@ -0,0 +1,46 @@
+package ihl.recipes;
+
+import java.util.Arrays;
+import java.util.List;
+
+import net.minecraft.item.ItemStack;
+import ic2.api.recipe.IRecipeInput;
+import ihl.interfaces.IWire;
+import ihl.items_blocks.FlexibleCableItem;
+import ihl.utils.IHLUtils;
+
+public class RecipeInputObjectInstance implements IRecipeInput
+{
+ public final ItemStack input;
+
+ public RecipeInputObjectInstance(ItemStack aInput)
+ {
+ this.input = aInput;
+ }
+
+ @Override
+ public boolean matches(ItemStack subject)
+ {
+ return this.input==subject;
+ }
+
+ @Override
+ public int getAmount()
+ {
+ return IHLUtils.getAmountOf(input);
+ }
+
+ @Override
+ public List<ItemStack> getInputs()
+ {
+ return Arrays.asList(new ItemStack[] {this.input});
+ }
+
+ @Override
+ public String toString()
+ {
+ ItemStack stack = this.input.copy();
+ return "RInputWireItemStack<" + stack + ">";
+ }
+
+}
diff --git a/ihl/recipes/RecipeInputOreDictionaryList.java b/ihl/recipes/RecipeInputOreDictionaryList.java
new file mode 100644
index 0000000..3c4b551
--- /dev/null
+++ b/ihl/recipes/RecipeInputOreDictionaryList.java
@@ -0,0 +1,149 @@
+package ihl.recipes;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import ic2.api.recipe.IRecipeInput;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraftforge.oredict.OreDictionary;
+
+public class RecipeInputOreDictionaryList implements IRecipeInput
+{
+
+ public final String[] input;
+ public final int amount;
+ public final Integer meta;
+ private List<ItemStack> ores;
+
+ public RecipeInputOreDictionaryList(String[] input1)
+ {
+ this(input1, 1);
+ }
+
+ public RecipeInputOreDictionaryList(String[] input1, int amount1)
+ {
+ this(input1, amount1, (Integer)null);
+ }
+
+ public RecipeInputOreDictionaryList(String[] input1, int amount1, Integer meta)
+ {
+ this.input = input1;
+ this.amount = amount1;
+ this.meta = meta;
+ }
+
+ @Override
+ public boolean matches(ItemStack subject)
+ {
+ List inputs = this.getOres();
+ boolean useOreStackMeta = this.meta == null;
+ Item subjectItem = subject.getItem();
+ int subjectMeta = subject.getItemDamage();
+ Iterator i$ = inputs.iterator();
+ Item oreItem;
+ int metaRequired;
+
+ do
+ {
+ do
+ {
+ ItemStack oreStack;
+
+ do
+ {
+ if (!i$.hasNext())
+ {
+ return false;
+ }
+
+ oreStack = (ItemStack)i$.next();
+ oreItem = oreStack.getItem();
+ }
+ while (oreItem == null);
+
+ metaRequired = useOreStackMeta ? oreStack.getItemDamage() : this.meta.intValue();
+ }
+ while (subjectItem != oreItem);
+ }
+ while (subjectMeta != metaRequired && metaRequired != 32767);
+
+ return true;
+ }
+
+ @Override
+ public int getAmount()
+ {
+ return this.amount;
+ }
+
+ @Override
+ public List<ItemStack> getInputs()
+ {
+ List ores = this.getOres();
+ boolean hasInvalidEntries = false;
+ Iterator ret = ores.iterator();
+
+ while (ret.hasNext())
+ {
+ ItemStack i$ = (ItemStack)ret.next();
+
+ if (i$.getItem() == null)
+ {
+ hasInvalidEntries = true;
+ break;
+ }
+ }
+
+ if (!hasInvalidEntries)
+ {
+ return ores;
+ }
+ else
+ {
+ ArrayList ret1 = new ArrayList(ores.size());
+ Iterator i$1 = ores.iterator();
+
+ while (i$1.hasNext())
+ {
+ ItemStack stack = (ItemStack)i$1.next();
+
+ if (stack.getItem() != null)
+ {
+ ret1.add(stack);
+ }
+ }
+
+ return Collections.unmodifiableList(ret1);
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ return this.meta == null ? "RInputOreDict<" + this.amount + "x" + this.input + ">" : "RInputOreDict<" + this.amount + "x" + this.input + "@" + this.meta + ">";
+ }
+
+ private List<ItemStack> getOres()
+ {
+ if (this.ores != null)
+ {
+ return this.ores;
+ }
+ else
+ {
+ this.ores = new ArrayList();
+ for(int i=0;i<this.input.length;i++)
+ {
+ ArrayList ret = OreDictionary.getOres(this.input[i]);
+ if (ret != OreDictionary.EMPTY_LIST)
+ {
+ this.ores.addAll(ret);
+ }
+ }
+ return this.ores;
+ }
+ }
+}
diff --git a/ihl/recipes/RecipeInputWire.java b/ihl/recipes/RecipeInputWire.java
new file mode 100644
index 0000000..720fe1b
--- /dev/null
+++ b/ihl/recipes/RecipeInputWire.java
@@ -0,0 +1,87 @@
+package ihl.recipes;
+
+import java.util.Arrays;
+import java.util.List;
+
+import ic2.api.recipe.IRecipeInput;
+import ihl.interfaces.IWire;
+import ihl.items_blocks.FlexibleCableItem;
+import ihl.utils.IHLUtils;
+import net.minecraft.item.ItemStack;
+
+public class RecipeInputWire implements IRecipeInput
+{
+ public final ItemStack input;
+ public final int amount;
+
+ public RecipeInputWire(ItemStack aInput)
+ {
+ this(aInput, IHLUtils.getWireLength(aInput));
+ }
+
+ public RecipeInputWire(ItemStack aInput, int aAmount)
+ {
+ if (aInput.getItem() == null || !(aInput.getItem() instanceof IWire))
+ {
+ throw new IllegalArgumentException("Invalid item stack specfied");
+ }
+ else
+ {
+ this.input = aInput.copy();
+ this.amount = aAmount;
+ }
+ }
+
+ public RecipeInputWire(String string, int i)
+ {
+ this(IHLUtils.getThisModWireItemStackWithLength(string, i),i);
+ }
+
+ public RecipeInputWire(String material, int length, int transverseSection)
+ {
+ this(IHLUtils.getUninsulatedWire(material, length, transverseSection),length);
+ }
+
+ public RecipeInputWire(String material, int length, int transverseSection, String insulationMaterial, int insulationThickness, int insulationBreakdownVoltage)
+ {
+ this(IHLUtils.getInsulatedWire(material, length, transverseSection, insulationMaterial, insulationThickness),length);
+ }
+
+ @Override
+ public boolean matches(ItemStack subject)
+ {
+ if(subject.getItem() == this.input.getItem() && (subject.getItemDamage() == this.input.getItemDamage() || this.input.getItemDamage() == 32767))
+ {
+ if(subject.getItem() instanceof FlexibleCableItem)
+ {
+ FlexibleCableItem item = (FlexibleCableItem) subject.getItem();
+ return item.isSameWire(this.input, subject);
+ }
+ else
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public int getAmount()
+ {
+ return this.amount;
+ }
+
+ @Override
+ public List<ItemStack> getInputs()
+ {
+ return Arrays.asList(new ItemStack[] {this.input});
+ }
+
+ @Override
+ public String toString()
+ {
+ ItemStack stack = this.input.copy();
+ return "RInputWireItemStack<" + stack + ">";
+ }
+}
+
diff --git a/ihl/recipes/RecipeOutputItemStack.java b/ihl/recipes/RecipeOutputItemStack.java
new file mode 100644
index 0000000..c765b1d
--- /dev/null
+++ b/ihl/recipes/RecipeOutputItemStack.java
@@ -0,0 +1,65 @@
+package ihl.recipes;
+
+import net.minecraft.item.ItemStack;
+import net.minecraftforge.oredict.OreDictionary;
+
+public class RecipeOutputItemStack
+{
+ public final ItemStack itemStack;
+ public final float quantity;
+ public RecipeOutputItemStack(ItemStack itemStack1, float quantity1)
+ {
+ itemStack=itemStack1;
+ quantity=quantity1;
+ itemStack.stackSize=1;
+ }
+
+ public RecipeOutputItemStack(ItemStack itemStack1)
+ {
+ this(itemStack1, itemStack1.stackSize);
+ }
+
+ public boolean matches(RecipeOutputItemStack is1)
+ {
+ if(is1==null||(itemStack.getItem()!=is1.itemStack.getItem()))
+ {
+ return false;
+ }
+ else if(is1.itemStack.getItemDamage()!=OreDictionary.WILDCARD_VALUE &&
+ itemStack.getItemDamage()!=is1.itemStack.getItemDamage())
+ {
+ return false;
+ }
+ return true;
+ }
+
+ public RecipeOutputItemStack copy(int mulipier)
+ {
+ return new RecipeOutputItemStack(itemStack, quantity*mulipier);
+ }
+
+ public RecipeOutputItemStack copy()
+ {
+ return new RecipeOutputItemStack(itemStack, quantity);
+ }
+
+ @Override
+ public String toString()
+ {
+ return this.itemStack.getUnlocalizedName()+":"+this.quantity;
+ }
+
+ public boolean matches(ItemStack is1)
+ {
+ if(is1==null||(itemStack.getItem()!=is1.getItem()))
+ {
+ return false;
+ }
+ else if(is1.getItemDamage()!=OreDictionary.WILDCARD_VALUE &&
+ itemStack.getItemDamage()!=is1.getItemDamage())
+ {
+ return false;
+ }
+ return false;
+ }
+}
diff --git a/ihl/recipes/UniversalRecipeInput.java b/ihl/recipes/UniversalRecipeInput.java
new file mode 100644
index 0000000..f0b42e2
--- /dev/null
+++ b/ihl/recipes/UniversalRecipeInput.java
@@ -0,0 +1,305 @@
+package ihl.recipes;
+
+import ic2.api.recipe.IRecipeInput;
+import ic2.api.recipe.RecipeInputItemStack;
+import ic2.api.recipe.RecipeInputOreDict;
+import ihl.interfaces.IWire;
+import ihl.utils.IHLUtils;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import net.minecraft.item.ItemStack;
+import net.minecraftforge.fluids.FluidStack;
+
+public class UniversalRecipeInput{
+
+ private final List<IRecipeInputFluid> fluidInputs=new ArrayList();
+ private final List<IRecipeInput> itemInputs=new ArrayList();
+ private boolean sharp=true;
+ private int temperatureMin = 273;
+ private int temperatureMax = Integer.MAX_VALUE;
+ private float speedFactor=-1.0f;//=-Ea/R (k=k0*exp(-Ea/(RT)))
+ private int multiplier=Integer.MAX_VALUE;
+
+
+ public UniversalRecipeInput(List fluidInputs1, List itemInputs1, boolean sharp1)
+ {
+ this(fluidInputs1, itemInputs1);
+ this.sharp=false;
+ }
+
+ public UniversalRecipeInput(List fluidInputs1, List itemInputs1)
+ {
+ if(fluidInputs1!=null)
+ {
+ Iterator ifluidInputs1 = fluidInputs1.iterator();
+ while(ifluidInputs1.hasNext())
+ {
+ Object material = ifluidInputs1.next();
+ if(material==null)
+ {
+ throw new NullPointerException("Recipe input cannot be null!");
+ }
+ if(material instanceof FluidStack)
+ {
+ fluidInputs.add(new RecipeInputFluidStack((FluidStack)material));
+ }
+ else
+ {
+ fluidInputs.add((IRecipeInputFluid) material);
+ }
+ }
+ }
+ if(itemInputs1!=null)
+ {
+ Iterator iitemInputs1 = itemInputs1.iterator();
+ while(iitemInputs1.hasNext())
+ {
+ Object material = iitemInputs1.next();
+ if(material==null)
+ {
+ throw new NullPointerException("Recipe input cannot be null!");
+ }
+ if(material instanceof ItemStack)
+ {
+ ItemStack stack = (ItemStack)material;
+ String oreDictName = IHLUtils.getFirstOreDictNameExcludingTagAny(stack);
+ if(stack.getItem() instanceof IWire)
+ {
+ itemInputs.add(new RecipeInputWire(stack));
+ }
+ else if(!oreDictName.isEmpty() && oreDictName.length()>3)
+ {
+ itemInputs.add(new RecipeInputOreDict(oreDictName,stack.stackSize));
+ }
+ else
+ {
+ itemInputs.add(new RecipeInputItemStack(stack));
+ }
+ }
+ else
+ {
+ itemInputs.add((IRecipeInput) material);
+ }
+ }
+ }
+ }
+
+ public boolean matches(List<FluidStack> fluidInputs1, List<ItemStack> itemInputs1)
+ {
+ return this.adjustAmounts(fluidInputs1, itemInputs1, false, false);
+ }
+
+ public List<IRecipeInputFluid> getFluidInputs() {
+ return fluidInputs;
+ }
+
+ public List<IRecipeInput> getItemInputs() {
+ return itemInputs;
+ }
+
+ public boolean matches(UniversalRecipeInput input) {
+ List<IRecipeInput> rInputs = input.getItemInputs();
+ Iterator<IRecipeInput> ii = rInputs.iterator();
+ List<ItemStack> rInputsItems = new ArrayList();
+ while(ii.hasNext())
+ {
+ IRecipeInput is = ii.next();
+ rInputsItems.add(is.getInputs().get(0));
+ }
+ List<FluidStack> rInputsFluids = new ArrayList();
+ List<IRecipeInputFluid> rInputsF = input.getFluidInputs();
+ Iterator<IRecipeInputFluid> iiF = rInputsF.iterator();
+ while(iiF.hasNext())
+ {
+ IRecipeInputFluid is = iiF.next();
+ rInputsFluids.add(is.getInputs().get(0));
+ }
+ return this.matches(rInputsFluids, rInputsItems);
+ }
+
+ public boolean adjustAmounts(List<FluidStack> fluidInputs1, List<ItemStack> itemInputs1, boolean doCheckAmounts, boolean doAdjustAmounts)
+ {
+ this.multiplier=Integer.MAX_VALUE;
+ if(incorrectInputAmount(fluidInputs1, itemInputs1))
+ {
+ return false;
+ }
+ if(fluidInputs1!=null)
+ {
+ Iterator<IRecipeInputFluid> fi = fluidInputs.iterator();
+ while(fi.hasNext())
+ {
+ IRecipeInputFluid fs = fi.next();
+ FluidStack fs1 = getMatchedFluidStack(fs,fluidInputs1);
+ if(fs1==null || !fs.matches(fs1))
+ {
+ multiplier=0;
+ return false;
+ }
+ else if(doCheckAmounts && fs1.amount<fs.getAmount())
+ {
+ multiplier=0;
+ return false;
+ }
+ else if(doAdjustAmounts)
+ {
+ if(fs.getAmount()>0)
+ {
+ int multiplier1=fs1.amount/fs.getAmount();
+ if(multiplier1<multiplier)
+ {
+ multiplier=multiplier1;
+ }
+ }
+ fs1.amount-=fs.getAmount();
+ if(fs1.amount<=0)fs1=null;
+ }
+ }
+ }
+ if(itemInputs1!=null)
+ {
+ Iterator<IRecipeInput> ii = itemInputs.iterator();
+ while(ii.hasNext())
+ {
+ IRecipeInput is = ii.next();
+ ItemStack is1 = getMatchedItemStack(is, itemInputs1);
+ if(is1==null || !is.matches(is1))
+ {
+ multiplier=0;
+ return false;
+ }
+ else if(doCheckAmounts && is1.stackSize<is.getAmount())
+ {
+ multiplier=0;
+ return false;
+ }
+ else if(doAdjustAmounts)
+ {
+ if(is.getAmount()>0)
+ {
+ int multiplier1=is1.stackSize/is.getAmount();
+ if(multiplier1<multiplier)
+ {
+ multiplier=multiplier1;
+ }
+ }
+ if(IHLUtils.reduceItemStackAmountUsingIRecipeInput(is, is1))
+ {
+ is1=null;
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ private ItemStack getMatchedItemStack(IRecipeInput is, List<ItemStack> itemInputs1)
+ {
+ for(ItemStack is1:itemInputs1)
+ {
+ if(is1!=null)
+ {
+ if(is.matches(is1))
+ {
+ return is1;
+ }
+ }
+ }
+ return null;
+ }
+
+ private FluidStack getMatchedFluidStack(IRecipeInputFluid fs, List<FluidStack> fluidInputs1)
+ {
+ for(FluidStack fs1:fluidInputs1)
+ {
+ if(fs.matches(fs1))
+ {
+ return fs1;
+ }
+ }
+ return null;
+ }
+
+ public boolean adjustAmounts(UniversalRecipeInput input, boolean doAdjustAmounts) {
+ List<IRecipeInput> rInputs = input.getItemInputs();
+ Iterator<IRecipeInput> ii = rInputs.iterator();
+ List<ItemStack> rInputsItems = new ArrayList();
+ while(ii.hasNext())
+ {
+ IRecipeInput is = ii.next();
+ rInputsItems.add(is.getInputs().get(0));
+ }
+ List<FluidStack> rInputsFluids = new ArrayList();
+ List<IRecipeInputFluid> rInputsF = input.getFluidInputs();
+ Iterator<IRecipeInputFluid> iiF = rInputsF.iterator();
+ while(iiF.hasNext())
+ {
+ IRecipeInputFluid is = iiF.next();
+ rInputsFluids.add(is.getInputs().get(0));
+ }
+ return this.adjustAmounts(rInputsFluids, rInputsItems, true, doAdjustAmounts);
+ }
+
+ public int getMultiplierAndAdjustAmounts(List<FluidStack> fluidInputs1, List<ItemStack> itemInputs1)
+ {
+ if(this.adjustAmounts(fluidInputs1, itemInputs1, true, true))
+ {
+ if(multiplier<Integer.MAX_VALUE)
+ {
+ return multiplier;
+ }
+ else return 1;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+
+ public boolean containItemStack(ItemStack ingredient)
+ {
+ if(itemInputs==null || itemInputs.isEmpty())
+ {
+ return false;
+ }
+ Iterator<IRecipeInput> ii = itemInputs.iterator();
+ while(ii.hasNext())
+ {
+ IRecipeInput is = ii.next();
+ if(is.matches(ingredient))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean containFluidStack(FluidStack fluidStack)
+ {
+ if(fluidInputs==null || fluidInputs.isEmpty())
+ {
+ return false;
+ }
+ Iterator<IRecipeInputFluid> ii = fluidInputs.iterator();
+ while(ii.hasNext())
+ {
+ IRecipeInputFluid is = ii.next();
+ if(is!=null && is.matches(fluidStack))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean incorrectInputAmount(List<FluidStack> fluidInputs1, List<ItemStack> itemInputs1)
+ {
+ return (fluidInputs.size()>0 && fluidInputs1==null)||
+ (itemInputs.size()>0 && itemInputs1==null)||
+ (fluidInputs1!=null && fluidInputs.size()>fluidInputs1.size())||
+ (itemInputs1!=null && itemInputs.size()>itemInputs1.size());
+ }
+}
diff --git a/ihl/recipes/UniversalRecipeManager.java b/ihl/recipes/UniversalRecipeManager.java
new file mode 100644
index 0000000..443a67f
--- /dev/null
+++ b/ihl/recipes/UniversalRecipeManager.java
@@ -0,0 +1,229 @@
+package ihl.recipes;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import net.minecraft.item.ItemStack;
+import net.minecraftforge.fluids.FluidStack;
+import ic2.api.recipe.IRecipeInput;
+import ihl.utils.IHLUtils;
+
+public class UniversalRecipeManager {
+
+ public static Map<String,UniversalRecipeManager> machineRecipeManagers = new HashMap<String,UniversalRecipeManager>();
+ public final String machine;
+ public UniversalRecipeManager(String machine1)
+ {
+ machine=machine1;
+ if(machineRecipeManagers.containsKey(machine1))
+ {
+ throw new IllegalArgumentException("Recipe manager for "+machine1+" already exist!");
+ }
+ machineRecipeManagers.put(machine1, this);
+ }
+
+ private final Map<UniversalRecipeInput, UniversalRecipeOutput> recipes = new HashMap();
+
+ public void addRecipe(UniversalRecipeInput input, UniversalRecipeOutput output)
+ {
+ if (input == null)
+ {
+ throw new NullPointerException("The recipe input is null");
+ }
+ else
+ {
+ if (output.getFluidOutputs() == null || output.getItemOutputs() == null ||(output.getFluidOutputs().size()==0 && output.getItemOutputs().size()==0))
+ {
+ throw new NullPointerException("The output is empty");
+ }
+ }
+
+ Iterator var8 = this.recipes.keySet().iterator();
+
+ while (var8.hasNext())
+ {
+ UniversalRecipeInput existingInput = (UniversalRecipeInput)var8.next();
+ if (existingInput.matches(input))
+ {
+ Iterator<IRecipeInput> ilist1 = existingInput.getItemInputs().iterator();
+ Iterator<IRecipeInput> ilist2 = input.getItemInputs().iterator();
+ while(ilist1.hasNext())
+ {
+ IRecipeInput is = ilist1.next();
+ }
+ System.out.println("recipe 2:");
+ while(ilist2.hasNext())
+ {
+ IRecipeInput is = ilist2.next();
+ }
+ throw new RuntimeException("Ambiguous recipe.");
+ }
+ }
+
+ this.recipes.put(input, output);
+ }
+
+
+ public UniversalRecipeOutput getOutputFor(List<FluidStack> fluidInputs, List<ItemStack> itemInputs, boolean adjustInput, boolean inputAffectOutput)
+ {
+ if (fluidInputs == null && itemInputs == null)
+ {
+ return null;
+ }
+ else
+ {
+ Iterator i$ = this.recipes.entrySet().iterator();
+
+ while (true)
+ {
+ if (i$.hasNext())
+ {
+ Entry entry = (Entry)i$.next();
+ UniversalRecipeInput recipeInput = (UniversalRecipeInput)entry.getKey();
+
+ if (!recipeInput.matches(fluidInputs, itemInputs))
+ {
+ continue;
+ }
+
+ if (recipeInput.adjustAmounts(fluidInputs, itemInputs,true, false))
+ {
+ UniversalRecipeOutput output = (UniversalRecipeOutput)entry.getValue();
+ if (adjustInput)
+ {
+ if(inputAffectOutput)
+ {
+ int multiplier = recipeInput.getMultiplierAndAdjustAmounts(fluidInputs, itemInputs);
+ return output.copyWithMultiplier(multiplier);
+ }
+ else
+ {
+ recipeInput.adjustAmounts(fluidInputs, itemInputs,true, true);
+ }
+ }
+ return output;
+ }
+ }
+
+ return null;
+ }
+ }
+ }
+
+ public Map<UniversalRecipeInput, UniversalRecipeOutput> getRecipes()
+ {
+ return this.recipes;
+ }
+
+
+ public UniversalRecipeInput getRecipeInput(List<FluidStack> fluidInputs1, List<ItemStack> itemInputs1) {
+ {
+ Iterator i$ = this.recipes.entrySet().iterator();
+
+ while (true)
+ {
+ if (i$.hasNext())
+ {
+ Entry entry = (Entry)i$.next();
+ UniversalRecipeInput recipeInput = (UniversalRecipeInput)entry.getKey();
+
+ if (!recipeInput.matches(fluidInputs1,itemInputs1))
+ {
+ continue;
+ }
+
+ if (recipeInput.adjustAmounts(fluidInputs1,itemInputs1,true, false))
+ {
+ return recipeInput;
+ }
+ }
+
+ return null;
+ }
+ }
+ }
+
+
+ public UniversalRecipeOutput getOutputFor(List[] input, boolean adjustInput, boolean inputAffectOutput)
+ {
+ return this.getOutputFor(input[0], input[1], adjustInput, inputAffectOutput);
+ }
+
+
+ public UniversalRecipeInput getRecipeInput(List[] input)
+ {
+ return this.getRecipeInput(input[0], input[1]);
+ }
+
+
+ public void removeRecipeByInput(UniversalRecipeInput uRecipeInput)
+ {
+ Entry entryToRemove = null;
+ List<FluidStack> fluidInputs = IHLUtils.convertRecipeInputToFluidStackList(uRecipeInput.getFluidInputs());
+ List<ItemStack> itemInputs = IHLUtils.convertRecipeInputToItemStackList(uRecipeInput.getItemInputs());
+ {
+ Iterator i$ = this.recipes.entrySet().iterator();
+ while (i$.hasNext())
+ {
+ Entry entry = (Entry)i$.next();
+ UniversalRecipeInput recipeInput = (UniversalRecipeInput)entry.getKey();
+ if (recipeInput.matches(fluidInputs, itemInputs))
+ {
+ i$.remove();
+ break;
+ }
+ }
+ }
+ }
+
+ public void removeRecipeByOutput(UniversalRecipeOutput uRecipeOutput)
+ {
+ Entry entryToRemove = null;
+ Iterator i$ = this.recipes.entrySet().iterator();
+ while (i$.hasNext())
+ {
+ Entry entry = (Entry)i$.next();
+ UniversalRecipeOutput recipeOutput = (UniversalRecipeOutput)entry.getValue();
+ if (recipeOutputHasCommonEntries(recipeOutput,uRecipeOutput))
+ {
+ i$.remove();
+ }
+ }
+ }
+
+ public boolean recipeOutputHasCommonEntries(UniversalRecipeOutput out, UniversalRecipeOutput out1)
+ {
+ List<FluidStack> fluidOutputs = out.getFluidOutputs();
+ List<RecipeOutputItemStack> itemOutputs = out.getItemOutputs();
+ if(!fluidOutputs.isEmpty() && !out1.getFluidOutputs().isEmpty())
+ {
+ FluidStack fs1 = out1.getFluidOutputs().get(0);
+ Iterator<FluidStack> fi = fluidOutputs.iterator();
+ while(fi.hasNext())
+ {
+ FluidStack fs = fi.next();
+ if(fs.getFluid()==fs1.getFluid())
+ {
+ return true;
+ }
+ }
+ }
+ if(!itemOutputs.isEmpty() && !out1.getItemOutputs().isEmpty())
+ {
+ RecipeOutputItemStack is1 = out1.getItemOutputs().get(0);
+ Iterator<RecipeOutputItemStack> ii = itemOutputs.iterator();
+ while(ii.hasNext())
+ {
+ RecipeOutputItemStack is = ii.next();
+ if(is.matches(is1))
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+}
diff --git a/ihl/recipes/UniversalRecipeOutput.java b/ihl/recipes/UniversalRecipeOutput.java
new file mode 100644
index 0000000..bda2bcf
--- /dev/null
+++ b/ihl/recipes/UniversalRecipeOutput.java
@@ -0,0 +1,145 @@
+package ihl.recipes;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import net.minecraft.item.ItemStack;
+import net.minecraftforge.fluids.FluidStack;
+
+public class UniversalRecipeOutput{
+
+ private final List<FluidStack> fluidOutputs=new ArrayList();
+ private final List<RecipeOutputItemStack> itemOutputs=new ArrayList();
+ private final int time;
+ public final boolean specialConditions;
+
+ public UniversalRecipeOutput(List<FluidStack> fluidOutputs1, List itemOutputs1, int time1)
+ {
+ this(fluidOutputs1, itemOutputs1, time1,false);
+ }
+
+ public UniversalRecipeOutput(List<FluidStack> fluidOutputs1, List itemOutputs1, int time1, boolean specialConditions1)
+ {
+ if(fluidOutputs1!=null)
+ {
+ Iterator<FluidStack> ioi = fluidOutputs1.iterator();
+ while(ioi.hasNext())
+ {
+ FluidStack fStack = ioi.next();
+ if(fStack==null)
+ {
+ throw new NullPointerException("Recipe cannot contain null elements!");
+ }
+ fluidOutputs.add(fStack);
+ }
+ }
+ if(itemOutputs1!=null)
+ {
+ Iterator ioi = itemOutputs1.iterator();
+ while(ioi.hasNext())
+ {
+ Object io = ioi.next();
+ if(io==null)
+ {
+ throw new NullPointerException("Recipe output cannot be null!");
+ }
+ if(io instanceof ItemStack)
+ {
+ this.itemOutputs.add(new RecipeOutputItemStack((ItemStack) io));
+ }
+ else
+ {
+ this.itemOutputs.add((RecipeOutputItemStack) io);
+ }
+ }
+ }
+ specialConditions=specialConditions1;
+ time=time1;
+ }
+
+ public boolean matches(List<FluidStack> fluidOutputs1, List<ItemStack> itemOutputs1)
+ {
+ if(fluidOutputs.size()!=fluidOutputs1.size()||itemOutputs.size()!=itemOutputs.size())
+ {
+ return false;
+ }
+ Iterator<FluidStack> fi1 = fluidOutputs1.iterator();
+ Iterator<ItemStack> ii1 = itemOutputs1.iterator();
+ Iterator<FluidStack> fi = fluidOutputs.iterator();
+ Iterator<RecipeOutputItemStack> ii = itemOutputs.iterator();
+ while(fi.hasNext())
+ {
+ FluidStack fs = fi.next();
+ FluidStack fs1 = fi1.next();
+ if(fs.getFluid()!=fs1.getFluid())
+ {
+ return false;
+ }
+ }
+ while(ii.hasNext())
+ {
+ RecipeOutputItemStack is = ii.next();
+ ItemStack is1 = ii1.next();
+ if(!is.matches(is1))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public List<FluidStack> getFluidOutputs() {
+ return fluidOutputs;
+ }
+
+ public List<RecipeOutputItemStack> getItemOutputs() {
+ return itemOutputs;
+ }
+
+ public UniversalRecipeOutput copyWithMultiplier(int mulipier) {
+ ArrayList<FluidStack> fluidStacks = new ArrayList<FluidStack>();
+ ArrayList<RecipeOutputItemStack> itemStacks = new ArrayList<RecipeOutputItemStack>();
+ if(fluidOutputs!=null && !fluidOutputs.isEmpty())
+ {
+ Iterator<FluidStack> fi = fluidOutputs.iterator();
+ while(fi.hasNext())
+ {
+ FluidStack fs = fi.next();
+ FluidStack newFs = fs.copy();
+ newFs.amount*=mulipier;
+ fluidStacks.add(newFs);
+ }
+ }
+ if(itemOutputs!=null && !itemOutputs.isEmpty())
+ {
+ Iterator<RecipeOutputItemStack> ii = itemOutputs.iterator();
+ while(ii.hasNext())
+ {
+ RecipeOutputItemStack is = ii.next();
+ RecipeOutputItemStack newIs = is.copy(mulipier);
+ itemStacks.add(newIs);
+ }
+ }
+ return new UniversalRecipeOutput(fluidStacks,itemStacks, getTime(),false);
+ }
+
+ public int getTime() {
+ return time;
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuffer out = new StringBuffer();
+ for(FluidStack fluid: this.fluidOutputs)
+ {
+ out.append(fluid.getLocalizedName()+": "+fluid.amount+"/n");
+ }
+ for(RecipeOutputItemStack stack: this.itemOutputs)
+ {
+ out.append(stack.itemStack.getDisplayName()+": "+stack.quantity+"/n");
+ }
+ return out.toString();
+ }
+}