diff options
Diffstat (limited to 'src/main/java/gregtech/api')
17 files changed, 278 insertions, 91 deletions
diff --git a/src/main/java/gregtech/api/interfaces/modularui/ControllerWithOptionalFeatures.java b/src/main/java/gregtech/api/interfaces/modularui/ControllerWithOptionalFeatures.java index 66eee78822..8574de7007 100644 --- a/src/main/java/gregtech/api/interfaces/modularui/ControllerWithOptionalFeatures.java +++ b/src/main/java/gregtech/api/interfaces/modularui/ControllerWithOptionalFeatures.java @@ -368,7 +368,8 @@ public interface ControllerWithOptionalFeatures extends IVoidable, IRecipeLockab void setStructureUpdateTime(int time); default ButtonWidget createStructureUpdateButton(IWidgetBuilder<?> builder) { - Widget button = new ButtonWidget().setOnClick((clickData, widget) -> { setStructureUpdateTime(1); }) + Widget button = new ButtonWidget() + .setOnClick((clickData, widget) -> { if (getStructureUpdateTime() <= -20) setStructureUpdateTime(1); }) .setPlayClickSound(true) .setBackground(() -> { List<UITexture> ret = new ArrayList<>(); diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index eb26cd7883..27a6216cff 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java @@ -139,6 +139,7 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity GT_FML_LOGGER.error("Encountered CRITICAL ERROR while saving MetaTileEntity.", e); } try { + nbt.setBoolean("mWasShutdown", mWasShutdown); nbt.setInteger("mID", mID); nbt.setLong("mStoredSteam", mStoredSteam); nbt.setLong("mStoredEnergy", mStoredEnergy); @@ -158,6 +159,8 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity nbt.setBoolean("mInputDisabled", mInputDisabled); nbt.setBoolean("mOutputDisabled", mOutputDisabled); nbt.setTag("GT.CraftingComponents", mRecipeStuff); + nbt.setString("shutDownReasonID", getLastShutDownReason().getID()); + nbt.setTag("shutDownReason", getLastShutDownReason().writeToNBT(new NBTTagCompound())); } catch (Throwable e) { GT_FML_LOGGER.error("Encountered CRITICAL ERROR while saving MetaTileEntity.", e); } @@ -189,6 +192,14 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity mWorkData = aNBT.getByte("mWorkData"); mFacing = oFacing = ForgeDirection.getOrientation(aNBT.getShort("mFacing")); mOwnerName = aNBT.getString("mOwnerName"); + setShutdownStatus(aNBT.getBoolean("mWasShutdown")); + String shutDownReasonID = aNBT.getString("shutDownReasonID"); + if (ShutDownReasonRegistry.isRegistered(shutDownReasonID)) { + ShutDownReason reason = ShutDownReasonRegistry.getSampleFromRegistry(shutDownReasonID) + .newInstance(); + reason.readFromNBT(aNBT.getCompoundTag("shutDownReason")); + setShutDownReason(reason); + } try { mOwnerUuid = UUID.fromString(aNBT.getString("mOwnerUuid")); } catch (IllegalArgumentException e) { @@ -1040,7 +1051,7 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity public void enableWorking() { if (!mWorks) mWorkUpdate = true; mWorks = true; - mWasShutdown = false; + setShutdownStatus(false); } @Override 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 709191f10c..6c2df9b082 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 @@ -8,6 +8,7 @@ import static mcp.mobius.waila.api.SpecialChars.GREEN; import static mcp.mobius.waila.api.SpecialChars.RED; import static mcp.mobius.waila.api.SpecialChars.RESET; +import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -137,7 +138,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity protected boolean inputSeparation = getDefaultInputSeparationMode(); protected VoidingMode voidingMode = getDefaultVoidingMode(); protected boolean batchMode = getDefaultBatchMode(); - private @Nonnull CheckRecipeResult checkRecipeResult = CheckRecipeResultRegistry.NONE; + protected @Nonnull CheckRecipeResult checkRecipeResult = CheckRecipeResultRegistry.NONE; protected static final String INPUT_SEPARATION_NBT_KEY = "inputSeparation"; protected static final String VOID_EXCESS_NBT_KEY = "voidExcess"; @@ -160,7 +161,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity @SideOnly(Side.CLIENT) protected GT_SoundLoop activitySoundLoop; - private long mLastWorkingTick = 0; + protected long mLastWorkingTick = 0, mTotalRunTime = 0; private static final int CHECK_INTERVAL = 100; // How often should we check for a new recipe on an idle machine? private final int randomTickOffset = (int) (Math.random() * CHECK_INTERVAL + 1); @@ -236,6 +237,10 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity return mMaxProgresstime; } + public long getTotalRuntimeInTicks() { + return mTotalRunTime; + } + @Override public int increaseProgress(int aProgress) { return aProgress; @@ -250,6 +255,10 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity aNBT.setInteger("mEfficiency", mEfficiency); aNBT.setInteger("mPollution", mPollution); aNBT.setInteger("mRuntime", mRuntime); + aNBT.setLong("mTotalRunTime", mTotalRunTime); + aNBT.setLong("mLastWorkingTick", mLastWorkingTick); + aNBT.setString("checkRecipeResultID", checkRecipeResult.getID()); + aNBT.setTag("checkRecipeResult", checkRecipeResult.writeToNBT(new NBTTagCompound())); if (supportsMachineModeSwitch()) { aNBT.setInteger("machineMode", machineMode); @@ -296,6 +305,17 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity mEfficiency = aNBT.getInteger("mEfficiency"); mPollution = aNBT.getInteger("mPollution"); mRuntime = aNBT.getInteger("mRuntime"); + mTotalRunTime = aNBT.getLong("mTotalRunTime"); + mLastWorkingTick = aNBT.getLong("mLastWorkingTick"); + + String checkRecipeResultID = aNBT.getString("checkRecipeResultID"); + if (CheckRecipeResultRegistry.isRegistered(checkRecipeResultID)) { + CheckRecipeResult result = CheckRecipeResultRegistry.getSampleFromRegistry(checkRecipeResultID) + .newInstance(); + result.readFromNBT(aNBT.getCompoundTag("checkRecipeResult")); + checkRecipeResult = result; + } + if (aNBT.hasKey("machineMode")) { machineMode = aNBT.getInteger("machineMode"); } @@ -433,6 +453,8 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity @Override public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { if (aBaseMetaTileEntity.isServerSide()) { + // Time Counter + mTotalRunTime++; if (mEfficiency < 0) mEfficiency = 0; if (mUpdated) { // duct tape fix for too many updates on an overloaded server, causing the structure check to not run @@ -485,8 +507,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity public void checkMaintenance() { if (!shouldCheckMaintenance()) return; - boolean broken = !(mWrench && mScrewdriver && mSoftHammer && mHardHammer && mSolderingTool && mCrowbar); - if (broken) { + if (getRepairStatus() != getIdealStatus()) { for (GT_MetaTileEntity_Hatch_Maintenance tHatch : filterValidMTEs(mMaintenanceHatches)) { if (tHatch.mAuto) tHatch.autoMaintainance(); if (tHatch.mWrench) mWrench = true; @@ -544,9 +565,9 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity if (shouldCheck) return true; // Perform more frequent recipe change after the machine just shuts down. - long timeElapsed = aTick - mLastWorkingTick; + long timeElapsed = mTotalRunTime - mLastWorkingTick; - if (timeElapsed >= CHECK_INTERVAL) return (aTick + randomTickOffset) % CHECK_INTERVAL == 0; + if (timeElapsed >= CHECK_INTERVAL) return (mTotalRunTime + randomTickOffset) % CHECK_INTERVAL == 0; // Batch mode should be a lot less aggressive at recipe checking if (!isBatchModeEnabled()) { return timeElapsed == 5 || timeElapsed == 12 @@ -603,7 +624,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity mProgresstime = 0; mMaxProgresstime = 0; mEfficiencyIncrease = 0; - mLastWorkingTick = aTick; + mLastWorkingTick = mTotalRunTime; if (aBaseMetaTileEntity.isAllowedToWork()) { checkRecipe(); } @@ -976,6 +997,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity if (!ShutDownReasonRegistry.isRegistered(reason.getID())) { throw new RuntimeException(String.format("Reason %s is not registered for registry", reason.getID())); } + mLastWorkingTick = mTotalRunTime; mOutputItems = null; mOutputFluids = null; mEUt = 0; @@ -2613,6 +2635,19 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity .setEnabled( widget -> getBaseMetaTileEntity().getErrorDisplayID() == 0 && getBaseMetaTileEntity().isActive())); + screenElements.widget(TextWidget.dynamicString(() -> { + Duration time = Duration.ofSeconds((mTotalRunTime - mLastWorkingTick) / 20); + return StatCollector.translateToLocalFormatted( + "GT5U.gui.text.shutdown_duration", + time.toHours(), + time.toMinutes() % 60, + time.getSeconds() % 60); + }) + .setEnabled( + widget -> shouldDisplayShutDownReason() && !getBaseMetaTileEntity().isActive() + && getBaseMetaTileEntity().wasShutdown())) + .widget(new FakeSyncWidget.LongSyncer(() -> mTotalRunTime, time -> mTotalRunTime = time)) + .widget(new FakeSyncWidget.LongSyncer(() -> mLastWorkingTick, time -> mLastWorkingTick = time)); screenElements.widget( TextWidget.dynamicString( () -> getBaseMetaTileEntity().getLastShutDownReason() diff --git a/src/main/java/gregtech/api/recipe/check/CheckRecipeResult.java b/src/main/java/gregtech/api/recipe/check/CheckRecipeResult.java index 8af5c58f5e..60436b9c3e 100644 --- a/src/main/java/gregtech/api/recipe/check/CheckRecipeResult.java +++ b/src/main/java/gregtech/api/recipe/check/CheckRecipeResult.java @@ -1,8 +1,6 @@ package gregtech.api.recipe.check; -import javax.annotation.Nonnull; - -import net.minecraft.network.PacketBuffer; +import gregtech.api.util.IMachineMessage; /** * Class to indicate the result of recipe check in the machine. It doesn't need to be actual result of recipemap check, @@ -10,13 +8,7 @@ import net.minecraft.network.PacketBuffer; * <p> * Sample instance must be registered to {@link CheckRecipeResultRegistry}. */ -public interface CheckRecipeResult { - - /** - * @return Unique registry ID - */ - @Nonnull - String getID(); +public interface CheckRecipeResult extends IMachineMessage<CheckRecipeResult> { /** * @return If recipe check is successful @@ -24,28 +16,6 @@ public interface CheckRecipeResult { boolean wasSuccessful(); /** - * @return Actual text to show on client GUI - */ - @Nonnull - String getDisplayString(); - - /** - * Create new instance to receive packet. - */ - @Nonnull - CheckRecipeResult newInstance(); - - /** - * Encode value to sync. - */ - void encode(@Nonnull PacketBuffer buffer); - - /** - * Decode synced value. - */ - void decode(PacketBuffer buffer); - - /** * @return If this message should stay on GUI when the machine is shut down. */ default boolean persistsOnShutdown() { diff --git a/src/main/java/gregtech/api/recipe/check/ResultInsufficientHeat.java b/src/main/java/gregtech/api/recipe/check/ResultInsufficientHeat.java index 26c3530ba3..9383abad9d 100644 --- a/src/main/java/gregtech/api/recipe/check/ResultInsufficientHeat.java +++ b/src/main/java/gregtech/api/recipe/check/ResultInsufficientHeat.java @@ -4,9 +4,12 @@ import java.util.Objects; import javax.annotation.Nonnull; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.util.StatCollector; +import org.jetbrains.annotations.NotNull; + import gregtech.api.enums.HeatingCoilLevel; import gregtech.api.util.GT_Utility; @@ -20,7 +23,7 @@ public class ResultInsufficientHeat implements CheckRecipeResult { @Override @Nonnull - public String getID() { + public @NotNull String getID() { return "insufficient_heat"; } @@ -31,7 +34,7 @@ public class ResultInsufficientHeat implements CheckRecipeResult { @Override @Nonnull - public String getDisplayString() { + public @NotNull String getDisplayString() { return Objects.requireNonNull( StatCollector.translateToLocalFormatted( "GT5U.gui.text.insufficient_heat", @@ -40,8 +43,19 @@ public class ResultInsufficientHeat implements CheckRecipeResult { } @Override + public @NotNull NBTTagCompound writeToNBT(@NotNull NBTTagCompound tag) { + tag.setInteger("required", required); + return tag; + } + + @Override + public void readFromNBT(@NotNull NBTTagCompound tag) { + required = tag.getInteger("required"); + } + + @Override @Nonnull - public CheckRecipeResult newInstance() { + public @NotNull CheckRecipeResult newInstance() { return new ResultInsufficientHeat(0); } diff --git a/src/main/java/gregtech/api/recipe/check/ResultInsufficientMachineTier.java b/src/main/java/gregtech/api/recipe/check/ResultInsufficientMachineTier.java index 742eb3ef7a..1fb2183edb 100644 --- a/src/main/java/gregtech/api/recipe/check/ResultInsufficientMachineTier.java +++ b/src/main/java/gregtech/api/recipe/check/ResultInsufficientMachineTier.java @@ -4,9 +4,12 @@ import java.util.Objects; import javax.annotation.Nonnull; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.util.StatCollector; +import org.jetbrains.annotations.NotNull; + import gregtech.api.util.GT_Utility; public class ResultInsufficientMachineTier implements CheckRecipeResult { @@ -19,7 +22,7 @@ public class ResultInsufficientMachineTier implements CheckRecipeResult { @Override @Nonnull - public String getID() { + public @NotNull String getID() { return "insufficient_machine_tier"; } @@ -30,7 +33,7 @@ public class ResultInsufficientMachineTier implements CheckRecipeResult { @Override @Nonnull - public String getDisplayString() { + public @NotNull String getDisplayString() { return Objects.requireNonNull( StatCollector.translateToLocalFormatted( "GT5U.gui.text.insufficient_machine_tier", @@ -38,8 +41,19 @@ public class ResultInsufficientMachineTier implements CheckRecipeResult { } @Override + public @NotNull NBTTagCompound writeToNBT(@NotNull NBTTagCompound tag) { + tag.setInteger("required", required); + return tag; + } + + @Override + public void readFromNBT(@NotNull NBTTagCompound tag) { + required = tag.getInteger("required"); + } + + @Override @Nonnull - public CheckRecipeResult newInstance() { + public @NotNull CheckRecipeResult newInstance() { return new ResultInsufficientMachineTier(0); } diff --git a/src/main/java/gregtech/api/recipe/check/ResultInsufficientPower.java b/src/main/java/gregtech/api/recipe/check/ResultInsufficientPower.java index fdc06c0c07..45b50aebf6 100644 --- a/src/main/java/gregtech/api/recipe/check/ResultInsufficientPower.java +++ b/src/main/java/gregtech/api/recipe/check/ResultInsufficientPower.java @@ -4,9 +4,12 @@ import java.util.Objects; import javax.annotation.Nonnull; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.util.StatCollector; +import org.jetbrains.annotations.NotNull; + import gregtech.api.util.GT_Utility; public class ResultInsufficientPower implements CheckRecipeResult { @@ -19,7 +22,7 @@ public class ResultInsufficientPower implements CheckRecipeResult { @Override @Nonnull - public String getID() { + public @NotNull String getID() { return "insufficient_power"; } @@ -30,7 +33,7 @@ public class ResultInsufficientPower implements CheckRecipeResult { @Override @Nonnull - public String getDisplayString() { + public @NotNull String getDisplayString() { return Objects.requireNonNull( StatCollector.translateToLocalFormatted( "GT5U.gui.text.insufficient_power", @@ -39,8 +42,19 @@ public class ResultInsufficientPower implements CheckRecipeResult { } @Override + public @NotNull NBTTagCompound writeToNBT(@NotNull NBTTagCompound tag) { + tag.setLong("required", required); + return tag; + } + + @Override + public void readFromNBT(@NotNull NBTTagCompound tag) { + required = tag.getLong("required"); + } + + @Override @Nonnull - public CheckRecipeResult newInstance() { + public @NotNull CheckRecipeResult newInstance() { return new ResultInsufficientPower(0); } diff --git a/src/main/java/gregtech/api/recipe/check/ResultInsufficientStartupPower.java b/src/main/java/gregtech/api/recipe/check/ResultInsufficientStartupPower.java index 62d2dd1fb2..c33e9bfff1 100644 --- a/src/main/java/gregtech/api/recipe/check/ResultInsufficientStartupPower.java +++ b/src/main/java/gregtech/api/recipe/check/ResultInsufficientStartupPower.java @@ -4,9 +4,12 @@ import java.util.Objects; import javax.annotation.Nonnull; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.util.StatCollector; +import org.jetbrains.annotations.NotNull; + import gregtech.api.util.GT_Utility; public class ResultInsufficientStartupPower implements CheckRecipeResult { @@ -19,7 +22,7 @@ public class ResultInsufficientStartupPower implements CheckRecipeResult { @Override @Nonnull - public String getID() { + public @NotNull String getID() { return "insufficient_startup_power"; } @@ -30,7 +33,7 @@ public class ResultInsufficientStartupPower implements CheckRecipeResult { @Override @Nonnull - public String getDisplayString() { + public @NotNull String getDisplayString() { return Objects.requireNonNull( StatCollector.translateToLocalFormatted( "GT5U.gui.text.insufficient_startup_power", @@ -38,8 +41,19 @@ public class ResultInsufficientStartupPower implements CheckRecipeResult { } @Override + public @NotNull NBTTagCompound writeToNBT(@NotNull NBTTagCompound tag) { + tag.setInteger("required", required); + return tag; + } + + @Override + public void readFromNBT(@NotNull NBTTagCompound tag) { + required = tag.getInteger("required"); + } + + @Override @Nonnull - public CheckRecipeResult newInstance() { + public @NotNull CheckRecipeResult newInstance() { return new ResultInsufficientStartupPower(0); } diff --git a/src/main/java/gregtech/api/recipe/check/ResultInsufficientStartupPowerBigInt.java b/src/main/java/gregtech/api/recipe/check/ResultInsufficientStartupPowerBigInt.java index 6a719b3c9c..f4b186c9a1 100644 --- a/src/main/java/gregtech/api/recipe/check/ResultInsufficientStartupPowerBigInt.java +++ b/src/main/java/gregtech/api/recipe/check/ResultInsufficientStartupPowerBigInt.java @@ -5,6 +5,7 @@ import static util.Util.toStandardForm; import java.math.BigInteger; import java.util.Objects; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.util.StatCollector; @@ -36,6 +37,17 @@ public class ResultInsufficientStartupPowerBigInt implements CheckRecipeResult { StatCollector.translateToLocalFormatted("GT5U.gui.text.insufficient_startup_power", required)); } + @Override + public @NotNull NBTTagCompound writeToNBT(@NotNull NBTTagCompound tag) { + tag.setString("required", required); + return tag; + } + + @Override + public void readFromNBT(@NotNull NBTTagCompound tag) { + required = tag.getString("required"); + } + @NotNull @Override public CheckRecipeResult newInstance() { diff --git a/src/main/java/gregtech/api/recipe/check/ResultMissingItem.java b/src/main/java/gregtech/api/recipe/check/ResultMissingItem.java index 868d664109..db4ea2ba41 100644 --- a/src/main/java/gregtech/api/recipe/check/ResultMissingItem.java +++ b/src/main/java/gregtech/api/recipe/check/ResultMissingItem.java @@ -7,8 +7,11 @@ import javax.annotation.Nullable; import net.minecraft.client.resources.I18n; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; +import org.jetbrains.annotations.NotNull; + import cpw.mods.fml.common.network.ByteBufUtils; public class ResultMissingItem implements CheckRecipeResult { @@ -26,7 +29,7 @@ public class ResultMissingItem implements CheckRecipeResult { @Override @Nonnull - public String getID() { + public @NotNull String getID() { return "missing_item"; } @@ -37,14 +40,25 @@ public class ResultMissingItem implements CheckRecipeResult { @Override @Nonnull - public String getDisplayString() { + public @NotNull String getDisplayString() { return Objects.requireNonNull( I18n.format("GT5U.gui.text.missing_item", itemStack != null ? itemStack.getDisplayName() : "null")); } @Override + public @NotNull NBTTagCompound writeToNBT(@NotNull NBTTagCompound tag) { + if (itemStack != null) return itemStack.writeToNBT(tag); + return tag; + } + + @Override + public void readFromNBT(@NotNull NBTTagCompound tag) { + itemStack = ItemStack.loadItemStackFromNBT(tag); + } + + @Override @Nonnull - public CheckRecipeResult newInstance() { + public @NotNull CheckRecipeResult newInstance() { return new ResultMissingItem(itemStack != null ? itemStack.copy() : null); } diff --git a/src/main/java/gregtech/api/recipe/check/SimpleCheckRecipeResult.java b/src/main/java/gregtech/api/recipe/check/SimpleCheckRecipeResult.java index 58c85bbe9d..ed998e93d9 100644 --- a/src/main/java/gregtech/api/recipe/check/SimpleCheckRecipeResult.java +++ b/src/main/java/gregtech/api/recipe/check/SimpleCheckRecipeResult.java @@ -4,9 +4,12 @@ import java.util.Objects; import javax.annotation.Nonnull; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.util.StatCollector; +import org.jetbrains.annotations.NotNull; + import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils; /** @@ -25,7 +28,7 @@ public class SimpleCheckRecipeResult implements CheckRecipeResult { } @Override - public String getID() { + public @NotNull String getID() { return "simple_result"; } @@ -36,13 +39,28 @@ public class SimpleCheckRecipeResult implements CheckRecipeResult { @Override @Nonnull - public String getDisplayString() { + public @NotNull String getDisplayString() { return Objects.requireNonNull(StatCollector.translateToLocal("GT5U.gui.text." + key)); } @Override + public @NotNull NBTTagCompound writeToNBT(@NotNull NBTTagCompound tag) { + tag.setBoolean("success", success); + tag.setString("key", key); + tag.setBoolean("persistsOnShutdown", persistsOnShutdown); + return tag; + } + + @Override + public void readFromNBT(@NotNull NBTTagCompound tag) { + success = tag.getBoolean("success"); + key = tag.getString("key"); + persistsOnShutdown = tag.getBoolean("persistsOnShutdown"); + } + + @Override @Nonnull - public CheckRecipeResult newInstance() { + public @NotNull CheckRecipeResult newInstance() { return new SimpleCheckRecipeResult(false, "", false); } diff --git a/src/main/java/gregtech/api/util/IMachineMessage.java b/src/main/java/gregtech/api/util/IMachineMessage.java new file mode 100644 index 0000000000..8b5c3e090f --- /dev/null +++ b/src/main/java/gregtech/api/util/IMachineMessage.java @@ -0,0 +1,50 @@ +package gregtech.api.util; + +import javax.annotation.Nonnull; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.PacketBuffer; + +import org.jetbrains.annotations.NotNull; + +public interface IMachineMessage<T extends IMachineMessage<T>> { + + /** + * @return Unique registry ID + */ + @Nonnull + String getID(); + + /** + * @return Actual text to show on client GUI + */ + @Nonnull + String getDisplayString(); + + /** + * Save info to NBT. + */ + @NotNull + NBTTagCompound writeToNBT(@Nonnull NBTTagCompound tag); + + /** + * Read info from NBT. + */ + void readFromNBT(@Nonnull NBTTagCompound tag); + + /** + * Create new instance to receive packet. + */ + @Nonnull + T newInstance(); + + /** + * Encode value to sync. + */ + void encode(@Nonnull PacketBuffer buffer); + + /** + * Decode synced value. + */ + void decode(PacketBuffer buffer); +} diff --git a/src/main/java/gregtech/api/util/shutdown/ReasonOutOfFluid.java b/src/main/java/gregtech/api/util/shutdown/ReasonOutOfFluid.java index 29b99a644a..0194afbc04 100644 --- a/src/main/java/gregtech/api/util/shutdown/ReasonOutOfFluid.java +++ b/src/main/java/gregtech/api/util/shutdown/ReasonOutOfFluid.java @@ -5,6 +5,7 @@ import static gregtech.api.util.GT_Utility.formatNumbers; import java.util.Objects; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.util.StatCollector; import net.minecraftforge.fluids.Fluid; @@ -37,6 +38,16 @@ public class ReasonOutOfFluid implements ShutDownReason { formatNumbers(requiredFluid.amount))); } + @Override + public @NotNull NBTTagCompound writeToNBT(@NotNull NBTTagCompound tag) { + return requiredFluid.writeToNBT(tag); + } + + @Override + public void readFromNBT(@NotNull NBTTagCompound tag) { + requiredFluid = FluidStack.loadFluidStackFromNBT(tag); + } + @NotNull @Override public ShutDownReason newInstance() { diff --git a/src/main/java/gregtech/api/util/shutdown/ReasonOutOfItem.java b/src/main/java/gregtech/api/util/shutdown/ReasonOutOfItem.java index f4a46f2d30..8f51bd83b2 100644 --- a/src/main/java/gregtech/api/util/shutdown/ReasonOutOfItem.java +++ b/src/main/java/gregtech/api/util/shutdown/ReasonOutOfItem.java @@ -6,6 +6,7 @@ import java.util.Objects; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.util.StatCollector; @@ -35,6 +36,16 @@ public class ReasonOutOfItem implements ShutDownReason { formatNumbers(requiredItem.stackSize))); } + @Override + public @NotNull NBTTagCompound writeToNBT(@NotNull NBTTagCompound tag) { + return requiredItem.writeToNBT(tag); + } + + @Override + public void readFromNBT(@NotNull NBTTagCompound tag) { + requiredItem.readFromNBT(tag); + } + @NotNull @Override public ShutDownReason newInstance() { diff --git a/src/main/java/gregtech/api/util/shutdown/ReasonOutOfStuff.java b/src/main/java/gregtech/api/util/shutdown/ReasonOutOfStuff.java index 0c3f7e0b64..72a75b062f 100644 --- a/src/main/java/gregtech/api/util/shutdown/ReasonOutOfStuff.java +++ b/src/main/java/gregtech/api/util/shutdown/ReasonOutOfStuff.java @@ -4,6 +4,7 @@ import static gregtech.api.util.GT_Utility.formatNumbers; import java.util.Objects; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.util.StatCollector; @@ -32,6 +33,19 @@ public class ReasonOutOfStuff implements ShutDownReason { StatCollector.translateToLocalFormatted("GT5U.gui.text.out_of_stuff", required, formatNumbers(amount))); } + @Override + public @NotNull NBTTagCompound writeToNBT(@NotNull NBTTagCompound tag) { + tag.setString("required", required); + tag.setInteger("amount", amount); + return tag; + } + + @Override + public void readFromNBT(@NotNull NBTTagCompound tag) { + required = tag.getString("required"); + tag.setInteger("amount", amount); + } + @NotNull @Override public ShutDownReason newInstance() { diff --git a/src/main/java/gregtech/api/util/shutdown/ShutDownReason.java b/src/main/java/gregtech/api/util/shutdown/ShutDownReason.java index 0815936a55..47889583aa 100644 --- a/src/main/java/gregtech/api/util/shutdown/ShutDownReason.java +++ b/src/main/java/gregtech/api/util/shutdown/ShutDownReason.java @@ -1,38 +1,8 @@ package gregtech.api.util.shutdown; -import javax.annotation.Nonnull; +import gregtech.api.util.IMachineMessage; -import net.minecraft.network.PacketBuffer; - -public interface ShutDownReason { - - /** - * @return Unique registry ID - */ - @Nonnull - String getID(); - - /** - * @return Actual text to show on client GUI - */ - @Nonnull - String getDisplayString(); - - /** - * Create new instance to receive packet. - */ - @Nonnull - ShutDownReason newInstance(); - - /** - * Encode value to sync. - */ - void encode(@Nonnull PacketBuffer buffer); - - /** - * Decode synced value. - */ - void decode(PacketBuffer buffer); +public interface ShutDownReason extends IMachineMessage<ShutDownReason> { /** * @return Whether the reason is critical. diff --git a/src/main/java/gregtech/api/util/shutdown/SimpleShutDownReason.java b/src/main/java/gregtech/api/util/shutdown/SimpleShutDownReason.java index 92763fa431..772fc203ea 100644 --- a/src/main/java/gregtech/api/util/shutdown/SimpleShutDownReason.java +++ b/src/main/java/gregtech/api/util/shutdown/SimpleShutDownReason.java @@ -4,6 +4,7 @@ import java.util.Objects; import javax.annotation.Nonnull; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.util.StatCollector; @@ -36,6 +37,19 @@ public class SimpleShutDownReason implements ShutDownReason { return Objects.requireNonNull(StatCollector.translateToLocal("GT5U.gui.text." + key)); } + @Override + public @NotNull NBTTagCompound writeToNBT(@NotNull NBTTagCompound tag) { + tag.setString("key", key); + tag.setBoolean("wasCritical", wasCritical); + return tag; + } + + @Override + public void readFromNBT(@NotNull NBTTagCompound tag) { + key = tag.getString("key"); + wasCritical = tag.getBoolean("wasCritical"); + } + @NotNull @Override public ShutDownReason newInstance() { |