Added extra validation to recipe inputs and outputs, fixed one bug because of it.

This commit is contained in:
modmuss50 2016-12-05 11:18:30 +00:00
parent b1e00e6ce7
commit d53f4dafc1
18 changed files with 40 additions and 29 deletions

View file

@ -4,6 +4,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import reborncore.api.recipe.IBaseRecipeType;
import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.List;
@ -12,7 +13,7 @@ import java.util.List;
*/
public abstract class BaseRecipe implements IBaseRecipeType, Cloneable {
public ArrayList<ItemStack> inputs;
private ArrayList<ItemStack> inputs;
public String name;
public int tickTime;
public int euPerTick;
@ -38,6 +39,9 @@ public abstract class BaseRecipe implements IBaseRecipeType, Cloneable {
}
public void addOutput(ItemStack stack) {
if(stack == null || stack.isEmpty()){
throw new InvalidParameterException("output is invalid!");
}
outputs.add(stack);
}
@ -91,4 +95,11 @@ public abstract class BaseRecipe implements IBaseRecipeType, Cloneable {
public List<ItemStack> getOutputs() {
return outputs;
}
public void addInput(ItemStack inuput){
if(inuput == null || inuput.isEmpty()){
throw new InvalidParameterException("input is invalid!");
}
inputs.add(inuput);
}
}

View file

@ -9,7 +9,7 @@ public class RecyclerRecipe extends BaseRecipe {
public RecyclerRecipe(ItemStack input) {
super(Reference.recyclerRecipe, 0, 0);
inputs.add(input);
addInput(input);
addOutput(TechRebornAPI.subItemRetriever.getPartByName("scrap"));
}

View file

@ -8,7 +8,7 @@ public class ScrapboxRecipe extends BaseRecipe {
public ScrapboxRecipe(ItemStack output) {
super(Reference.scrapboxRecipe, 0, 0);
inputs.add(new ItemStack(TechRebornAPI.getItem("scrapBox")));
addInput(new ItemStack(TechRebornAPI.getItem("scrapBox")));
addOutput(output);
}

View file

@ -9,9 +9,9 @@ public class AlloySmelterRecipe extends BaseRecipe {
public AlloySmelterRecipe(ItemStack input1, ItemStack input2, ItemStack output1, int tickTime, int euPerTick) {
super(Reference.alloySmelteRecipe, tickTime, euPerTick);
if (input1 != null)
inputs.add(input1);
addInput(input1);
if (input2 != null)
inputs.add(input2);
addInput(input2);
if (output1 != null)
addOutput(output1);
}

View file

@ -9,9 +9,9 @@ public class AssemblingMachineRecipe extends BaseRecipe {
public AssemblingMachineRecipe(ItemStack input1, ItemStack input2, ItemStack output1, int tickTime, int euPerTick) {
super(Reference.assemblingMachineRecipe, tickTime, euPerTick);
if (input1 != null)
inputs.add(input1);
addInput(input1);
if (input2 != null)
inputs.add(input2);
addInput(input2);
if (output1 != null)
addOutput(output1);
}

View file

@ -12,9 +12,9 @@ public class BlastFurnaceRecipe extends BaseRecipe {
int euPerTick, int neededHeat) {
super(Reference.blastFurnaceRecipe, tickTime, euPerTick);
if (input1 != null)
inputs.add(input1);
addInput(input1);
if (input2 != null)
inputs.add(input2);
addInput(input2);
if (output1 != null)
addOutput(output1);
if (output2 != null)

View file

@ -12,9 +12,9 @@ public class CentrifugeRecipe extends BaseRecipe {
ItemStack output4, int tickTime, int euPerTick) {
super(Reference.centrifugeRecipe, tickTime, euPerTick);
if (input1 != null)
inputs.add(input1);
addInput(input1);
if (input2 != null)
inputs.add(input2);
addInput(input2);
if (output1 != null)
addOutput(output1);
if (output2 != null)

View file

@ -9,9 +9,9 @@ public class ChemicalReactorRecipe extends BaseRecipe {
public ChemicalReactorRecipe(ItemStack input1, ItemStack input2, ItemStack output1, int tickTime, int euPerTick) {
super(Reference.chemicalReactorRecipe, tickTime, euPerTick);
if (input1 != null)
inputs.add(input1);
addInput(input1);
if (input2 != null)
inputs.add(input2);
addInput(input2);
if (output1 != null)
addOutput(output1);
}

View file

@ -9,7 +9,7 @@ public class CompressorRecipe extends BaseRecipe {
public CompressorRecipe(ItemStack input1, ItemStack output1, int tickTime, int euPerTick) {
super(Reference.compressorRecipe, tickTime, euPerTick);
if (input1 != null)
inputs.add(input1);
addInput(input1);
if (output1 != null)
addOutput(output1);
}

View file

@ -11,7 +11,7 @@ public class ExtractorRecipe extends BaseRecipe {
public ExtractorRecipe(ItemStack input1, ItemStack output1, int tickTime, int euPerTick) {
super(Reference.extractorRecipe, tickTime, euPerTick);
if (input1 != null)
inputs.add(input1);
addInput(input1);
if (output1 != null)
addOutput(output1);
}

View file

@ -9,7 +9,7 @@ public class GrinderRecipe extends BaseRecipe {
public GrinderRecipe(ItemStack input1, ItemStack output1, int tickTime, int euPerTick) {
super(Reference.grinderRecipe, tickTime, euPerTick / 10); //Done to buff energy usage to be more in line with ic2
if (input1 != null)
inputs.add(input1);
addInput(input1);
if (output1 != null)
addOutput(output1);
}

View file

@ -10,9 +10,9 @@ public class ImplosionCompressorRecipe extends BaseRecipe {
int tickTime, int euPerTick) {
super(Reference.implosionCompressorRecipe, tickTime, euPerTick);
if (input1 != null)
inputs.add(input1);
addInput(input1);
if (input2 != null)
inputs.add(input2);
addInput(input2);
if (output1 != null)
addOutput(output1);
if (output2 != null)

View file

@ -12,9 +12,9 @@ public class IndustrialElectrolyzerRecipe extends BaseRecipe {
ItemStack output3, ItemStack output4, int tickTime, int euPerTick) {
super(Reference.industrialElectrolyzerRecipe, tickTime, euPerTick);
if (inputCells != null)
inputs.add(inputCells);
addInput(inputCells);
if (input2 != null)
inputs.add(input2);
addInput(input2);
if (output1 != null)
addOutput(output1);
if (output2 != null)

View file

@ -13,7 +13,7 @@ public class IndustrialGrinderRecipe extends BaseRecipe {
ItemStack output2, ItemStack output3, ItemStack output4, int tickTime, int euPerTick) {
super(Reference.industrialGrinderRecipe, tickTime, (int) (euPerTick / 2.5)); // Buff energy usage to be more in line with other machines
if (input1 != null)
inputs.add(input1);
addInput(input1);
if (output1 != null)
addOutput(output1);
if (output2 != null)

View file

@ -15,9 +15,9 @@ public class IndustrialSawmillRecipe extends BaseRecipe {
ItemStack output2, ItemStack output3, int tickTime, int euPerTick) {
super(Reference.industrialSawmillRecipe, tickTime, euPerTick);
if (input1 != null)
inputs.add(input1);
addInput(input1);
if (input2 != null)
inputs.add(input2);
addInput(input2);
if (output1 != null)
addOutput(output1);
if (output2 != null)
@ -31,9 +31,9 @@ public class IndustrialSawmillRecipe extends BaseRecipe {
ItemStack output2, ItemStack output3, int tickTime, int euPerTick, boolean canUseOreDict) {
super(Reference.industrialSawmillRecipe, tickTime, euPerTick);
if (input1 != null)
inputs.add(input1);
addInput(input1);
if (input2 != null)
inputs.add(input2);
addInput(input2);
if (output1 != null)
addOutput(output1);
if (output2 != null)

View file

@ -9,7 +9,7 @@ public class PlateCuttingMachineRecipe extends BaseRecipe {
public PlateCuttingMachineRecipe(ItemStack input1, ItemStack output1, int tickTime, int euPerTick) {
super(Reference.plateCuttingMachineRecipe, tickTime, euPerTick);
if (input1 != null)
inputs.add(input1);
addInput(input1);
if (output1 != null)
addOutput(output1);
}

View file

@ -9,7 +9,7 @@ public class VacuumFreezerRecipe extends BaseRecipe {
public VacuumFreezerRecipe(ItemStack input, ItemStack output, int tickTime, int euPerTick) {
super(Reference.vacuumFreezerRecipe, tickTime, euPerTick);
if (input != null)
inputs.add(input);
addInput(input);
if (output != null)
addOutput(output);
}

View file

@ -443,13 +443,13 @@ public class ModRecipes {
data[1].equals("aluminium") ||
data[1].equals("iridium") ||
data[1].equals("saltpeter")) ||
oreStack == null)
oreStack == ItemStack.EMPTY)
continue;
boolean ore = data[0].equals("ore");
Core.logHelper.debug("Ore: " + data[1]);
ItemStack dust = getDictOreOrNull(joinDictName("dust", data[1]), ore ? 2 : 1);
if (dust == null || dust.getItem() == null) {
if (dust == ItemStack.EMPTY || dust.getItem() == null) {
continue;
}
dust = dust.copy();