From f8771316cfae2c8ad48c1adc0fac1f596f80ac04 Mon Sep 17 00:00:00 2001 From: HoleFish <48403212+HoleFish@users.noreply.github.com> Date: Sun, 28 Jul 2024 23:10:59 +0800 Subject: [PATCH] Fix plasma mixer power consumption and overflow (#2778) * fix * better fix --- .../check/CheckRecipeResultRegistry.java | 7 +++ .../ResultInsufficientStartupPowerBigInt.java | 59 +++++++++++++++++++ ...etaTileEntity_TranscendentPlasmaMixer.java | 18 ++++-- 3 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 src/main/java/gregtech/api/recipe/check/ResultInsufficientStartupPowerBigInt.java diff --git a/src/main/java/gregtech/api/recipe/check/CheckRecipeResultRegistry.java b/src/main/java/gregtech/api/recipe/check/CheckRecipeResultRegistry.java index 7112b478860..41ea858fecb 100644 --- a/src/main/java/gregtech/api/recipe/check/CheckRecipeResultRegistry.java +++ b/src/main/java/gregtech/api/recipe/check/CheckRecipeResultRegistry.java @@ -1,5 +1,6 @@ package gregtech.api.recipe.check; +import java.math.BigInteger; import java.util.HashMap; import java.util.Map; @@ -142,11 +143,17 @@ public static CheckRecipeResult insufficientStartupPower(int required) { return new ResultInsufficientStartupPower(required); } + @Nonnull + public static CheckRecipeResult insufficientStartupPower(BigInteger required) { + return new ResultInsufficientStartupPowerBigInt(required); + } + static { register(new SimpleCheckRecipeResult(false, "", false)); register(new ResultInsufficientPower(0)); register(new ResultInsufficientHeat(0)); register(new ResultInsufficientMachineTier(0)); register(new ResultInsufficientStartupPower(0)); + register(new ResultInsufficientStartupPowerBigInt(BigInteger.ZERO)); } } diff --git a/src/main/java/gregtech/api/recipe/check/ResultInsufficientStartupPowerBigInt.java b/src/main/java/gregtech/api/recipe/check/ResultInsufficientStartupPowerBigInt.java new file mode 100644 index 00000000000..6a719b3c9c2 --- /dev/null +++ b/src/main/java/gregtech/api/recipe/check/ResultInsufficientStartupPowerBigInt.java @@ -0,0 +1,59 @@ +package gregtech.api.recipe.check; + +import static util.Util.toStandardForm; + +import java.math.BigInteger; +import java.util.Objects; + +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.StatCollector; + +import org.jetbrains.annotations.NotNull; + +public class ResultInsufficientStartupPowerBigInt implements CheckRecipeResult { + + private String required; + + public ResultInsufficientStartupPowerBigInt(BigInteger required) { + this.required = toStandardForm(required); + } + + @NotNull + @Override + public String getID() { + return "insufficient_startup_power_bigint"; + } + + @Override + public boolean wasSuccessful() { + return false; + } + + @NotNull + @Override + public String getDisplayString() { + return Objects.requireNonNull( + StatCollector.translateToLocalFormatted("GT5U.gui.text.insufficient_startup_power", required)); + } + + @NotNull + @Override + public CheckRecipeResult newInstance() { + return new ResultInsufficientStartupPowerBigInt(BigInteger.ZERO); + } + + @Override + public void encode(@NotNull PacketBuffer buffer) { + try { + buffer.writeStringToBuffer(required); + } catch (Exception ignored) {} + + } + + @Override + public void decode(PacketBuffer buffer) { + try { + required = buffer.readStringFromBuffer(32768); + } catch (Exception ignored) {} + } +} 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 c36a524971b..2dba9e7c9d8 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 @@ -172,24 +172,30 @@ public RecipeMap getRecipeMap() { protected ProcessingLogic createProcessingLogic() { return new ProcessingLogic() { + BigInteger recipeEU; + @NotNull @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); + BigInteger availableEU = getUserEU(ownerUUID); + recipeEU = BigInteger.valueOf(10L * recipe.mEUt * recipe.mDuration); + if (availableEU.compareTo(recipeEU) < 0) { + return CheckRecipeResultRegistry.insufficientStartupPower(recipeEU); } + maxParallel = availableEU.divide(recipeEU) + .min(BigInteger.valueOf(maxParallel)) + .intValue(); return CheckRecipeResultRegistry.SUCCESSFUL; } @NotNull @Override protected CheckRecipeResult onRecipeStart(@Nonnull GT_Recipe recipe) { - mWirelessEUt = 10L * (long) recipe.mEUt * (long) multiplier; + BigInteger finalConsumption = recipeEU.multiply(BigInteger.valueOf(-calculatedParallels)); // 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); + if (!addEUToGlobalEnergyMap(ownerUUID, finalConsumption)) { + return CheckRecipeResultRegistry.insufficientStartupPower(finalConsumption); } // Energy consumed all at once from wireless net. setCalculatedEut(0);