From 1f7b870f378f7fd71eed910e984fd45ccffb17f0 Mon Sep 17 00:00:00 2001 From: Jason Mitchell Date: Tue, 29 Oct 2019 20:22:42 -0700 Subject: More gracefully handle nulls in LCR recipes --- src/main/java/gregtech/api/util/GT_Recipe.java | 56 +++++++++++++++----------- 1 file changed, 32 insertions(+), 24 deletions(-) (limited to 'src/main/java/gregtech/api/util/GT_Recipe.java') diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index 5a5ba21fa4..17f54b6f53 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -814,7 +814,7 @@ public class GT_Recipe implements Comparable { if (aInputs == null) return null; int tAmount = 0; for (ItemStack aInput : aInputs) if (aInput != null) tAmount++; - if (tAmount < mMinimalInputItems) return null; + if (tAmount < mMinimalInputItems) return null; } } @@ -1592,9 +1592,12 @@ public class GT_Recipe implements Comparable { if (aInputs == null) { aInputs = new ItemStack[0]; + } else { + aInputs = GT_Utility.getArrayListWithoutTrailingNulls(aInputs).toArray(new ItemStack[0]); } + for (ItemStack input : aInputs) { - FluidStack inputFluidContent = FluidContainerRegistry.getFluidForFilledItem(input); + FluidStack inputFluidContent = FluidContainerRegistry.getFluidForFilledItem(input); if (inputFluidContent != null) { inputFluidContent.amount *= input.stackSize; if (inputFluidContent.getFluid().getName().equals("ic2steam")) { @@ -1628,8 +1631,11 @@ public class GT_Recipe implements Comparable { } aInputs = adjustedInputs.toArray(new ItemStack[adjustedInputs.size()]); aFluidInputs = adjustedFluidInputs.toArray(new FluidStack[adjustedFluidInputs.size()]); + if (aOutputs == null) { aOutputs = new ItemStack[0]; + } else { + aOutputs = GT_Utility.getArrayListWithoutTrailingNulls(aOutputs).toArray(new ItemStack[0]); } for (ItemStack output : aOutputs) { @@ -1677,34 +1683,36 @@ public class GT_Recipe implements Comparable { ArrayList inputStacks = new ArrayList(inputlimit); for (int i = 0; i < itemLimit; i++, j++) { - if (GT_Values.allow_broken_recipemap) { - if (this != null && this.mInputs != null && this.mInputs[i] != null) - inputStacks.add(new FixedPositionedStack(this.mInputs[i].copy(), 48 - j % 3 * 18, (j >= 3 ? 5 : 23))); - else { - if (this.mOutputs != null && this.mOutputs.length > 0 && this.mOutputs[0] != null) - GT_Log.out.println("recipe " + this.toString() + " Output 0:" + this.mOutputs[0].getDisplayName() + " has errored!"); - else - GT_Log.out.println("recipe " + this.toString() + " has errored!"); - inputStacks.add(new FixedPositionedStack(new ItemStack(Items.command_block_minecart), 48 - j % 3 * 18, (j >= 3 ? 5 : 23))); - } - }else + if( this.mInputs == null || (this.mInputs[i] == null && (i == 0 && itemLimit == 1)) ) { + if (this.mOutputs != null && this.mOutputs.length > 0 && this.mOutputs[0] != null) + GT_Log.out.println("recipe " + this.toString() + " Output 0:" + this.mOutputs[0].getDisplayName() + " has errored!"); + else + GT_Log.out.println("recipe " + this.toString() + " has errored!"); + + new Exception("Recipe Fixme").printStackTrace(GT_Log.out); + } + + + if ((this.mInputs != null && this.mInputs[i] != null) || !GT_Values.allow_broken_recipemap) inputStacks.add(new FixedPositionedStack(this.mInputs[i].copy(), 48 - j % 3 * 18, (j >= 3 ? 5 : 23))); + else + inputStacks.add(new FixedPositionedStack(new ItemStack(Items.command_block_minecart), 48 - j % 3 * 18, (j >= 3 ? 5 : 23))); } for (int i = 0; i < fluidLimit; i++, j++) { - if (GT_Values.allow_broken_recipemap) { - if (this != null && this.mFluidInputs != null && this.mFluidInputs[i] != null) - inputStacks.add(new FixedPositionedStack(GT_Utility.getFluidDisplayStack(this.mFluidInputs[i], true), 48 - j % 3 * 18, (j >= 3 ? 5 : 23))); - else { - if (this.mOutputs != null && this.mOutputs.length > 0 && this.mOutputs[0] != null) - GT_Log.out.println("recipe " + this.toString() + " Output 0:" + this.mOutputs[0].getDisplayName() + " has errored!"); - else - GT_Log.out.println("recipe " + this.toString() + " has errored!"); - } - }else + if (this.mFluidInputs == null || this.mFluidInputs[i] == null) { + if (this.mOutputs != null && this.mOutputs.length > 0 && this.mOutputs[0] != null) + GT_Log.out.println("recipe " + this.toString() + " Output 0:" + this.mOutputs[0].getDisplayName() + " has errored!"); + else + GT_Log.out.println("recipe " + this.toString() + " has errored!"); + + new Exception("Recipe Fixme").printStackTrace(GT_Log.out); + } + + if ((this.mFluidInputs != null && this.mFluidInputs[i] != null) || !GT_Values.allow_broken_recipemap) inputStacks.add(new FixedPositionedStack(GT_Utility.getFluidDisplayStack(this.mFluidInputs[i], true), 48 - j % 3 * 18, (j >= 3 ? 5 : 23))); } - + return inputStacks; } -- cgit