Skip to content

Commit

Permalink
Fix Heat Exchanger interaction with Stocking Input Hatch(ME) (#3271)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Robertz <dream-master@gmx.net>
  • Loading branch information
reobf and Dream-Master committed Sep 26, 2024
1 parent 05f8dd4 commit 302a698
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
import gregtech.api.util.GTUtility;
import gregtech.api.util.IGTHatchAdder;
import gregtech.api.util.MultiblockTooltipBuilder;
import gregtech.common.tileentities.machines.IRecipeProcessingAwareHatch;
import gregtech.common.tileentities.machines.MTEHatchInputME;

public class MTEExtremeHeatExchanger extends MTETooltipMultiBlockBaseEM
implements IConstructable, ISurvivalConstructable {
Expand Down Expand Up @@ -223,18 +225,26 @@ protected MultiblockTooltipBuilder createTooltip() {
@Override
public @NotNull CheckRecipeResult checkProcessing_EM() {
tRunningRecipe = null;
if (mHotFluidHatch.getFluid() == null) return CheckRecipeResultRegistry.SUCCESSFUL;
FluidStack hotFluid = null;
if (mHotFluidHatch instanceof MTEHatchInputME inputME) {
FluidStack[] fluids = inputME.getStoredFluids();
if (fluids.length > 0) {
hotFluid = fluids[0];
}
} else {
hotFluid = mHotFluidHatch.getFluid();
}
if (hotFluid == null) return CheckRecipeResultRegistry.SUCCESSFUL;
ExtremeHeatExchangerRecipe tRecipe = (ExtremeHeatExchangerRecipe) GoodGeneratorRecipeMaps.extremeHeatExchangerFuels
.getBackend()
.findFuel(mHotFluidHatch.getFluid());
.findFuel(hotFluid);
if (tRecipe == null) return CheckRecipeResultRegistry.NO_RECIPE;
tRunningRecipe = tRecipe;
this.hotName = mHotFluidHatch.getFluid()
.getFluid()
this.hotName = hotFluid.getFluid()
.getName();
int tMaxConsume = tRecipe.getMaxHotFluidConsume();
int transformed_threshold = tRecipe.mSpecialValue;
int tRealConsume = Math.min(tMaxConsume, mHotFluidHatch.getFluid().amount);
int tRealConsume = Math.min(tMaxConsume, hotFluid.amount);
double penalty = 0.0d;
double efficiency = 1d;
int shs_reduction_per_config = 150;
Expand All @@ -255,7 +265,8 @@ protected MultiblockTooltipBuilder createTooltip() {

this.mMaxProgresstime = 20;
this.mEUt = (int) (tRecipe.getEUt() * efficiency * ((double) tRealConsume / (double) tMaxConsume));
mHotFluidHatch.drain(tRealConsume, true);
// the 3-arg drain will work on both normal hatch and ME hatch
mHotFluidHatch.drain(ForgeDirection.UNKNOWN, new FluidStack(hotFluid.getFluid(), tRealConsume), true);
mCooledFluidHatch.fill(new FluidStack(tRecipe.getCooledFluid(), tRealConsume), true);
this.mEfficiencyIncrease = 160;

Expand All @@ -269,7 +280,10 @@ public boolean onRunningTick(ItemStack aStack) {
int waterAmount = (int) (this.mEUt / getUnitSteamPower(tReadySteam.getName())) / 160;
if (waterAmount < 0) return false;
int steamToOutput;
if (depleteInput(GTModHandler.getDistilledWater(waterAmount))) {
startRecipeProcessing();
boolean isDepleteSuccess = depleteInput(GTModHandler.getDistilledWater(waterAmount));
endRecipeProcessing();
if (isDepleteSuccess) {
if (tRunningRecipe.mFluidInputs[0].getUnlocalizedName()
.contains("plasma")) {
steamToOutput = waterAmount * 160 / 1000;
Expand Down Expand Up @@ -421,4 +435,20 @@ public IGTHatchAdder<? super MTEExtremeHeatExchanger> adder() {
return adder;
}
}

@Override
public void startRecipeProcessing() {
super.startRecipeProcessing();
if (mHotFluidHatch instanceof IRecipeProcessingAwareHatch aware && mHotFluidHatch.isValid()) {
aware.startRecipeProcessing();
}
}

@Override
public void endRecipeProcessing() {
super.endRecipeProcessing();
if (mHotFluidHatch instanceof IRecipeProcessingAwareHatch aware && mHotFluidHatch.isValid()) {
aware.endRecipeProcessing(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import gregtech.api.util.GTModHandler;
import gregtech.api.util.GTUtility;
import gregtech.api.util.MultiblockTooltipBuilder;
import gregtech.common.tileentities.machines.IRecipeProcessingAwareHatch;
import gregtech.common.tileentities.machines.MTEHatchInputME;

public class MTEHeatExchanger extends MTEEnhancedMultiBlockBase<MTEHeatExchanger> implements ISurvivalConstructable {

Expand Down Expand Up @@ -179,9 +181,19 @@ protected IAlignmentLimits getInitialAlignmentLimits() {
@Override
@Nonnull
public CheckRecipeResult checkProcessing() {
if (mInputHotFluidHatch.getFluid() == null) return CheckRecipeResultRegistry.NO_RECIPE;
FluidStack hotFluid = null;
if (mInputHotFluidHatch instanceof MTEHatchInputME inputME) {
FluidStack[] fluids = inputME.getStoredFluids();
if (fluids.length > 0) {
hotFluid = fluids[0];
}
} else {
hotFluid = mInputHotFluidHatch.getFluid();
}

if (hotFluid == null) return CheckRecipeResultRegistry.NO_RECIPE;

int fluidAmountToConsume = mInputHotFluidHatch.getFluidAmount(); // how much fluid is in hatch
int fluidAmountToConsume = hotFluid.amount; // how much fluid is in hatch

superheated_threshold = 4000; // default: must have 4000L per second to generate superheated steam
float efficiency = 1f; // default: operate at 100% efficiency with no integrated circuitry
Expand All @@ -202,9 +214,7 @@ public CheckRecipeResult checkProcessing() {

efficiency -= penalty;

var coolant = LHECoolantRegistry.getCoolant(
mInputHotFluidHatch.getFluid()
.getFluid());
var coolant = LHECoolantRegistry.getCoolant(hotFluid.getFluid());

if (coolant == null) {
superheated_threshold = 0;
Expand All @@ -220,8 +230,9 @@ public CheckRecipeResult checkProcessing() {

// Don't consume too much hot fluid per second
fluidAmountToConsume = Math.min(fluidAmountToConsume, superheated_threshold * 2);

mInputHotFluidHatch.drain(fluidAmountToConsume, true);
// the 3-arg drain will work on both normal hatch and ME hatch
mInputHotFluidHatch
.drain(ForgeDirection.UNKNOWN, new FluidStack(hotFluid.getFluid(), fluidAmountToConsume), true);
mOutputColdFluidHatch.fill(coolant.getColdFluid(fluidAmountToConsume), true);

this.mMaxProgresstime = 20;
Expand Down Expand Up @@ -393,4 +404,20 @@ public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBu
if (mMachine) return -1;
return survivialBuildPiece(STRUCTURE_PIECE_MAIN, stackSize, 1, 3, 0, elementBudget, env, false, true);
}

@Override
public void startRecipeProcessing() {
super.startRecipeProcessing();
if (mInputHotFluidHatch instanceof IRecipeProcessingAwareHatch aware && mInputHotFluidHatch.isValid()) {
aware.startRecipeProcessing();
}
}

@Override
public void endRecipeProcessing() {
super.endRecipeProcessing();
if (mInputHotFluidHatch instanceof IRecipeProcessingAwareHatch aware && mInputHotFluidHatch.isValid()) {
aware.endRecipeProcessing(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;

Expand All @@ -35,6 +36,8 @@
import gregtech.api.util.GTModHandler;
import gregtech.api.util.GTUtility;
import gregtech.api.util.MultiblockTooltipBuilder;
import gregtech.common.tileentities.machines.IRecipeProcessingAwareHatch;
import gregtech.common.tileentities.machines.MTEHatchInputME;
import gtPlusPlus.core.block.ModBlocks;
import gtPlusPlus.core.block.base.BasicBlock.BlockTypes;
import gtPlusPlus.core.block.base.BlockBaseModular;
Expand Down Expand Up @@ -168,9 +171,18 @@ protected IAlignmentLimits getInitialAlignmentLimits() {

@Override
public @NotNull CheckRecipeResult checkProcessing() {
if (mInputHotFluidHatch.getFluid() == null) return CheckRecipeResultRegistry.SUCCESSFUL;
FluidStack hotFluid = null;
if (mInputHotFluidHatch instanceof MTEHatchInputME inputME) {
FluidStack[] fluids = inputME.getStoredFluids();
if (fluids.length > 0) {
hotFluid = fluids[0];
}
} else {
hotFluid = mInputHotFluidHatch.getFluid();
}
if (hotFluid == null) return CheckRecipeResultRegistry.SUCCESSFUL;

int fluidAmountToConsume = mInputHotFluidHatch.getFluidAmount(); // how much fluid is in hatch
int fluidAmountToConsume = hotFluid.amount; // how much fluid is in hatch

// The XL LHE works as fast as 32 regular LHEs. These are the comments from the original LHE,
// with changes where the values needed to change for the 32x speed multiplier
Expand All @@ -193,9 +205,7 @@ protected IAlignmentLimits getInitialAlignmentLimits() {

efficiency -= penalty;

var coolant = LHECoolantRegistry.getCoolant(
mInputHotFluidHatch.getFluid()
.getFluid());
var coolant = LHECoolantRegistry.getCoolant(hotFluid.getFluid());

if (coolant == null) {
superheated_threshold = 0;
Expand All @@ -210,8 +220,9 @@ protected IAlignmentLimits getInitialAlignmentLimits() {

// Don't consume too much hot fluid per second, maximum is 2x SH threshold.
fluidAmountToConsume = Math.min(fluidAmountToConsume, superheated_threshold * 2);

mInputHotFluidHatch.drain(fluidAmountToConsume, true);
// the 3-arg drain will work on both normal hatch and ME hatch
mInputHotFluidHatch
.drain(ForgeDirection.UNKNOWN, new FluidStack(hotFluid.getFluid(), fluidAmountToConsume), true);
mOutputColdFluidHatch.fill(coolant.getColdFluid(fluidAmountToConsume), true);

this.mMaxProgresstime = 20;
Expand Down Expand Up @@ -242,6 +253,7 @@ public boolean onRunningTick(ItemStack aStack) {
// 1:160 ratio with distilled water consumption

FluidStack distilledStack = GTModHandler.getDistilledWater(distilledConsumed);
startRecipeProcessing();
if (depleteInput(distilledStack)) // Consume the distilled water
{
if (superheated) {
Expand All @@ -255,6 +267,7 @@ public boolean onRunningTick(ItemStack aStack) {
GTLog.exp.println(this.mName + " had no more Distilled water!");
explodeMultiblock(); // Generate crater
}
endRecipeProcessing();
}
return true;
}
Expand Down Expand Up @@ -393,4 +406,20 @@ public static Block getFrame() {
}
return sFrame;
}

@Override
public void startRecipeProcessing() {
super.startRecipeProcessing();
if (mInputHotFluidHatch instanceof IRecipeProcessingAwareHatch aware && mInputHotFluidHatch.isValid()) {
aware.startRecipeProcessing();
}
}

@Override
public void endRecipeProcessing() {
super.endRecipeProcessing();
if (mInputHotFluidHatch instanceof IRecipeProcessingAwareHatch aware && mInputHotFluidHatch.isValid()) {
aware.endRecipeProcessing(this);
}
}
}

0 comments on commit 302a698

Please sign in to comment.