From de9e9e44a1e646b99411f328d6ae4c8650286c07 Mon Sep 17 00:00:00 2001 From: CrazyPants Date: Sat, 29 Nov 2014 21:33:24 +0800 Subject: [PATCH] #1312 Incorrect number of items used in Alloy Smelter recipe --- ReleaseNotes.txt | 1 + .../enderio/machine/MachineRecipeInput.java | 12 +++- .../machine/recipe/AbstractMachineRecipe.java | 70 ++++++++++++++++--- 3 files changed, 72 insertions(+), 11 deletions(-) diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt index 8e1804f8..932e4674 100644 --- a/ReleaseNotes.txt +++ b/ReleaseNotes.txt @@ -40,6 +40,7 @@ Bugs - #1280 The Ender Sword holds 1m RF but only shows 100k - #1298 Painted Blocks for biome specific Blocks render grey - #1300 Farming Station won't take MFR Rubber trees +- #1312 Incorrect number of items used in Alloy Smelter recipe diff --git a/src/main/java/crazypants/enderio/machine/MachineRecipeInput.java b/src/main/java/crazypants/enderio/machine/MachineRecipeInput.java index 2d161322..8b581ed8 100644 --- a/src/main/java/crazypants/enderio/machine/MachineRecipeInput.java +++ b/src/main/java/crazypants/enderio/machine/MachineRecipeInput.java @@ -27,12 +27,12 @@ public class MachineRecipeInput { public MachineRecipeInput(int slotNumber, ItemStack item) { this.slotNumber = slotNumber; this.item = item; - this.fluid = null; + fluid = null; } public MachineRecipeInput(int slotNumber, FluidStack fluid) { this.slotNumber = slotNumber; - this.item = null; + item = null; this.fluid = fluid; } @@ -42,6 +42,14 @@ public class MachineRecipeInput { this.fluid = fluid; } + public MachineRecipeInput copy() { + if(isFluid()) { + return new MachineRecipeInput(slotNumber, fluid.copy()); + } else { + return new MachineRecipeInput(slotNumber, item == null ? (ItemStack) null : item.copy()); + } + } + public static MachineRecipeInput readFromNBT(NBTTagCompound root) { int slotNum = root.getInteger("slotNum"); ItemStack item = null; diff --git a/src/main/java/crazypants/enderio/machine/recipe/AbstractMachineRecipe.java b/src/main/java/crazypants/enderio/machine/recipe/AbstractMachineRecipe.java index f5eeac4e..c497c18b 100644 --- a/src/main/java/crazypants/enderio/machine/recipe/AbstractMachineRecipe.java +++ b/src/main/java/crazypants/enderio/machine/recipe/AbstractMachineRecipe.java @@ -22,16 +22,28 @@ public abstract class AbstractMachineRecipe implements IMachineRecipe { @Override public List getQuantitiesConsumed(MachineRecipeInput[] inputs) { - IRecipe rec = getRecipeForInputs(inputs); + IRecipe recipe = getRecipeForInputs(inputs); List result = new ArrayList(); - for (RecipeInput ri : rec.getInputs()) { - for (MachineRecipeInput input : inputs) { - if(input != null && (input.item != null || input.fluid != null)) { - if(ri.isInput(input.item) && (ri.getSlotNumber() == -1 || ri.getSlotNumber() == input.slotNumber)) { - result.add(new MachineRecipeInput(input.slotNumber, ri.getInput().copy())); - break; - } else if(ri.isInput(input.fluid)) { - result.add(new MachineRecipeInput(input.slotNumber, ri.getFluidInput().copy())); + + //Need to make copies so we can reduce their values as we go + MachineRecipeInput[] availableInputs = new MachineRecipeInput[inputs.length]; + int i = 0; + for (MachineRecipeInput available : inputs) { + availableInputs[i] = available.copy(); + ++i; + } + RecipeInput[] requiredIngredients = new RecipeInput[recipe.getInputs().length]; + i = 0; + for (RecipeInput ri : recipe.getInputs()) { + requiredIngredients[i] = ri.copy(); + ++i; + } + + //For each input required by the recipe got through the available machine inputs and consume them + for (RecipeInput required : requiredIngredients) { + for (MachineRecipeInput available : availableInputs) { + if(isValid(available)) { + if(consume(required, available, result)) { break; } } @@ -40,6 +52,46 @@ public abstract class AbstractMachineRecipe implements IMachineRecipe { return result; } + protected boolean consume(RecipeInput required, MachineRecipeInput available, List consumedInputs) { + + if(required.isInput(available.fluid)) { + consumedInputs.add(new MachineRecipeInput(available.slotNumber, required.getFluidInput().copy())); + return true; + } + + + if(required.isInput(available.item) && (required.getSlotNumber() == -1 || required.getSlotNumber() == available.slotNumber)) { + + ItemStack availableStack = available.item; + ItemStack requiredStack = required.getInput(); + + ItemStack comsumedStack = requiredStack.copy(); + comsumedStack.stackSize = Math.min(requiredStack.stackSize, availableStack.stackSize); + + requiredStack.stackSize -= comsumedStack.stackSize; + availableStack.stackSize -= comsumedStack.stackSize; + + consumedInputs.add(new MachineRecipeInput(available.slotNumber, comsumedStack)); + + if(requiredStack.stackSize <= 0) { + //Fully met the requirement + return true; + } + + } + return false; + } + + protected boolean isValid(MachineRecipeInput input) { + if(input == null) { + return false; + } + if(input.item != null && input.item.stackSize > 0) { + return true; + } + return input.fluid != null && input.fluid.amount > 0; + } + @Override public float getExperianceForOutput(ItemStack output) { return 0;