diff options
Diffstat (limited to 'src/main/java')
25 files changed, 341 insertions, 173 deletions
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/util/ResultWrongSievert.java b/src/main/java/com/github/bartimaeusnek/bartworks/util/ResultWrongSievert.java index b6216f3c42..93d7318715 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/util/ResultWrongSievert.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/util/ResultWrongSievert.java @@ -1,8 +1,11 @@ package com.github.bartimaeusnek.bartworks.util; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.util.StatCollector; +import org.jetbrains.annotations.NotNull; + import gregtech.api.recipe.check.CheckRecipeResult; import gregtech.api.util.GT_Utility; @@ -21,7 +24,7 @@ public class ResultWrongSievert implements CheckRecipeResult { this.type = type; } - public String getID() { + public @NotNull String getID() { return "wrong_sievert"; } @@ -31,7 +34,7 @@ public class ResultWrongSievert implements CheckRecipeResult { } @Override - public String getDisplayString() { + public @NotNull String getDisplayString() { return switch (this.type) { case EXACTLY -> StatCollector.translateToLocalFormatted( "GT5U.gui.text.wrong_sievert_exactly", @@ -42,12 +45,24 @@ public class ResultWrongSievert implements CheckRecipeResult { } @Override - public CheckRecipeResult newInstance() { + public @NotNull NBTTagCompound writeToNBT(@NotNull NBTTagCompound tag) { + tag.setInteger("required", required); + tag.setInteger("type", type.ordinal()); + return tag; + } + + @Override + public void readFromNBT(@NotNull NBTTagCompound tag) { + required = tag.getInteger("required"); + } + + @Override + public @NotNull CheckRecipeResult newInstance() { return new ResultWrongSievert(0, NeededSievertType.EXACTLY); } @Override - public void encode(PacketBuffer buffer) { + public void encode(@NotNull PacketBuffer buffer) { buffer.writeVarIntToBuffer(this.required); buffer.writeVarIntToBuffer(this.type.ordinal()); } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java index ad0c5a0c97..fc91adb69f 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java @@ -1073,6 +1073,7 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM @Override public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { if (aBaseMetaTileEntity.isServerSide()) { + mTotalRunTime++; explodedThisTick = false; if (mEfficiency < 0) { mEfficiency = 0; diff --git a/src/main/java/goodgenerator/blocks/tileEntity/PreciseAssembler.java b/src/main/java/goodgenerator/blocks/tileEntity/PreciseAssembler.java index f6ea2596a2..3d8c0df58c 100644 --- a/src/main/java/goodgenerator/blocks/tileEntity/PreciseAssembler.java +++ b/src/main/java/goodgenerator/blocks/tileEntity/PreciseAssembler.java @@ -120,45 +120,50 @@ public class PreciseAssembler extends GT_MetaTileEntity_ExtendedPowerMultiBlockB { "CCCC~CCCC", "CMMMMMMMC", "CMMMMMMMC", "CMMMMMMMC", "CCCCCCCCC" } })) .addElement( 'C', - GT_HatchElementBuilder.<PreciseAssembler>builder() - .atLeast( - InputBus, - InputHatch, - OutputHatch, - OutputBus, - Maintenance, - Muffler, - ExoticEnergy.or(Energy)) - .adder(PreciseAssembler::addToPAssList) - .casingIndex(CASING_INDEX) - .dot(1) - .buildAndChain( - onElementPass( - x -> x.casingAmount++, - StructureUtility.ofBlocksTiered( - (block, meta) -> block == Loaders.impreciseUnitCasing ? -1 - : block == Loaders.preciseUnitCasing ? meta : -2, - ImmutableList.of( - Pair.of(Loaders.impreciseUnitCasing, 0), - Pair.of(Loaders.preciseUnitCasing, 0), - Pair.of(Loaders.preciseUnitCasing, 1), - Pair.of(Loaders.preciseUnitCasing, 2), - Pair.of(Loaders.preciseUnitCasing, 3)), - -3, - PreciseAssembler::setCasingTier, - PreciseAssembler::getCasingTier)))) + withChannel( + "unit casing", + GT_HatchElementBuilder.<PreciseAssembler>builder() + .atLeast( + InputBus, + InputHatch, + OutputHatch, + OutputBus, + Maintenance, + Muffler, + ExoticEnergy.or(Energy)) + .adder(PreciseAssembler::addToPAssList) + .casingIndex(CASING_INDEX) + .dot(1) + .buildAndChain( + onElementPass( + x -> x.casingAmount++, + StructureUtility.ofBlocksTiered( + (block, meta) -> block == Loaders.impreciseUnitCasing ? -1 + : block == Loaders.preciseUnitCasing ? meta : -2, + ImmutableList.of( + Pair.of(Loaders.impreciseUnitCasing, 0), + Pair.of(Loaders.preciseUnitCasing, 0), + Pair.of(Loaders.preciseUnitCasing, 1), + Pair.of(Loaders.preciseUnitCasing, 2), + Pair.of(Loaders.preciseUnitCasing, 3)), + -3, + PreciseAssembler::setCasingTier, + PreciseAssembler::getCasingTier))))) .addElement('F', ofFrame(Materials.TungstenSteel)) - .addElement('G', ofGlassTieredMixed((byte) 4, (byte) 127, 2)) + .addElement('G', withChannel("glass", ofGlassTieredMixed((byte) 4, (byte) 127, 2))) .addElement( 'M', - StructureUtility.ofBlocksTiered( - (block, meta) -> block == GregTech_API.sBlockCasings1 ? meta : -2, - IntStream.range(0, 10) - .mapToObj(meta -> org.apache.commons.lang3.tuple.Pair.of(GregTech_API.sBlockCasings1, meta)) - .collect(Collectors.toList()), - -1, - PreciseAssembler::setMachineTier, - PreciseAssembler::getMachineTier)) + withChannel( + "machine casing", + StructureUtility.ofBlocksTiered( + (block, meta) -> block == GregTech_API.sBlockCasings1 ? meta : -2, + IntStream.range(0, 10) + .mapToObj( + meta -> org.apache.commons.lang3.tuple.Pair.of(GregTech_API.sBlockCasings1, meta)) + .collect(Collectors.toList()), + -1, + PreciseAssembler::setMachineTier, + PreciseAssembler::getMachineTier))) .build(); } return multiDefinition; diff --git a/src/main/java/goodgenerator/blocks/tileEntity/base/LargeFusionComputer.java b/src/main/java/goodgenerator/blocks/tileEntity/base/LargeFusionComputer.java index 50039e19c5..5c31d55b16 100644 --- a/src/main/java/goodgenerator/blocks/tileEntity/base/LargeFusionComputer.java +++ b/src/main/java/goodgenerator/blocks/tileEntity/base/LargeFusionComputer.java @@ -274,6 +274,7 @@ public abstract class LargeFusionComputer extends GT_MetaTileEntity_TooltipMulti } if (aBaseMetaTileEntity.isServerSide()) { + mTotalRunTime++; if (mEfficiency < 0) mEfficiency = 0; if (mRunningOnLoad && checkMachine(aBaseMetaTileEntity, mInventory[1])) { checkRecipe(); 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() { diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java index 8edd2dea4e..9dd01c969d 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java @@ -385,6 +385,7 @@ public abstract class GT_MetaTileEntity_FusionComputer @Override public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { if (aBaseMetaTileEntity.isServerSide()) { + mTotalRunTime++; if (mEfficiency < 0) mEfficiency = 0; if (mRunningOnLoad && checkMachine(aBaseMetaTileEntity, mInventory[1])) { this.mEUStore = aBaseMetaTileEntity.getStoredEU(); diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java index 491f696c43..1417f53c01 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java @@ -102,7 +102,6 @@ public abstract class GregtechMeta_MultiBlockBase<T extends GT_MetaTileEntity_Ex public static final boolean DEBUG_DISABLE_CORES_TEMPORARILY = true; public GT_Recipe mLastRecipe; - protected long mTotalRunTime = 0; /** * Don't use this for recipe input check, otherwise you'll get duplicated fluids @@ -129,10 +128,6 @@ public abstract class GregtechMeta_MultiBlockBase<T extends GT_MetaTileEntity_Ex return (tStackSize + tMaxStackSize - 1) / tMaxStackSize; } - public long getTotalRuntimeInTicks() { - return this.mTotalRunTime; - } - public abstract String getMachineType(); public String getMachineTooltip() { @@ -425,29 +420,6 @@ public abstract class GregtechMeta_MultiBlockBase<T extends GT_MetaTileEntity_Ex } @Override - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { - - // Time Counter - if (aBaseMetaTileEntity.isServerSide()) { - this.mTotalRunTime++; - } - - if (aBaseMetaTileEntity.isServerSide()) { - if (this.mUpdate == 1 || this.mStartUpCheck == 1) { - this.mChargeHatches.clear(); - this.mDischargeHatches.clear(); - this.mAirIntakes.clear(); - this.mTecTechEnergyHatches.clear(); - this.mTecTechDynamoHatches.clear(); - this.mAllEnergyHatches.clear(); - this.mAllDynamoHatches.clear(); - } - } - - super.onPostTick(aBaseMetaTileEntity, aTick); - } - - @Override public void explodeMultiblock() { MetaTileEntity tTileEntity; for (final Iterator<GT_MetaTileEntity_Hatch_InputBattery> localIterator = this.mChargeHatches @@ -1042,15 +1014,8 @@ public abstract class GregtechMeta_MultiBlockBase<T extends GT_MetaTileEntity_Ex } @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setLong("mTotalRunTime", this.mTotalRunTime); - super.saveNBTData(aNBT); - } - - @Override public void loadNBTData(NBTTagCompound aNBT) { super.loadNBTData(aNBT); - this.mTotalRunTime = aNBT.getLong("mTotalRunTime"); if (aNBT.hasKey("mVoidExcess")) { // backward compatibility voidingMode = aNBT.getBoolean("mVoidExcess") ? VoidingMode.VOID_ALL : VoidingMode.VOID_NONE; diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/GregtechMTE_AlgaePondBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/GregtechMTE_AlgaePondBase.java index 17e1093b71..7e5200e16c 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/GregtechMTE_AlgaePondBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/GregtechMTE_AlgaePondBase.java @@ -319,11 +319,6 @@ public class GregtechMTE_AlgaePondBase extends GregtechMeta_MultiBlockBase<Gregt } @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - } - - @Override public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { super.onPreTick(aBaseMetaTileEntity, aTick); // Silly Client Syncing diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java index 0270dfea37..13bef7c885 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java @@ -517,7 +517,6 @@ public class GregtechMetaTileEntity_PowerSubStationController extends aNBT.setLong("mTotalEnergyAdded", this.mTotalEnergyAdded); aNBT.setLong("mTotalEnergyLost", this.mTotalEnergyLost); aNBT.setLong("mTotalEnergyConsumed", this.mTotalEnergyConsumed); - aNBT.setLong("mTotalRunTime", this.mTotalRunTime); aNBT.setBoolean("mIsOutputtingPower", this.mIsOutputtingPower); aNBT.setLong("mBatteryCapacity", this.mBatteryCapacity); super.saveNBTData(aNBT); @@ -543,7 +542,6 @@ public class GregtechMetaTileEntity_PowerSubStationController extends this.mTotalEnergyAdded = aNBT.getLong("mTotalEnergyAdded"); this.mTotalEnergyLost = aNBT.getLong("mTotalEnergyLost"); this.mTotalEnergyConsumed = aNBT.getLong("mTotalEnergyConsumed"); - this.mTotalRunTime = aNBT.getLong("mTotalRunTime"); this.mIsOutputtingPower = aNBT.getBoolean("mIsOutputtingPower"); |