#1312 Incorrect number of items used in Alloy Smelter recipe

This commit is contained in:
CrazyPants committed 2014-11-29 21:33:24 +08:00
1 parent f7d04bf3c0
commit de9e9e44a1
3 files changed
+72 -11

No files matched your search

@@ -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;
@@ -22,16 +22,28 @@ public abstract class AbstractMachineRecipe implements IMachineRecipe {
@Override
public List<MachineRecipeInput> getQuantitiesConsumed(MachineRecipeInput[] inputs) {
IRecipe rec = getRecipeForInputs(inputs);
IRecipe recipe = getRecipeForInputs(inputs);
List<MachineRecipeInput> result = new ArrayList<MachineRecipeInput>();
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<MachineRecipeInput> 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;