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

Prevent Instant UCFE Explosions #256

Merged
merged 6 commits into from
May 19, 2024
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.ArrayList;
import java.util.List;

import gregtech.api.enums.TickTime;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.common.util.ForgeDirection;
Expand Down Expand Up @@ -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
Loading