From 2636ccdd67b5f33421ab7f9152021bc4ebc147b3 Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Tue, 7 Feb 2017 20:16:24 +0300 Subject: Fixed an ore dictionary recipes of Iron workbench which using wrong set of items. Fixed wire recipe input. All recipes of Iron workbench now use fluid container input and will drop an empty container. --- ihl/recipes/UniversalRecipeInput.java | 298 +++++++++++++--------------------- 1 file changed, 117 insertions(+), 181 deletions(-) (limited to 'ihl/recipes/UniversalRecipeInput.java') diff --git a/ihl/recipes/UniversalRecipeInput.java b/ihl/recipes/UniversalRecipeInput.java index 1d2b06c..62d6c87 100644 --- a/ihl/recipes/UniversalRecipeInput.java +++ b/ihl/recipes/UniversalRecipeInput.java @@ -13,74 +13,55 @@ import java.util.List; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; -public class UniversalRecipeInput{ +public class UniversalRecipeInput { - private final List fluidInputs=new ArrayList(); - private final List itemInputs=new ArrayList(); - private int multiplier=Integer.MAX_VALUE; - - public UniversalRecipeInput(Object[] fluidStacks, Object[] iRecipeInputs) - { - if(fluidStacks!=null) - { - for(Object material:fluidStacks) - { - 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(iRecipeInputs!=null) - { - for(Object material:iRecipeInputs) - { - 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); - } - } - } - } + private final List fluidInputs = new ArrayList(); + private final List itemInputs = new ArrayList(); + private int multiplier = Integer.MAX_VALUE; - public boolean matches(List fluidInputs1, List itemInputs1) - { + public UniversalRecipeInput(Object[] fluidStacks, Object[] iRecipeInputs) { + if (fluidStacks != null) { + for (Object material : fluidStacks) { + 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 (iRecipeInputs != null) { + for (Object material : iRecipeInputs) { + 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 fluidInputs1, List itemInputs1) { return this.adjustAmounts(fluidInputs1, itemInputs1, false, false); } public List getFluidInputs() { return fluidInputs; } - + public List getItemInputs() { return itemInputs; } @@ -89,119 +70,91 @@ public class UniversalRecipeInput{ List rInputs = input.getItemInputs(); Iterator ii = rInputs.iterator(); List rInputsItems = new ArrayList(); - while(ii.hasNext()) - { + while (ii.hasNext()) { IRecipeInput is = ii.next(); rInputsItems.add(is.getInputs().get(0)); } List rInputsFluids = new ArrayList(); List rInputsF = input.getFluidInputs(); Iterator iiF = rInputsF.iterator(); - while(iiF.hasNext()) - { + while (iiF.hasNext()) { IRecipeInputFluid is = iiF.next(); rInputsFluids.add(is.getInputs().get(0)); } return this.matches(rInputsFluids, rInputsItems); } - - public boolean adjustAmounts(List fluidInputs1, List itemInputs1, boolean doCheckAmounts, boolean doAdjustAmounts) - { - this.multiplier=Integer.MAX_VALUE; - if(incorrectInputAmount(fluidInputs1, itemInputs1)) - { + + public boolean adjustAmounts(List fluidInputs1, List itemInputs1, boolean doCheckAmounts, + boolean doAdjustAmounts) { + this.multiplier = Integer.MAX_VALUE; + if (incorrectInputAmount(fluidInputs1, itemInputs1)) { return false; } - if(fluidInputs1!=null) - { - Iterator 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.amount0) - { - int multiplier1=fs1.amount/fs.getAmount(); - if(multiplier1 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; } - fs1.amount-=fs.getAmount(); - if(fs1.amount<=0)fs1=null; } } - } - if(itemInputs1!=null) - { - Iterator 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.stackSize0) - { - int multiplier1=is1.stackSize/is.getAmount(); - if(multiplier1 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; } - } - if(IHLUtils.reduceItemStackAmountUsingIRecipeInput(is, is1)) - { - is1=null; } } } - } return true; } - private ItemStack getMatchedItemStack(IRecipeInput is, List itemInputs1) - { - for(ItemStack is1:itemInputs1) - { - if(is1!=null) - { - if(is.matches(is1)) - { + private ItemStack getMatchedItemStack(IRecipeInput is, List itemInputs1) { + for (ItemStack is1 : itemInputs1) { + if (is1 != null) { + if (is.matches(is1)) { return is1; } - } + } } return null; } - private FluidStack getMatchedFluidStack(IRecipeInputFluid fs, List fluidInputs1) - { - for(FluidStack fs1:fluidInputs1) - { - if(fs.matches(fs1)) - { + private FluidStack getMatchedFluidStack(IRecipeInputFluid fs, List fluidInputs1) { + for (FluidStack fs1 : fluidInputs1) { + if (fs.matches(fs1)) { return fs1; } } @@ -212,79 +165,62 @@ public class UniversalRecipeInput{ List rInputs = input.getItemInputs(); Iterator ii = rInputs.iterator(); List rInputsItems = new ArrayList(); - while(ii.hasNext()) - { + while (ii.hasNext()) { IRecipeInput is = ii.next(); rInputsItems.add(is.getInputs().get(0)); } List rInputsFluids = new ArrayList(); List rInputsF = input.getFluidInputs(); Iterator iiF = rInputsF.iterator(); - while(iiF.hasNext()) - { + while (iiF.hasNext()) { IRecipeInputFluid is = iiF.next(); rInputsFluids.add(is.getInputs().get(0)); } return this.adjustAmounts(rInputsFluids, rInputsItems, true, doAdjustAmounts); } - public int getMultiplierAndAdjustAmounts(List fluidInputs1, List itemInputs1) - { - if(this.adjustAmounts(fluidInputs1, itemInputs1, true, true)) - { - if(multiplier fluidInputs1, List itemInputs1) { + if (this.adjustAmounts(fluidInputs1, itemInputs1, true, true)) { + if (multiplier < Integer.MAX_VALUE) { return multiplier; - } - else return 1; - } - else - { + } else + return 1; + } else { return 0; } } - public boolean containItemStack(ItemStack ingredient) - { - if(itemInputs==null || itemInputs.isEmpty()) - { + public boolean containItemStack(ItemStack ingredient) { + if (itemInputs == null || itemInputs.isEmpty()) { return false; } Iterator ii = itemInputs.iterator(); - while(ii.hasNext()) - { + while (ii.hasNext()) { IRecipeInput is = ii.next(); - if(is.matches(ingredient)) - { + if (is.matches(ingredient)) { return true; } } return false; } - public boolean containFluidStack(FluidStack fluidStack) - { - if(fluidInputs==null || fluidInputs.isEmpty()) - { + public boolean containFluidStack(FluidStack fluidStack) { + if (fluidInputs == null || fluidInputs.isEmpty()) { return false; } Iterator ii = fluidInputs.iterator(); - while(ii.hasNext()) - { + while (ii.hasNext()) { IRecipeInputFluid is = ii.next(); - if(is!=null && is.matches(fluidStack)) - { + if (is != null && is.matches(fluidStack)) { return true; } } return false; } - - private boolean incorrectInputAmount(List fluidInputs1, List itemInputs1) - { - return (fluidInputs.size()>0 && fluidInputs1==null)|| - (itemInputs.size()>0 && itemInputs1==null)|| - (fluidInputs1!=null && fluidInputs.size()>fluidInputs1.size())|| - (itemInputs1!=null && itemInputs.size()>itemInputs1.size()); + + private boolean incorrectInputAmount(List fluidInputs1, List itemInputs1) { + return (fluidInputs.size() > 0 && fluidInputs1 == null) || (itemInputs.size() > 0 && itemInputs1 == null) + || (fluidInputs1 != null && fluidInputs.size() > fluidInputs1.size()) + || (itemInputs1 != null && itemInputs.size() > itemInputs1.size()); } } -- cgit v1.2.3