diff options
author | Maxim <maxim235@gmx.de> | 2023-06-19 11:13:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-19 11:13:11 +0200 |
commit | 756d3f2ac6946c21e07db4e5fb38986adc5a31f6 (patch) | |
tree | f443c437f184ee319f31f88ebf640e9891122a81 /src/main | |
parent | 44b532bbcebb78f8732c3f0528457b89656be2f7 (diff) | |
download | GT5-Unofficial-756d3f2ac6946c21e07db4e5fb38986adc5a31f6.tar.gz GT5-Unofficial-756d3f2ac6946c21e07db4e5fb38986adc5a31f6.tar.bz2 GT5-Unofficial-756d3f2ac6946c21e07db4e5fb38986adc5a31f6.zip |
Fix chunk corruption when using single recipe lock (#2092)
* Added null checks to single recipe check saving
* Removed left over brackets
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/gregtech/api/util/GT_Single_Recipe_Check.java | 77 |
1 files changed, 48 insertions, 29 deletions
diff --git a/src/main/java/gregtech/api/util/GT_Single_Recipe_Check.java b/src/main/java/gregtech/api/util/GT_Single_Recipe_Check.java index 733cca3b69..f939275e6c 100644 --- a/src/main/java/gregtech/api/util/GT_Single_Recipe_Check.java +++ b/src/main/java/gregtech/api/util/GT_Single_Recipe_Check.java @@ -197,38 +197,56 @@ public class GT_Single_Recipe_Check { // we don't yet have a mean to uniquely name a recipe, this will have to make do. // consider move serialization code to GT_Recipe once this has been proven to work NBTTagCompound tag = new NBTTagCompound(); - tag.setTag("inputs", writeList(recipe.mInputs, GT_Utility::saveItem)); - tag.setTag("outputs", writeList(recipe.mOutputs, GT_Utility::saveItem)); - tag.setIntArray("chances", recipe.mChances); - tag.setTag( - "fInputs", - writeList(recipe.mFluidInputs, s -> s == null ? new NBTTagCompound() : s.writeToNBT(new NBTTagCompound()))); - tag.setTag( - "fOutputs", - writeList( - recipe.mFluidOutputs, - s -> s == null ? new NBTTagCompound() : s.writeToNBT(new NBTTagCompound()))); + if (recipe == null) return tag; + + if (recipe.mInputs != null) { + tag.setTag("inputs", writeList(recipe.mInputs, GT_Utility::saveItem)); + } + if (recipe.mOutputs != null) { + tag.setTag("outputs", writeList(recipe.mOutputs, GT_Utility::saveItem)); + } + if (recipe.mChances != null) { + tag.setIntArray("chances", recipe.mChances); + } + if (recipe.mFluidInputs != null) { + tag.setTag( + "fInputs", + writeList( + recipe.mFluidInputs, + s -> s == null ? new NBTTagCompound() : s.writeToNBT(new NBTTagCompound()))); + } + if (recipe.mFluidOutputs != null) { + tag.setTag( + "fOutputs", + writeList( + recipe.mFluidOutputs, + s -> s == null ? new NBTTagCompound() : s.writeToNBT(new NBTTagCompound()))); + } tag.setInteger("eut", recipe.mEUt); tag.setInteger("duration", recipe.mDuration); tag.setInteger("specialValue", recipe.mSpecialValue); - tag.setTag("itemCost", writeList(itemCost.entrySet(), e -> { - NBTTagCompound ret = new NBTTagCompound(); - ret.setTag( - "id", - e.getKey() - .writeToNBT()); - ret.setInteger("count", e.getValue()); - return ret; - })); - tag.setTag("fluidCost", writeList(fluidCost.entrySet(), e -> { - NBTTagCompound ret = new NBTTagCompound(); - ret.setString( - "id", - e.getKey() - .getName()); - ret.setInteger("count", e.getValue()); - return ret; - })); + if (itemCost != null) { + tag.setTag("itemCost", writeList(itemCost.entrySet(), e -> { + NBTTagCompound ret = new NBTTagCompound(); + ret.setTag( + "id", + e.getKey() + .writeToNBT()); + ret.setInteger("count", e.getValue()); + return ret; + })); + } + if (fluidCost != null) { + tag.setTag("fluidCost", writeList(fluidCost.entrySet(), e -> { + NBTTagCompound ret = new NBTTagCompound(); + ret.setString( + "id", + e.getKey() + .getName()); + ret.setInteger("count", e.getValue()); + return ret; + })); + } return tag; } @@ -292,6 +310,7 @@ public class GT_Single_Recipe_Check { GT_Recipe found = recipeMap .findRecipe(parent.getBaseMetaTileEntity(), false, GT_Values.V[GT_Utility.getTier(eut)], fInputs, inputs); int[] chances = tag.getIntArray("chances"); + if (chances.length == 0) chances = null; if (found == null || !GT_Utility.equals(inputs, found.mInputs) || !Arrays.equals(fInputs, found.mFluidInputs) || !GT_Utility.equals(outputs, found.mOutputs) |