aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGDCloud <93287602+GDCloudstrike@users.noreply.github.com>2024-11-03 19:47:09 +0100
committerGitHub <noreply@github.com>2024-11-03 18:47:09 +0000
commite8a8baa0e8691cbd556431f2a94d02a63dd85698 (patch)
tree261b91c4830215d09c4c0e604dad7aa6d78a1112
parentf905da4c3bf9cdd2614b2ea0062203859a646af1 (diff)
downloadGT5-Unofficial-e8a8baa0e8691cbd556431f2a94d02a63dd85698.tar.gz
GT5-Unofficial-e8a8baa0e8691cbd556431f2a94d02a63dd85698.tar.bz2
GT5-Unofficial-e8a8baa0e8691cbd556431f2a94d02a63dd85698.zip
Fix DTPF convergence catalyst consumption for non-catalyst recipes (#3399)
Co-authored-by: Martin Robertz <dream-master@gmx.net> Co-authored-by: Maya <10861407+serenibyss@users.noreply.github.com>
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/multi/MTEPlasmaForge.java74
1 files changed, 54 insertions, 20 deletions
diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEPlasmaForge.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEPlasmaForge.java
index 69a9401288..a41ee1128d 100644
--- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEPlasmaForge.java
+++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEPlasmaForge.java
@@ -18,6 +18,7 @@ import static gregtech.api.enums.Textures.BlockIcons.casingTexturePages;
import static gregtech.api.metatileentity.BaseTileEntity.TOOLTIP_DELAY;
import static gregtech.api.util.GTStructureUtility.buildHatchAdder;
import static gregtech.api.util.GTStructureUtility.ofCoil;
+import static gregtech.api.util.GTUtility.filterValidMTEs;
import static gregtech.api.util.GTUtility.validMTEList;
import static net.minecraft.util.StatCollector.translateToLocal;
@@ -74,6 +75,7 @@ import gregtech.api.metatileentity.GregTechTileClientEvents;
import gregtech.api.metatileentity.implementations.MTEExtendedPowerMultiBlockBase;
import gregtech.api.metatileentity.implementations.MTEHatch;
import gregtech.api.metatileentity.implementations.MTEHatchEnergy;
+import gregtech.api.metatileentity.implementations.MTEHatchInput;
import gregtech.api.objects.GTChunkManager;
import gregtech.api.recipe.RecipeMap;
import gregtech.api.recipe.RecipeMaps;
@@ -142,6 +144,8 @@ public class MTEPlasmaForge extends MTEExtendedPowerMultiBlockBase<MTEPlasmaForg
private int mHeatingCapacity = 0;
private long running_time = 0;
private boolean convergence = false;
+ private boolean doesRecipeHaveNativeCatInput = true;
+ private boolean isEnoughCatalystPresent = true;
private HeatingCoilLevel mCoilLevel;
private OverclockCalculator overclockCalculator;
@@ -766,7 +770,9 @@ public class MTEPlasmaForge extends MTEExtendedPowerMultiBlockBase<MTEPlasmaForg
overclockCalculator = super.createOverclockCalculator(recipe).setRecipeHeat(recipe.mSpecialValue)
.setMachineHeat(mHeatingCapacity);
if (discount == maximum_discount && convergence) {
- overclockCalculator = overclockCalculator.enablePerfectOC();
+ if (doesRecipeHaveNativeCatInput || isEnoughCatalystPresent) {
+ overclockCalculator = overclockCalculator.enablePerfectOC();
+ }
}
return overclockCalculator;
}
@@ -787,6 +793,7 @@ public class MTEPlasmaForge extends MTEExtendedPowerMultiBlockBase<MTEPlasmaForg
@Nonnull
protected GTRecipe recipeAfterAdjustments(@Nonnull GTRecipe recipe) {
+ doesRecipeHaveNativeCatInput = true;
GTRecipe tRecipe = recipe.copy();
boolean adjusted = false;
outside: for (int i = 0; i < recipe.mFluidInputs.length; i++) {
@@ -811,6 +818,8 @@ public class MTEPlasmaForge extends MTEExtendedPowerMultiBlockBase<MTEPlasmaForg
&& convergence
&& overclockCalculator != null
&& overclockCalculator.getCalculationStatus()) {
+ doesRecipeHaveNativeCatInput = false;
+ isEnoughCatalystPresent = checkCatalyst();
recalculateDiscount();
calculateCatalystIncrease(tRecipe, 0, true);
getBaseMetaTileEntity().sendBlockEvent(GregTechTileClientEvents.CHANGE_CUSTOM_DATA, getUpdateData());
@@ -818,6 +827,35 @@ public class MTEPlasmaForge extends MTEExtendedPowerMultiBlockBase<MTEPlasmaForg
return tRecipe;
}
+ private boolean checkCatalyst() {
+ FluidStack selectedCatalyst = valid_fuels[catalystTypeForRecipesWithoutCatalyst - 1];
+
+ double sub1TickMultiplier = Math.max(Math.floor(1 / recipeDuration), 1d);
+ int neededAmount = (int) Math.min(
+ maximum_discount * (isBatchModeEnabled() ? getMaxBatchSize() : 1)
+ * sub1TickMultiplier
+ * extraCatalystNeeded,
+ Integer.MAX_VALUE);
+ selectedCatalyst.amount = neededAmount;
+ startRecipeProcessing();
+ for (MTEHatchInput hatch : filterValidMTEs(mInputHatches)) {
+ FluidStack checked = hatch.drain(ForgeDirection.UNKNOWN, selectedCatalyst, true);
+
+ if (checked == null) {
+ continue;
+ }
+
+ neededAmount -= checked.amount;
+
+ if (neededAmount == 0) {
+ endRecipeProcessing();
+ return true;
+ }
+ }
+ endRecipeProcessing();
+ return false;
+ }
+
@Override
public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) {
@@ -984,16 +1022,16 @@ public class MTEPlasmaForge extends MTEExtendedPowerMultiBlockBase<MTEPlasmaForg
}
private int catalystTypeForRecipesWithoutCatalyst = 1;
+ private int extraCatalystNeeded;
+ private double recipeDuration;
private void calculateCatalystIncrease(GTRecipe recipe, int index, boolean withoutCatalyst) {
long machineConsumption = overclockCalculator.getConsumption();
int numberOfOverclocks = (int) Math.ceil(calculateTier(machineConsumption) - GTUtility.getTier(recipe.mEUt));
- double recipeDuration = recipe.mDuration / Math.pow(4, numberOfOverclocks);
+ recipeDuration = recipe.mDuration / Math.pow(4, numberOfOverclocks);
// Power difference between regular and perfect OCs for this recipe duration
long extraPowerNeeded = (long) ((Math.pow(2, numberOfOverclocks) - 1) * machineConsumption * recipeDuration);
- int inputFluids = recipe.mFluidInputs.length;
int outputFluids = recipe.mFluidOutputs.length;
- int extraCatalystNeeded;
Fluid validFuel;
if (!withoutCatalyst) {
validFuel = recipe.mFluidInputs[index].getFluid();
@@ -1009,26 +1047,22 @@ public class MTEPlasmaForge extends MTEExtendedPowerMultiBlockBase<MTEPlasmaForg
}
}
} else {
- // Add chosen catalyst as recipe input
+ // Calculate extra catalyst amount
validFuel = valid_fuels[catalystTypeForRecipesWithoutCatalyst - 1].getFluid();
extraCatalystNeeded = (int) (extraPowerNeeded / FUEL_ENERGY_VALUES.get(validFuel)
.getLeft());
- FluidStack[] newInputFluids = new FluidStack[inputFluids + 1];
- for (int i = 0; i < inputFluids; i++) {
- newInputFluids[i] = recipe.mFluidInputs[i].copy();
- }
- newInputFluids[inputFluids] = new FluidStack(validFuel, extraCatalystNeeded / 2);
- recipe.mFluidInputs = newInputFluids;
- // Add residue as recipe output
- FluidStack[] newOutputFluids = new FluidStack[outputFluids + 1];
- for (int i = 0; i < outputFluids; i++) {
- newOutputFluids[i] = recipe.mFluidOutputs[i].copy();
+ if (isEnoughCatalystPresent) {
+ // Add residue as recipe output
+ FluidStack[] newOutputFluids = new FluidStack[outputFluids + 1];
+ for (int i = 0; i < outputFluids; i++) {
+ newOutputFluids[i] = recipe.mFluidOutputs[i].copy();
+ }
+ newOutputFluids[outputFluids] = new FluidStack(
+ MaterialsUEVplus.DimensionallyTranscendentResidue.getFluid(1),
+ (int) (extraCatalystNeeded * FUEL_ENERGY_VALUES.get(validFuel)
+ .getRight()));
+ recipe.mFluidOutputs = newOutputFluids;
}
- newOutputFluids[outputFluids] = new FluidStack(
- MaterialsUEVplus.DimensionallyTranscendentResidue.getFluid(1),
- (int) (extraCatalystNeeded * FUEL_ENERGY_VALUES.get(validFuel)
- .getRight()));
- recipe.mFluidOutputs = newOutputFluids;
}
}