diff options
author | Alex Bee <a.bramley@gmail.com> | 2023-12-03 12:26:45 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-03 13:26:45 +0100 |
commit | b6f7c5da89d80ee2b4a73951f1063217e02f215c (patch) | |
tree | f027fdb8ba80c751aaee1b459323f8f22070e56d /src/main | |
parent | 2568913fd034f727c6da252a6b2a845676dfd3b0 (diff) | |
download | GT5-Unofficial-b6f7c5da89d80ee2b4a73951f1063217e02f215c.tar.gz GT5-Unofficial-b6f7c5da89d80ee2b4a73951f1063217e02f215c.tar.bz2 GT5-Unofficial-b6f7c5da89d80ee2b4a73951f1063217e02f215c.zip |
Plasma Mixer: only consume power when recipe starts. Fixes #14895. (#2375)
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/gregtech/api/logic/ProcessingLogic.java | 18 | ||||
-rw-r--r-- | src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_TranscendentPlasmaMixer.java | 25 |
2 files changed, 34 insertions, 9 deletions
diff --git a/src/main/java/gregtech/api/logic/ProcessingLogic.java b/src/main/java/gregtech/api/logic/ProcessingLogic.java index 4758af3254..803abafbe3 100644 --- a/src/main/java/gregtech/api/logic/ProcessingLogic.java +++ b/src/main/java/gregtech/api/logic/ProcessingLogic.java @@ -378,6 +378,11 @@ public class ProcessingLogic { } duration = (int) finalDuration; + CheckRecipeResult hookResult = onRecipeStart(recipe); + if (!hookResult.wasSuccessful()) { + return hookResult; + } + outputItems = helper.getItemOutputs(); outputFluids = helper.getFluidOutputs(); @@ -471,6 +476,19 @@ public class ProcessingLogic { .setEUtIncreasePerOC(overClockPowerIncrease); } + /** + * Override to perform additional logic when recipe starts. + * + * This is called when the recipe processing logic has finished all + * checks, consumed all inputs, but has not yet set the outputs to + * be produced. Returning a result other than SUCCESSFUL will void + * all inputs! + */ + @Nonnull + protected CheckRecipeResult onRecipeStart(@Nonnull GT_Recipe recipe) { + return CheckRecipeResultRegistry.SUCCESSFUL; + } + // endregion // region Getters diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_TranscendentPlasmaMixer.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_TranscendentPlasmaMixer.java index be034dbc1f..dedcc1ac6a 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_TranscendentPlasmaMixer.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_TranscendentPlasmaMixer.java @@ -18,6 +18,8 @@ import static java.lang.Math.max; import static net.minecraft.util.EnumChatFormatting.GOLD; import static net.minecraft.util.EnumChatFormatting.GRAY; +import java.math.BigInteger; + import javax.annotation.Nonnull; import net.minecraft.item.ItemStack; @@ -155,9 +157,23 @@ public class GT_MetaTileEntity_TranscendentPlasmaMixer @Override protected CheckRecipeResult validateRecipe(@Nonnull GT_Recipe recipe) { mWirelessEUt = 10L * (long) recipe.mEUt * (long) multiplier; + if (getUserEU(ownerUUID).compareTo(BigInteger.valueOf(mWirelessEUt * recipe.mDuration)) < 0) { + return CheckRecipeResultRegistry.insufficientPower(mWirelessEUt * recipe.mDuration); + } + return CheckRecipeResultRegistry.SUCCESSFUL; + } + + @NotNull + @Override + protected CheckRecipeResult onRecipeStart(@Nonnull GT_Recipe recipe) { + mWirelessEUt = 10L * (long) recipe.mEUt * (long) multiplier; + // This will void the inputs if wireless energy has dropped + // below the required amount between validateRecipe and here. if (!addEUToGlobalEnergyMap(ownerUUID, -mWirelessEUt * recipe.mDuration)) { return CheckRecipeResultRegistry.insufficientPower(mWirelessEUt * recipe.mDuration); } + // Energy consumed all at once from wireless net. + setCalculatedEut(0); return CheckRecipeResultRegistry.SUCCESSFUL; } @@ -166,15 +182,6 @@ public class GT_MetaTileEntity_TranscendentPlasmaMixer protected GT_OverclockCalculator createOverclockCalculator(@Nonnull GT_Recipe recipe) { return GT_OverclockCalculator.ofNoOverclock(recipe); } - - @NotNull - @Override - public CheckRecipeResult process() { - CheckRecipeResult result = super.process(); - // Power will be directly consumed through wireless - setCalculatedEut(0); - return result; - } }.setMaxParallelSupplier(() -> { ItemStack controllerStack = getControllerSlot(); if (controllerStack != null && controllerStack.getItem() instanceof GT_IntegratedCircuit_Item) { |