From dc25b04bd59b064026040d68926d54bc601b6ed2 Mon Sep 17 00:00:00 2001 From: HoleFish <48403212+HoleFish@users.noreply.github.com> Date: Wed, 20 Mar 2024 17:13:11 +0800 Subject: [PATCH] Implement shutdown reason mechanism (#853) * migrate machines * add annotation * damn animation --- .../base/GregtechMeta_SteamMultiBase.java | 8 ++--- ...etaTileEntity_IndustrialVacuumFreezer.java | 8 +++-- .../GregtechMetaTileEntity_Adv_EBF.java | 7 ++++- .../GregtechMTE_NuclearReactor.java | 3 +- ...gtechMetaTileEntity_LargeRocketEngine.java | 3 +- ...etaTileEntity_QuantumForceTransformer.java | 12 ++++--- .../turbines/GT_MTE_LargeTurbine_Plasma.java | 5 +-- ...gtechMetaTileEntity_LargerTurbineBase.java | 31 +++++++++---------- 8 files changed, 43 insertions(+), 34 deletions(-) diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_SteamMultiBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_SteamMultiBase.java index 55288bc85..2dafe59cd 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_SteamMultiBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_SteamMultiBase.java @@ -27,6 +27,7 @@ import gregtech.api.util.GT_HatchElementBuilder; import gregtech.api.util.GT_Utility; import gregtech.api.util.IGT_HatchAdder; +import gregtech.api.util.shutdown.ShutDownReasonRegistry; import gtPlusPlus.core.util.minecraft.FluidUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Steam_BusInput; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Steam_BusOutput; @@ -135,7 +136,7 @@ public boolean onRunningTick(ItemStack aStack) { long aSteamVal = ((-lEUt * 10000) / Math.max(1000, mEfficiency)); // Logger.INFO("Trying to drain "+aSteamVal+" steam per tick."); if (!tryConsumeSteam((int) aSteamVal)) { - stopMachine(); + stopMachine(ShutDownReasonRegistry.POWER_LOSS); return false; } } @@ -175,11 +176,6 @@ public boolean addToMachineList(final IGregTechTileEntity aTileEntity, final int return aDidAdd; } - @Override - public void stopMachine() { - super.stopMachine(); - } - /* * Handle I/O with custom hatches */ diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialVacuumFreezer.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialVacuumFreezer.java index 4d27705c1..592033de2 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialVacuumFreezer.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialVacuumFreezer.java @@ -15,6 +15,7 @@ import static gregtech.api.util.GT_Utility.filterValidMTEs; import java.util.ArrayList; +import java.util.Objects; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; @@ -31,6 +32,7 @@ import gregtech.api.logic.ProcessingLogic; import gregtech.api.recipe.RecipeMap; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.shutdown.ShutDownReasonRegistry; import gtPlusPlus.api.recipe.GTPPRecipeMaps; import gtPlusPlus.core.block.ModBlocks; import gtPlusPlus.core.lib.CORE; @@ -80,7 +82,7 @@ protected GT_Multiblock_Tooltip_Builder createTooltip() { GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); tt.addMachineType(getMachineType()).addInfo("Factory Grade Advanced Vacuum Freezer") .addInfo("Speed: +100% | EU Usage: 100% | Parallel: 4") - .addInfo("Consumes 1L of " + mCryoFuelName + "/t during operation") + .addInfo("Consumes 20L of " + mCryoFuelName + "/s during operation") .addInfo("Constructed exactly the same as a normal Vacuum Freezer") .addPollutionAmount(getPollutionPerSecond(null)).addSeparator().beginStructureBlock(3, 3, 3, true) .addController("Front Center").addCasingInfoMin(mCasingName, 10, false).addInputBus("Any Casing", 1) @@ -234,7 +236,9 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { if (!this.depleteInputFromRestrictedHatches(this.mCryotheumHatches, 10)) { if (mGraceTimer-- == 0) { this.causeMaintenanceIssue(); - this.stopMachine(); + this.stopMachine( + ShutDownReasonRegistry.outOfFluid( + Objects.requireNonNull(FluidUtils.getFluidStack("cryotheum", 20)))); mGraceTimer = 2; } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_EBF.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_EBF.java index 9bff4f00a..a1b5eea34 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_EBF.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_EBF.java @@ -16,6 +16,7 @@ import static gregtech.api.util.GT_Utility.filterValidMTEs; import java.util.ArrayList; +import java.util.Objects; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -46,8 +47,10 @@ import gregtech.api.util.GT_OverclockCalculator; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; +import gregtech.api.util.shutdown.ShutDownReasonRegistry; import gtPlusPlus.core.block.ModBlocks; import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.FluidUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GT_MetaTileEntity_Hatch_CustomFluidBase; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; @@ -268,7 +271,9 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { if (!this.depleteInputFromRestrictedHatches(this.mPyrotheumHatches, 5)) { if (mGraceTimer-- == 0) { this.causeMaintenanceIssue(); - this.stopMachine(); + this.stopMachine( + ShutDownReasonRegistry.outOfFluid( + Objects.requireNonNull(FluidUtils.getFluidStack("pyrotheum", 10)))); mGraceTimer = 2; } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_NuclearReactor.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_NuclearReactor.java index 146977a2a..18db51962 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_NuclearReactor.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_NuclearReactor.java @@ -45,6 +45,7 @@ import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_OverclockCalculator; import gregtech.api.util.GT_Recipe; +import gregtech.api.util.shutdown.ShutDownReasonRegistry; import gtPlusPlus.api.recipe.GTPPRecipeMaps; import gtPlusPlus.core.block.ModBlocks; import gtPlusPlus.core.lib.CORE; @@ -377,7 +378,7 @@ protected CheckRecipeResult validateRecipe(@NotNull GT_Recipe recipe) { protected void resetMultiProcessing() { this.mEfficiency = 0; this.mLastRecipe = null; - stopMachine(); + stopMachine(ShutDownReasonRegistry.NONE); } @Override diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeRocketEngine.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeRocketEngine.java index 3ba8cdbfd..ba037c965 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeRocketEngine.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeRocketEngine.java @@ -41,6 +41,7 @@ import gregtech.api.recipe.check.SimpleCheckRecipeResult; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Recipe; +import gregtech.api.util.shutdown.ShutDownReasonRegistry; import gtPlusPlus.api.recipe.GTPPRecipeMaps; import gtPlusPlus.core.block.ModBlocks; import gtPlusPlus.core.item.chemistry.RocketFuels; @@ -242,7 +243,7 @@ public RecipeMap getRecipeMap() { int aircount = getAir(); int aAirToConsume = this.euProduction / 100; if (aircount < aAirToConsume) { - criticalStopMachine(); + stopMachine(ShutDownReasonRegistry.outOfFluid(new FluidStack(sAirFluid, aAirToConsume))); return SimpleCheckRecipeResult.ofFailure("no_air"); } else { int aTotalAir = 0; diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_QuantumForceTransformer.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_QuantumForceTransformer.java index 27ac35f1d..803d0f0a9 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_QuantumForceTransformer.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_QuantumForceTransformer.java @@ -73,6 +73,7 @@ import gregtech.api.util.GT_ParallelHelper; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; +import gregtech.api.util.shutdown.ShutDownReasonRegistry; import gtPlusPlus.api.recipe.GTPPRecipeMaps; import gtPlusPlus.core.block.ModBlocks; import gtPlusPlus.core.material.ELEMENT; @@ -599,7 +600,6 @@ protected void setProcessingLogicPower(ProcessingLogic logic) { @Override public boolean onRunningTick(ItemStack aStack) { if (!super.onRunningTick(aStack)) { - criticalStopMachine(); return false; } @@ -607,17 +607,19 @@ public boolean onRunningTick(ItemStack aStack) { int amount = (int) (getFocusingTier() * 4 * Math.sqrt(Math.min(mMaxParallel, processingLogic.getCurrentParallels()))); if (doFermium) { - if (!drain(mFermiumHatch, new FluidStack(mFermium, amount), true)) { + FluidStack fermiumToConsume = new FluidStack(mFermium, amount); + if (!drain(mFermiumHatch, fermiumToConsume, true)) { doFermium = false; - criticalStopMachine(); + stopMachine(ShutDownReasonRegistry.outOfFluid(fermiumToConsume)); return false; } } if (doNeptunium) { - if (!drain(mNeptuniumHatch, new FluidStack(mNeptunium, amount), true)) { + FluidStack neptuniumToConsume = new FluidStack(mNeptunium, amount); + if (!drain(mNeptuniumHatch, neptuniumToConsume, true)) { doNeptunium = false; - criticalStopMachine(); + stopMachine(ShutDownReasonRegistry.outOfFluid(neptuniumToConsume)); return false; } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Plasma.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Plasma.java index d65224f4d..fb875dba3 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Plasma.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Plasma.java @@ -23,6 +23,7 @@ import gregtech.api.recipe.maps.FuelBackend; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; +import gregtech.api.util.shutdown.ShutDownReasonRegistry; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Turbine; @@ -112,7 +113,7 @@ protected boolean filtersFluid() { } if (getEmptyTurbineAssemblies().size() > 0 || !areAllTurbinesTheSame()) { - stopMachine(); + stopMachine(ShutDownReasonRegistry.NO_TURBINE); return CheckRecipeResultRegistry.NO_TURBINE_FOUND; } @@ -163,7 +164,7 @@ protected boolean filtersFluid() { optFlow = MathUtils.roundToClosestInt(aTotalOptimalFlow); euPerTurbine = MathUtils.roundToClosestInt(aEUPerTurbine); if (optFlow <= 0 || baseEff <= 0) { - stopMachine(); // in case the turbine got removed + stopMachine(ShutDownReasonRegistry.NONE); // in case the turbine got removed return CheckRecipeResultRegistry.NO_FUEL_FOUND; } } else { diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GregtechMetaTileEntity_LargerTurbineBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GregtechMetaTileEntity_LargerTurbineBase.java index 92995a831..adb35cc0d 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GregtechMetaTileEntity_LargerTurbineBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GregtechMetaTileEntity_LargerTurbineBase.java @@ -45,6 +45,8 @@ import gregtech.api.recipe.check.CheckRecipeResultRegistry; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Utility; +import gregtech.api.util.shutdown.ShutDownReason; +import gregtech.api.util.shutdown.ShutDownReasonRegistry; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.api.objects.minecraft.BlockPos; @@ -438,7 +440,7 @@ protected void depleteTurbineFromStock(ItemStack aTurbine) { } if (getEmptyTurbineAssemblies().size() > 0 || !areAllTurbinesTheSame()) { - stopMachine(); + stopMachine(ShutDownReasonRegistry.NO_TURBINE); return CheckRecipeResultRegistry.NO_TURBINE_FOUND; } @@ -474,7 +476,7 @@ protected void depleteTurbineFromStock(ItemStack aTurbine) { baseEff = MathUtils.roundToClosestInt(aTotalBaseEff); optFlow = MathUtils.roundToClosestInt(aTotalOptimalFlow); if (optFlow <= 0 || baseEff <= 0) { - stopMachine(); // in case the turbine got removed + stopMachine(ShutDownReasonRegistry.NONE); // in case the turbine got removed return CheckRecipeResultRegistry.NO_FUEL_FOUND; } } else { @@ -518,10 +520,11 @@ protected void depleteTurbineFromStock(ItemStack aTurbine) { @Override public boolean doRandomMaintenanceDamage() { - if (getMaxParallelRecipes() == 0 || getRepairStatus() == 0) { - stopMachine(); + if (getMaxParallelRecipes() == 0) { + stopMachine(ShutDownReasonRegistry.NO_TURBINE); return false; } + if (mRuntime++ > 1000) { mRuntime = 0; @@ -732,27 +735,23 @@ protected ITexture getFrontFacingTurbineTexture(boolean isActive) { @Override public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); if (aBaseMetaTileEntity.isServerSide()) { - if (mUpdate == 1 || mStartUpCheck == 1) { - log("Cleared Rotor Assemblies."); - this.mTurbineRotorHatches.clear(); + if (this.maxProgresstime() > 0 || this.getBaseMetaTileEntity().hasWorkJustBeenEnabled()) { + enableAllTurbineHatches(); + } + if (this.maxProgresstime() <= 0) { + stopMachine(ShutDownReasonRegistry.NONE); } - } - super.onPostTick(aBaseMetaTileEntity, aTick); - if (this.maxProgresstime() > 0 || this.getBaseMetaTileEntity().hasWorkJustBeenEnabled()) { - enableAllTurbineHatches(); - } - if (this.maxProgresstime() <= 0) { - stopMachine(); } } @Override - public void stopMachine() { + public void stopMachine(@NotNull ShutDownReason reason) { baseEff = 0; optFlow = 0; disableAllTurbineHatches(); - super.stopMachine(); + super.stopMachine(reason); } @Override