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

Commit

Permalink
Prevent Instant UCFE Explosions (#256)
Browse files Browse the repository at this point in the history
* Add safety explosion counter to protect multi

- Added a 10 second counter that fails the normal energy output in the UCFE, but also prevents it from exploding. This fixes the issue of starting it with some fuel in the inputs, and also on world load if EU is not extracted fast enough.

* Clarify tooltip and shutdown on explosion

- Added relevant information to tooltip;
- Force shutdown of the multi after explosion, since it keeps running due to some weird structure check.

* Shorten description lines and add structure info

- Shortened the longest description lines since they were too long;
- Added a note about needing to force structure check by powering on the multi;
- Spotless.

* Remove explosion possibility

- Removed doExplosion from the EU generation part of the cody, now the machine only stops when the dynamo is full;
- Renamed variables and changed comments and tooltip to match the way the code works now.

* Change ticks to seconds in final variable

* spotlessApply (#257)

Co-authored-by: GitHub GTNH Actions <>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
(cherry picked from commit 6286ee0)
  • Loading branch information
Steelux8 authored and Dream-Master committed May 20, 2024
1 parent 0757dad commit 8417ccd
Showing 1 changed file with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import goodgenerator.util.DescTextLocalization;
import gregtech.api.GregTech_API;
import gregtech.api.enums.GT_HatchElement;
import gregtech.api.enums.TickTime;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
Expand All @@ -55,8 +56,11 @@ public class UniversalChemicalFuelEngine extends GT_MetaTileEntity_TooltipMultiB
protected final double GAS_EFFICIENCY_COEFFICIENT = 0.04D;
protected final double ROCKET_EFFICIENCY_COEFFICIENT = 0.005D;
protected final double EFFICIENCY_CEILING = 1.5D;
protected final int HEATING_TIMER = TickTime.SECOND * 10;

private long tEff;
private int heatingTicks;
private boolean isStoppingSafe;

private IStructureDefinition<UniversalChemicalFuelEngine> multiDefinition = null;

Expand Down Expand Up @@ -183,9 +187,13 @@ protected GT_Multiblock_Tooltip_Builder createTooltip() {
tt.addMachineType("Chemical Engine").addInfo("Controller block for the Chemical Engine")
.addInfo("BURNING BURNING BURNING").addInfo("Use combustible liquid to generate power.")
.addInfo("You need to supply Combustion Promoter to keep it running.")
.addInfo("This engine will consume all the fuel and combustion promoter in the hatch every second.")
.addInfo("It will consume all the fuel and promoter in the hatch every second.")
.addInfo("If the Dynamo Hatch's buffer fills up, the machine will stop.")
.addInfo("When turned on, there's 10-second period where the machine will not stop.")
.addInfo("Even if it doesn't stop, all the fuel in the hatch will be consumed.")
.addInfo("The efficiency is determined by the proportion of Combustion Promoter to fuel.")
.addInfo("The proportion is bigger, and the efficiency will be higher.")
.addInfo("Start machine with power button to force structure check.")
.addInfo("It creates sqrt(Current Output Power) pollution every second")
.addInfo(
"If you forget to supply Combustion Promoter, this engine will swallow all the fuel "
Expand All @@ -195,9 +203,10 @@ protected GT_Multiblock_Tooltip_Builder createTooltip() {
+ ".")
.addInfo("The efficiency is up to 150%.").addInfo("The structure is too complex!")
.addInfo(BLUE_PRINT_INFO).addSeparator().beginStructureBlock(5, 4, 9, false)
.addMaintenanceHatch("Hint block with dot 1").addMufflerHatch("Hint block with dot 2")
.addInputHatch("Hint block with dot 3").addDynamoHatch("Hint block with dot 4")
.toolTipFinisher("Good Generator");
.addMaintenanceHatch("Hint block with dot 1")
.addMufflerHatch("Hint block with dot 2 (fill all slots with mufflers)")
.addInputHatch("Hint block with dot 3 (fill all slots with input hatches)")
.addDynamoHatch("Hint block with dot 4").toolTipFinisher("Good Generator");
return tt;
}

Expand Down Expand Up @@ -242,9 +251,24 @@ protected CheckRecipeResult processFuel(ArrayList<FluidStack> tFluids, RecipeMap
return CheckRecipeResultRegistry.NO_FUEL_FOUND;
}

@Override
public void stopMachine() {
// Reset the counter for heating, so that it works again when the machine restarts
heatingTicks = 0;
super.stopMachine();
}

@Override
public boolean onRunningTick(ItemStack stack) {
super.onRunningTick(stack);
// Counts ticks up to the defined timer (200 ticks, 10 seconds)
// The multiblock will not stop due to excess energy during this time
// Machine used to explode in the past, this timer was first made to prevent that
if (heatingTicks < HEATING_TIMER) {
heatingTicks++;
isStoppingSafe = true;
} else if (isStoppingSafe) isStoppingSafe = false;

if (this.getBaseMetaTileEntity().isServerSide()) {
addAutoEnergy();
}
Expand Down Expand Up @@ -275,13 +299,17 @@ void addAutoEnergy() {
GT_MetaTileEntity_Hatch_Dynamo tHatch = mDynamoHatches.get(0);
if (tHatch.maxEUOutput() * tHatch.maxAmperesOut() >= exEU) {
tHatch.setEUVar(Math.min(tHatch.maxEUStore(), tHatch.getBaseMetaTileEntity().getStoredEU() + exEU));
} else tHatch.doExplosion(tHatch.maxEUOutput());
} else if (!isStoppingSafe) {
stopMachine();
}
}
if (!eDynamoMulti.isEmpty()) {
GT_MetaTileEntity_Hatch_DynamoMulti tHatch = eDynamoMulti.get(0);
if (tHatch.maxEUOutput() * tHatch.maxAmperesOut() >= exEU) {
tHatch.setEUVar(Math.min(tHatch.maxEUStore(), tHatch.getBaseMetaTileEntity().getStoredEU() + exEU));
} else tHatch.doExplosion(tHatch.maxEUOutput());
} else if (!isStoppingSafe) {
stopMachine();
}
}
}

Expand Down

0 comments on commit 8417ccd

Please sign in to comment.