Skip to content
This repository has been archived by the owner on May 26, 2024. It is now read-only.

Commit

Permalink
Implement shutdown reason mechanism (#853)
Browse files Browse the repository at this point in the history
* migrate machines

* add annotation

* damn animation
  • Loading branch information
HoleFish committed Mar 20, 2024
1 parent 4552944 commit dc25b04
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -599,25 +600,26 @@ protected void setProcessingLogicPower(ProcessingLogic logic) {
@Override
public boolean onRunningTick(ItemStack aStack) {
if (!super.onRunningTick(aStack)) {
criticalStopMachine();
return false;
}

if (runningTick % 20 == 0) {
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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -112,7 +113,7 @@ protected boolean filtersFluid() {
}

if (getEmptyTurbineAssemblies().size() > 0 || !areAllTurbinesTheSame()) {
stopMachine();
stopMachine(ShutDownReasonRegistry.NO_TURBINE);
return CheckRecipeResultRegistry.NO_TURBINE_FOUND;
}

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -438,7 +440,7 @@ protected void depleteTurbineFromStock(ItemStack aTurbine) {
}

if (getEmptyTurbineAssemblies().size() > 0 || !areAllTurbinesTheSame()) {
stopMachine();
stopMachine(ShutDownReasonRegistry.NO_TURBINE);
return CheckRecipeResultRegistry.NO_TURBINE_FOUND;
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dc25b04

Please sign in to comment.