aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/metatileentity/implementations
diff options
context:
space:
mode:
authorGlease <4586901+Glease@users.noreply.github.com>2023-02-27 13:49:05 +0800
committerGitHub <noreply@github.com>2023-02-27 06:49:05 +0100
commit44824520ab2140f561a741bc486bc2f3459da2fe (patch)
tree5d81da726f4cb783a6b2369241a7613a2eeefff6 /src/main/java/gregtech/api/metatileentity/implementations
parentf04ae276af1346fb8ca5a022b21f5f372960ae13 (diff)
downloadGT5-Unofficial-44824520ab2140f561a741bc486bc2f3459da2fe.tar.gz
GT5-Unofficial-44824520ab2140f561a741bc486bc2f3459da2fe.tar.bz2
GT5-Unofficial-44824520ab2140f561a741bc486bc2f3459da2fe.zip
implement save & load for single recipe lock (#1771)
* implement save & load for single recipe lock * fix fat finger * fix NPE * disable machine if old locked recipe is gone * address reviews * spotless
Diffstat (limited to 'src/main/java/gregtech/api/metatileentity/implementations')
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java
index 57ec61e19d..7bbfd46b35 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java
@@ -20,6 +20,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
+import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
@@ -195,7 +196,11 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
aNBT.setInteger("mEfficiency", mEfficiency);
aNBT.setInteger("mPollution", mPollution);
aNBT.setInteger("mRuntime", mRuntime);
- aNBT.setBoolean("mLockedToSingleRecipe", mLockedToSingleRecipe);
+ if (supportsSingleRecipeLocking()) {
+ aNBT.setBoolean("mLockedToSingleRecipe", mLockedToSingleRecipe);
+ if (mLockedToSingleRecipe && mSingleRecipeCheck != null)
+ aNBT.setTag("mSingleRecipeCheck", mSingleRecipeCheck.writeToNBT());
+ }
if (mOutputItems != null) {
aNBT.setInteger("mOutputItemsLength", mOutputItems.length);
@@ -232,7 +237,16 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
mEfficiency = aNBT.getInteger("mEfficiency");
mPollution = aNBT.getInteger("mPollution");
mRuntime = aNBT.getInteger("mRuntime");
- mLockedToSingleRecipe = aNBT.getBoolean("mLockedToSingleRecipe");
+ if (supportsSingleRecipeLocking()) {
+ mLockedToSingleRecipe = aNBT.getBoolean("mLockedToSingleRecipe");
+ if (mLockedToSingleRecipe && aNBT.hasKey("mSingleRecipeCheck", Constants.NBT.TAG_COMPOUND)) {
+ GT_Single_Recipe_Check c = loadSingleRecipeChecker(aNBT.getCompoundTag("mSingleRecipeCheck"));
+ if (c != null) mSingleRecipeCheck = c;
+ // the old recipe is gone. we disable the machine to prevent making garbage in case of shared inputs
+ // maybe use a better way to inform player in the future.
+ else getBaseMetaTileEntity().disableWorking();
+ }
+ }
batchMode = aNBT.getBoolean(BATCH_MODE_NBT_KEY);
inputSeparation = aNBT.getBoolean(INPUT_SEPARATION_NBT_KEY);
voidExcess = aNBT.getBoolean(VOID_EXCESS_NBT_KEY);
@@ -259,6 +273,10 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
mCrowbar = aNBT.getBoolean("mCrowbar");
}
+ protected GT_Single_Recipe_Check loadSingleRecipeChecker(NBTTagCompound aNBT) {
+ return GT_Single_Recipe_Check.tryLoad(this, aNBT);
+ }
+
@Override
public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) {
GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer);