From 4647e2e8be384582ad09c4f97a4c50dff4e05e4b Mon Sep 17 00:00:00 2001 From: BlueWeabo Date: Fri, 28 Jul 2023 13:13:57 +0300 Subject: Add more API to ParallelHelper and rework OverclockCalculator (#2185) * refactor OC calc * somewhat refactor parallel helper * fix PA not OCing correctly no clue why it wasn't using super and then setting the duration again. * make use of new api to make fusion cleaner * make batch mode actually dynamic * add another reason for 0 parallel * move variables around to try and group them together * address reviews * add overclocking past 1 tick by adding parallels * add null check and make a basic calculator to prevent npe * check null recipeMap supplier * address reviews * addressing of reviews * make it possible to call some OverclockCalculator methods through static methods * address reviews * make sure one doesn't get too many OCs when calculatin under 1 tick * add api for custom duration under one tick and fix batch mode doing 0 ticking * fix not calculating duration under 1 tick correctly * spotless * try to have correct eut consumption * address review * make sure mk5 fusion is said in nei * fix eutCalculating under one tick way too much and address reviews * remove roundUp voltage --- .../api/logic/ComplexParallelProcessingLogic.java | 4 +- .../java/gregtech/api/logic/ProcessingLogic.java | 55 +++++++++++++++++----- 2 files changed, 44 insertions(+), 15 deletions(-) (limited to 'src/main/java/gregtech/api/logic') diff --git a/src/main/java/gregtech/api/logic/ComplexParallelProcessingLogic.java b/src/main/java/gregtech/api/logic/ComplexParallelProcessingLogic.java index 65d7ea5397..05d39cd02c 100644 --- a/src/main/java/gregtech/api/logic/ComplexParallelProcessingLogic.java +++ b/src/main/java/gregtech/api/logic/ComplexParallelProcessingLogic.java @@ -126,8 +126,8 @@ public class ComplexParallelProcessingLogic { .setFluidInputs(inputFluids[index]) .setAvailableEUt(availableEut[index]) .setMachine(tileEntity, isItemVoidProtected[index], isFluidVoidProtected[index]) - .enableConsumption() - .enableOutputCalculation(); + .setConsumption(true) + .setOutputCalculation(true); helper.build(); diff --git a/src/main/java/gregtech/api/logic/ProcessingLogic.java b/src/main/java/gregtech/api/logic/ProcessingLogic.java index cf3bef97e8..2a2e0e5137 100644 --- a/src/main/java/gregtech/api/logic/ProcessingLogic.java +++ b/src/main/java/gregtech/api/logic/ProcessingLogic.java @@ -53,6 +53,7 @@ public class ProcessingLogic { protected int batchSize = 1; protected float euModifier = 1.0f; protected float speedBoost = 1.0f; + protected boolean amperageOC = true; public ProcessingLogic() {} @@ -227,6 +228,14 @@ public class ProcessingLogic { return this.setOverclock(2, 2); } + /** + * Sets wether the multi should use amperage to OC or not + */ + public ProcessingLogic setAmperageOC(boolean amperageOC) { + this.amperageOC = amperageOC; + return this; + } + /** * Clears calculated results and provided machine inputs to prepare for the next machine operation. */ @@ -301,16 +310,17 @@ public class ProcessingLogic { } GT_ParallelHelper helper = createParallelHelper(recipe); - + GT_OverclockCalculator calculator = createOverclockCalculator(recipe); + helper.setCalculator(calculator); helper.build(); - if (helper.getCurrentParallel() <= 0) return CheckRecipeResultRegistry.OUTPUT_FULL; + if (!helper.getResult() + .wasSuccessful()) { + return helper.getResult(); + } calculatedParallels = helper.getCurrentParallel(); - GT_OverclockCalculator calculator = createOverclockCalculator(recipe, helper); - - calculator.calculate(); if (calculator.getConsumption() == Long.MAX_VALUE) { return CheckRecipeResultRegistry.POWER_OVERFLOW; } @@ -346,8 +356,14 @@ public class ProcessingLogic { @Nonnull protected FindRecipeResult findRecipe(@Nullable GT_Recipe_Map map) { if (map == null) return FindRecipeResult.NOT_FOUND; - return map - .findRecipeWithResult(lastRecipe, false, false, availableVoltage, inputFluids, specialSlotItem, inputItems); + return map.findRecipeWithResult( + lastRecipe, + false, + false, + amperageOC ? availableVoltage * availableAmperage : availableVoltage, + inputFluids, + specialSlotItem, + inputItems); } /** @@ -364,8 +380,8 @@ public class ProcessingLogic { .setMaxParallel(maxParallel) .setEUtModifier(euModifier) .enableBatchMode(batchSize) - .enableConsumption() - .enableOutputCalculation(); + .setConsumption(true) + .setOutputCalculation(true); } /** @@ -377,18 +393,31 @@ public class ProcessingLogic { } /** - * Override to tweak overclock logic if needed. + * Use {@link #createOverclockCalculator(GT_Recipe)} */ @Nonnull + @Deprecated protected GT_OverclockCalculator createOverclockCalculator(@Nonnull GT_Recipe recipe, - @Nonnull GT_ParallelHelper helper) { + @Nullable GT_ParallelHelper helper) { + return createOverclockCalculator(recipe); + } + + /** + * Override to tweak overclock logic if needed. + */ + @Nonnull + protected GT_OverclockCalculator createOverclockCalculator(@Nonnull GT_Recipe recipe) { return new GT_OverclockCalculator().setRecipeEUt(recipe.mEUt) - .setParallel((int) Math.floor(helper.getCurrentParallel() / helper.getDurationMultiplierDouble())) - .setDuration(recipe.mDuration) + .setRecipeAmperage( + recipeMapSupplier != null && recipeMapSupplier.get() != null + ? Math.max(recipeMapSupplier.get().mAmperage, 1) + : 1) .setAmperage(availableAmperage) .setEUt(availableVoltage) + .setDuration(recipe.mDuration) .setSpeedBoost(speedBoost) .setEUtDiscount(euModifier) + .setAmperageOC(amperageOC) .setDurationDecreasePerOC(overClockTimeReduction) .setEUtIncreasePerOC(overClockPowerIncrease); } -- cgit