diff --git a/src/functionalTest/java/gregtech/test/GTParallelHelperTest.java b/src/functionalTest/java/gregtech/test/GTParallelHelperTest.java index a0242627f9d..f2821de6177 100644 --- a/src/functionalTest/java/gregtech/test/GTParallelHelperTest.java +++ b/src/functionalTest/java/gregtech/test/GTParallelHelperTest.java @@ -13,7 +13,7 @@ import gregtech.api.enums.TierEU; import gregtech.api.util.GTRecipe; import gregtech.api.util.GTUtility; -import gregtech.api.util.ParallelHelper; +import gregtech.api.util.ProcessingHelper; import gregtech.test.mock.MockIVoidableMachine; public class GTParallelHelperTest { @@ -46,10 +46,10 @@ static void setup() { @Test void OutputsIntegerOverflow() { - ParallelHelper helper = new ParallelHelper().setRecipe(rubberRecipe) + ProcessingHelper helper = new ProcessingHelper().setRecipe(rubberRecipe) .setMachine(machine, false, false) .setItemInputs(inputItems) - .setMaxParallel(4_000_000) + .setMaxParallels(4_000_000) .setAvailableEUt(4_000_000) .setOutputCalculation(true) .setConsumption(false); @@ -64,22 +64,23 @@ void OutputsIntegerOverflow() { @Test void parallelIntegerOverflow() { // Without batch mode - ParallelHelper helperWithoutBatchMode = new ParallelHelper().setRecipe(rubberRecipe) + ProcessingHelper helperWithoutBatchMode = new ProcessingHelper().setRecipe(rubberRecipe) .setMachine(machine, false, false) .setItemInputs(inputItems) - .setMaxParallel(Integer.MAX_VALUE) + .setMaxParallels(Integer.MAX_VALUE) .setAvailableEUt(TierEU.MAX * 16) .setConsumption(false) .build(); assertEquals(Integer.MAX_VALUE, helperWithoutBatchMode.getCurrentParallel()); // With batch mode - ParallelHelper helperWithBatchMode = new ParallelHelper().setRecipe(rubberRecipe) + ProcessingHelper helperWithBatchMode = new ProcessingHelper().setRecipe(rubberRecipe) .setMachine(machine, false, false) .setItemInputs(inputItems) - .setMaxParallel(Integer.MAX_VALUE / 50) + .setMaxParallels(Integer.MAX_VALUE / 50) .setAvailableEUt(TierEU.MAX * 16) - .enableBatchMode(128) + .setBatchMode(true) + .setBatchModifier(128) .setConsumption(false) .build(); assertEquals(Integer.MAX_VALUE, helperWithBatchMode.getCurrentParallel()); @@ -87,10 +88,10 @@ void parallelIntegerOverflow() { @Test void chanceMultiplier() { - ParallelHelper helper = new ParallelHelper().setRecipe(rubberRecipe) + ProcessingHelper helper = new ProcessingHelper().setRecipe(rubberRecipe) .setMachine(machine, false, false) .setItemInputs(inputItems) - .setMaxParallel(10) + .setMaxParallels(10) .setAvailableEUt(10) .setConsumption(false) .setOutputCalculation(true) @@ -106,10 +107,10 @@ void chanceMultiplier() { @Test void outputMultiplier() { - ParallelHelper helper = new ParallelHelper().setRecipe(rubberRecipe) + ProcessingHelper helper = new ProcessingHelper().setRecipe(rubberRecipe) .setMachine(machine, false, false) .setItemInputs(inputItems) - .setMaxParallel(1) + .setMaxParallels(1) .setAvailableEUt(1) .setConsumption(false) .setOutputCalculation(true) diff --git a/src/main/java/bartworks/common/tileentities/multis/MTEBioVat.java b/src/main/java/bartworks/common/tileentities/multis/MTEBioVat.java index 0b6cbc468eb..878f5c12d21 100644 --- a/src/main/java/bartworks/common/tileentities/multis/MTEBioVat.java +++ b/src/main/java/bartworks/common/tileentities/multis/MTEBioVat.java @@ -85,7 +85,7 @@ import gregtech.api.util.GTRecipeConstants; import gregtech.api.util.GTUtility; import gregtech.api.util.MultiblockTooltipBuilder; -import gregtech.api.util.ParallelHelper; +import gregtech.api.util.ProcessingHelper; import gregtech.api.util.recipe.Sievert; public class MTEBioVat extends MTEEnhancedMultiBlockBase implements ISurvivalConstructable { @@ -264,10 +264,10 @@ protected CheckRecipeResult validateRecipe(@NotNull GTRecipe recipe) { @NotNull @Override - protected ParallelHelper createParallelHelper(@NotNull GTRecipe recipe) { - return super.createParallelHelper(recipeWithMultiplier(recipe, inputFluids)); + protected ProcessingHelper createProcessingHelper(@NotNull GTRecipe recipe) { + return super.createProcessingHelper(recipeWithMultiplier(recipe, inputFluids)); } - }; + }.setOverclock(true); } protected GTRecipe recipeWithMultiplier(GTRecipe recipe, FluidStack[] fluidInputs) { diff --git a/src/main/java/bartworks/common/tileentities/multis/MTECircuitAssemblyLine.java b/src/main/java/bartworks/common/tileentities/multis/MTECircuitAssemblyLine.java index 744e0c0f68c..5c5323d8618 100644 --- a/src/main/java/bartworks/common/tileentities/multis/MTECircuitAssemblyLine.java +++ b/src/main/java/bartworks/common/tileentities/multis/MTECircuitAssemblyLine.java @@ -312,7 +312,6 @@ public Collection> getAvailableRecipeMaps() { @Override protected ProcessingLogic createProcessingLogic() { return new ProcessingLogic() { - @Override @Nonnull protected CheckRecipeResult validateRecipe(@Nonnull GTRecipe recipe) { @@ -323,7 +322,8 @@ protected CheckRecipeResult validateRecipe(@Nonnull GTRecipe recipe) { } return CheckRecipeResultRegistry.SUCCESSFUL; } - }.enablePerfectOverclock(); + }.setOverclock(true) + .setPerfectOverclock(); } @NotNull diff --git a/src/main/java/bartworks/common/tileentities/multis/MTEElectricImplosionCompressor.java b/src/main/java/bartworks/common/tileentities/multis/MTEElectricImplosionCompressor.java index b8a5ace3cd7..807b5f5460b 100644 --- a/src/main/java/bartworks/common/tileentities/multis/MTEElectricImplosionCompressor.java +++ b/src/main/java/bartworks/common/tileentities/multis/MTEElectricImplosionCompressor.java @@ -331,7 +331,8 @@ protected OverclockCalculator createOverclockCalculator(@NotNull GTRecipe recipe .setEUt(MTEElectricImplosionCompressor.this.getMaxInputEu()) .setAmperage(1); } - }.setMaxParallelSupplier(() -> (int) Math.pow(4, Math.max(this.mBlockTier - 1, 0))); + }.setOverclock(true) + .setMaxParallelSupplier(() -> (int) Math.pow(4, Math.max(this.mBlockTier - 1, 0))); } private void updateChunkCoordinates() { diff --git a/src/main/java/bartworks/common/tileentities/multis/mega/MTEMegaBlastFurnace.java b/src/main/java/bartworks/common/tileentities/multis/mega/MTEMegaBlastFurnace.java index d1746731f57..f33333b9b3a 100644 --- a/src/main/java/bartworks/common/tileentities/multis/mega/MTEMegaBlastFurnace.java +++ b/src/main/java/bartworks/common/tileentities/multis/mega/MTEMegaBlastFurnace.java @@ -63,7 +63,6 @@ import gregtech.api.util.GTRecipe; import gregtech.api.util.GTUtility; import gregtech.api.util.MultiblockTooltipBuilder; -import gregtech.api.util.OverclockCalculator; import gregtech.common.pollution.PollutionConfig; public class MTEMegaBlastFurnace extends MegaMultiBlockBase implements ISurvivalConstructable { @@ -276,22 +275,18 @@ protected String[] getExtendedInfoData() { protected ProcessingLogic createProcessingLogic() { return new ProcessingLogic() { - @Nonnull - @Override - protected OverclockCalculator createOverclockCalculator(@Nonnull GTRecipe recipe) { - return super.createOverclockCalculator(recipe).setRecipeHeat(recipe.mSpecialValue) - .setMachineHeat(MTEMegaBlastFurnace.this.mHeatingCapacity) - .setHeatOC(true) - .setHeatDiscount(true); - } - @Override protected @Nonnull CheckRecipeResult validateRecipe(@Nonnull GTRecipe recipe) { return recipe.mSpecialValue <= MTEMegaBlastFurnace.this.mHeatingCapacity ? CheckRecipeResultRegistry.SUCCESSFUL : CheckRecipeResultRegistry.insufficientHeat(recipe.mSpecialValue); } - }.setMaxParallel(Configuration.Multiblocks.megaMachinesMax); + }.setOverclock(true) + .setHeatOC(true) + .setHeatDiscount(true) + .setHeatDiscountMultiplier(0.95) + .setMachineHeat(MTEMegaBlastFurnace.this.mHeatingCapacity) + .setMaxParallel(Configuration.Multiblocks.megaMachinesMax); } @Override diff --git a/src/main/java/bartworks/common/tileentities/multis/mega/MTEMegaChemicalReactor.java b/src/main/java/bartworks/common/tileentities/multis/mega/MTEMegaChemicalReactor.java index 9cc18de9b31..f68dc7e44cb 100644 --- a/src/main/java/bartworks/common/tileentities/multis/mega/MTEMegaChemicalReactor.java +++ b/src/main/java/bartworks/common/tileentities/multis/mega/MTEMegaChemicalReactor.java @@ -174,7 +174,9 @@ public boolean onWireCutterRightClick(ForgeDirection side, ForgeDirection wrench @Override protected ProcessingLogic createProcessingLogic() { - return new ProcessingLogic().enablePerfectOverclock() + return new ProcessingLogic() + .setOverclock(true) + .setPerfectOverclock() .setMaxParallel(Configuration.Multiblocks.megaMachinesMax); } diff --git a/src/main/java/bartworks/common/tileentities/multis/mega/MTEMegaDistillTower.java b/src/main/java/bartworks/common/tileentities/multis/mega/MTEMegaDistillTower.java index 62697dcb8fd..c4a642eee82 100644 --- a/src/main/java/bartworks/common/tileentities/multis/mega/MTEMegaDistillTower.java +++ b/src/main/java/bartworks/common/tileentities/multis/mega/MTEMegaDistillTower.java @@ -385,7 +385,9 @@ public boolean onWireCutterRightClick(ForgeDirection side, ForgeDirection wrench @Override protected ProcessingLogic createProcessingLogic() { - return new ProcessingLogic().setMaxParallel(Configuration.Multiblocks.megaMachinesMax); + return new ProcessingLogic() + .setOverclock(true) + .setMaxParallel(Configuration.Multiblocks.megaMachinesMax); } @Override diff --git a/src/main/java/bartworks/common/tileentities/multis/mega/MTEMegaOilCracker.java b/src/main/java/bartworks/common/tileentities/multis/mega/MTEMegaOilCracker.java index 51d8d5ada3b..59fac3ed7f5 100644 --- a/src/main/java/bartworks/common/tileentities/multis/mega/MTEMegaOilCracker.java +++ b/src/main/java/bartworks/common/tileentities/multis/mega/MTEMegaOilCracker.java @@ -31,8 +31,6 @@ import java.util.List; import java.util.Map; -import javax.annotation.Nonnull; - import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; @@ -62,7 +60,6 @@ import gregtech.api.metatileentity.implementations.MTEHatchOutput; import gregtech.api.recipe.RecipeMap; import gregtech.api.recipe.RecipeMaps; -import gregtech.api.recipe.check.CheckRecipeResult; import gregtech.api.recipe.maps.OilCrackerBackend; import gregtech.api.render.TextureFactory; import gregtech.api.util.GTUtility; @@ -223,15 +220,10 @@ public RecipeMap getRecipeMap() { @Override protected ProcessingLogic createProcessingLogic() { - return new ProcessingLogic() { - - @Override - @Nonnull - public CheckRecipeResult process() { - this.setEuModifier(1.0F - Math.min(0.1F * (MTEMegaOilCracker.this.heatLevel.getTier() + 1), 0.5F)); - return super.process(); - } - }.setMaxParallel(Configuration.Multiblocks.megaMachinesMax); + return new ProcessingLogic() + .setOverclock(true) + .setEUtModifier(1 - Math.min(0.1 * (this.heatLevel.getTier() + 1), 0.5)) + .setMaxParallel(Configuration.Multiblocks.megaMachinesMax); } public HeatingCoilLevel getCoilLevel() { diff --git a/src/main/java/bartworks/common/tileentities/multis/mega/MTEMegaVacuumFreezer.java b/src/main/java/bartworks/common/tileentities/multis/mega/MTEMegaVacuumFreezer.java index c9138789363..ab2c00d638e 100644 --- a/src/main/java/bartworks/common/tileentities/multis/mega/MTEMegaVacuumFreezer.java +++ b/src/main/java/bartworks/common/tileentities/multis/mega/MTEMegaVacuumFreezer.java @@ -29,8 +29,6 @@ import java.util.Arrays; import java.util.Optional; -import javax.annotation.Nonnull; - import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; @@ -60,10 +58,8 @@ import gregtech.api.recipe.RecipeMap; import gregtech.api.recipe.RecipeMaps; import gregtech.api.render.TextureFactory; -import gregtech.api.util.GTRecipe; import gregtech.api.util.GTUtility; import gregtech.api.util.MultiblockTooltipBuilder; -import gregtech.api.util.OverclockCalculator; import gregtech.api.util.shutdown.ShutDownReasonRegistry; import gregtech.common.blocks.BlockCasingsAbstract; @@ -409,24 +405,14 @@ public SubspaceCoolingFluid findSubspaceCoolingFluid() { @Override protected ProcessingLogic createProcessingLogic() { - return new ProcessingLogic() { - - @Nonnull - @Override - protected OverclockCalculator createOverclockCalculator(@Nonnull GTRecipe recipe) { - // Check if the freezer is T2 - if (mTier == 1) return super.createOverclockCalculator(recipe); - - // First try to detect the current fluid used for subspace cooling. - currentCoolingFluid = findSubspaceCoolingFluid(); - - return super.createOverclockCalculator(recipe) - .setMachineHeat(currentCoolingFluid == null ? 0 : currentCoolingFluid.perfectOverclocks * 1800) - .setRecipeHeat(0) - .setHeatOC(true) - .setHeatDiscount(false); - } - }.setMaxParallel(Configuration.Multiblocks.megaMachinesMax); + currentCoolingFluid = findSubspaceCoolingFluid(); + + return new ProcessingLogic() + .setOverclock(true) + .setHeatOC(true) + .setHeatDiscount(false) + .setMachineHeat(currentCoolingFluid == null ? 0 : currentCoolingFluid.perfectOverclocks * 1800) + .setMaxParallel(Configuration.Multiblocks.megaMachinesMax); } @Override diff --git a/src/main/java/goodgenerator/blocks/tileEntity/MTEFuelRefineFactory.java b/src/main/java/goodgenerator/blocks/tileEntity/MTEFuelRefineFactory.java index c7f4d9d9945..d0b55da319e 100644 --- a/src/main/java/goodgenerator/blocks/tileEntity/MTEFuelRefineFactory.java +++ b/src/main/java/goodgenerator/blocks/tileEntity/MTEFuelRefineFactory.java @@ -217,7 +217,7 @@ protected OverclockCalculator createOverclockCalculator(@NotNull GTRecipe recipe int overclockAmount = Tier - recipe.mSpecialValue; return super.createOverclockCalculator(recipe).limitOverclockCount(overclockAmount); } - }.enablePerfectOverclock(); + }.setPerfectOverclock(); } @Override diff --git a/src/main/java/goodgenerator/blocks/tileEntity/MTENeutronActivator.java b/src/main/java/goodgenerator/blocks/tileEntity/MTENeutronActivator.java index d03ad532ac3..39e97a44ee3 100644 --- a/src/main/java/goodgenerator/blocks/tileEntity/MTENeutronActivator.java +++ b/src/main/java/goodgenerator/blocks/tileEntity/MTENeutronActivator.java @@ -53,11 +53,9 @@ import gregtech.api.recipe.RecipeMap; import gregtech.api.recipe.check.CheckRecipeResult; import gregtech.api.render.TextureFactory; -import gregtech.api.util.GTRecipe; import gregtech.api.util.GTUtility; import gregtech.api.util.IGTHatchAdder; import gregtech.api.util.MultiblockTooltipBuilder; -import gregtech.api.util.OverclockCalculator; import tectech.thing.metaTileEntity.multi.base.INameFunction; import tectech.thing.metaTileEntity.multi.base.IStatusFunction; import tectech.thing.metaTileEntity.multi.base.LedStatus; @@ -111,14 +109,6 @@ public MTENeutronActivator(int id, String name, String nameRegional) { protected ProcessingLogic createProcessingLogic() { return new ProcessingLogic() { - @NotNull - @Override - protected OverclockCalculator createOverclockCalculator(@NotNull GTRecipe recipe) { - return OverclockCalculator.ofNoOverclock(recipe) - .setDuration((int) Math.ceil(recipe.mDuration * Math.pow(0.9f, height - 4))) - .setDurationUnderOneTickSupplier(() -> recipe.mDuration * Math.pow(0.9f, height - 4)); - } - @NotNull @Override public CheckRecipeResult process() { @@ -132,10 +122,10 @@ public CheckRecipeResult process() { overwriteOutputItems(ItemRefer.Radioactive_Waste.get(4)); } // NA does not consume power, its hatches do. Set it to 0 to be sure - calculatedEut = 0; + calculatedEUt = 0; return result; } - }; + }.setDurationSupplier((recipe) -> recipe.mDuration * Math.pow(0.9f, this.height - 4)); } @Override diff --git a/src/main/java/goodgenerator/blocks/tileEntity/base/MTELargeFusionComputer.java b/src/main/java/goodgenerator/blocks/tileEntity/base/MTELargeFusionComputer.java index 5c1a49e58f0..f120ce7f98d 100644 --- a/src/main/java/goodgenerator/blocks/tileEntity/base/MTELargeFusionComputer.java +++ b/src/main/java/goodgenerator/blocks/tileEntity/base/MTELargeFusionComputer.java @@ -62,7 +62,7 @@ import gregtech.api.util.GTUtility; import gregtech.api.util.HatchElementBuilder; import gregtech.api.util.OverclockCalculator; -import gregtech.api.util.ParallelHelper; +import gregtech.api.util.ProcessingHelper; import gregtech.api.util.shutdown.ShutDownReasonRegistry; import gregtech.common.tileentities.machines.IDualInputHatch; import gregtech.common.tileentities.machines.multi.drone.MTEHatchDroneDownLink; @@ -422,9 +422,9 @@ protected ProcessingLogic createProcessingLogic() { @NotNull @Override - protected ParallelHelper createParallelHelper(@NotNull GTRecipe recipe) { + protected ProcessingHelper createProcessingHelper(@NotNull GTRecipe recipe) { // When the fusion first loads and is still processing, it does the recipe check without consuming. - return super.createParallelHelper(recipe).setConsumption(!mRunningOnLoad); + return super.createProcessingHelper(recipe).setConsumption(!mRunningOnLoad); } @NotNull diff --git a/src/main/java/gregtech/api/logic/AbstractProcessingLogic.java b/src/main/java/gregtech/api/logic/AbstractProcessingLogic.java new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/main/java/gregtech/api/logic/MuTEProcessingLogic.java b/src/main/java/gregtech/api/logic/MuTEProcessingLogic.java new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/main/java/gregtech/api/logic/ProcessingLogic.java b/src/main/java/gregtech/api/logic/ProcessingLogic.java index 9e311043f6d..a68b4689f65 100644 --- a/src/main/java/gregtech/api/logic/ProcessingLogic.java +++ b/src/main/java/gregtech/api/logic/ProcessingLogic.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -22,8 +23,8 @@ import gregtech.api.recipe.check.CheckRecipeResultRegistry; import gregtech.api.recipe.check.SingleRecipeCheck; import gregtech.api.util.GTRecipe; -import gregtech.api.util.OverclockCalculator; -import gregtech.api.util.ParallelHelper; +import gregtech.api.util.ProcessingHelper; +import gregtech.api.util.ProcessingResult; import gregtech.common.tileentities.machines.IDualInputInventory; /** @@ -31,7 +32,6 @@ */ @SuppressWarnings({ "unused", "UnusedReturnValue" }) public class ProcessingLogic { - // Traits protected IVoidable machine; protected IRecipeLockable recipeLockableMachine; @@ -44,20 +44,32 @@ public class ProcessingLogic { protected Supplier maxParallelSupplier; protected int batchSize = 1; protected Supplier> recipeMapSupplier; - protected double euModifier = 1.0; - protected double speedBoost = 1.0; + protected double eutModifier = 1.0; protected long availableVoltage; protected long availableAmperage; protected boolean protectItems; protected boolean protectFluids; - protected double overClockTimeReduction = 2.0; - protected double overClockPowerIncrease = 4.0; protected boolean amperageOC = true; + // Speed related parameters + protected double speedBoost = 1.0; + protected Function durationSupplier; + + // Overclock related parameters + protected boolean overclock; + protected Function ocEUtModifierSupplier; + protected Function ocDurationModifierSupplier; + + // Heat related parameters + protected boolean heatOC; + protected boolean heatDiscount; + protected double heatDiscountMultiplier; + protected int machineHeat; + // Calculated results protected ItemStack[] outputItems; protected FluidStack[] outputFluids; - protected long calculatedEut; + protected long calculatedEUt; protected int duration; protected int calculatedParallels = 0; @@ -173,8 +185,8 @@ public ProcessingLogic setRecipeMapSupplier(Supplier> supplier) { return this; } - public ProcessingLogic setEuModifier(double modifier) { - this.euModifier = modifier; + public ProcessingLogic setEUtModifier(double eutModifier) { + this.eutModifier = eutModifier; return this; } @@ -183,6 +195,33 @@ public ProcessingLogic setSpeedBonus(double speedModifier) { return this; } + public ProcessingLogic setDurationSupplier(Function durationSupplier) { + this.durationSupplier = durationSupplier; + return this; + } + + public ProcessingLogic setOverclock(boolean overclock) { + this.overclock = overclock; + return this; + } + + public ProcessingLogic setOCEUtModifierSupplier(Function ocEUtModifierSupplier) { + this.ocEUtModifierSupplier = ocEUtModifierSupplier; + return this; + } + + public ProcessingLogic setOCDurationModifierSupplier(Function ocDurationModifierSupplier) { + this.ocDurationModifierSupplier = ocDurationModifierSupplier; + return this; + } + + /** + * Sets overclock ratio to 4/4. + */ + public ProcessingLogic setPerfectOverclock() { + return this.setOCDurationModifierSupplier((overclocks) -> 4.0); + } + /** * Sets voltage of the machine. It doesn't need to be actual voltage (excluding amperage) of the machine; * For example, most of the multiblock machines set maximum possible input power (including amperage) as voltage @@ -208,17 +247,30 @@ public ProcessingLogic setVoidProtection(boolean protectItems, boolean protectFl return this; } - public ProcessingLogic setOverclock(double timeReduction, double powerIncrease) { - this.overClockTimeReduction = timeReduction; - this.overClockPowerIncrease = powerIncrease; + // public ProcessingLogic setOverclock(double timeReduction, double powerIncrease) { + // this.overClockTimeReduction = timeReduction; + // this.overClockPowerIncrease = powerIncrease; + // return this; + // } + + public ProcessingLogic setHeatOC(boolean heatOC) { + this.heatOC = heatOC; return this; } - /** - * Sets overclock ratio to 4/4. - */ - public ProcessingLogic enablePerfectOverclock() { - return this.setOverclock(4.0, 4.0); + public ProcessingLogic setHeatDiscount(boolean heatDiscount) { + this.heatDiscount = heatDiscount; + return this; + } + + public ProcessingLogic setHeatDiscountMultiplier(double heatDiscountMultiplier) { + this.heatDiscountMultiplier = heatDiscountMultiplier; + return this; + } + + public ProcessingLogic setMachineHeat(int machineHeat) { + this.machineHeat = machineHeat; + return this; } /** @@ -253,7 +305,7 @@ public ProcessingLogic overwriteOutputFluids(FluidStack... fluidOutputs) { * Overwrites calculated EU/t. */ public ProcessingLogic overwriteCalculatedEut(long calculatedEut) { - this.calculatedEut = calculatedEut; + this.calculatedEUt = calculatedEut; return this; } @@ -276,7 +328,7 @@ public ProcessingLogic clear() { this.specialSlotItem = null; this.outputItems = null; this.outputFluids = null; - this.calculatedEut = 0; + this.calculatedEUt = 0; this.duration = 0; this.calculatedParallels = 0; this.craftingPattern = null; @@ -375,22 +427,18 @@ public CheckRecipeResult process() { */ @Nonnull private CalculationResult validateAndCalculateRecipe(@Nonnull GTRecipe recipe) { - CheckRecipeResult result = validateRecipe(recipe); - if (!result.wasSuccessful()) { - return CalculationResult.ofFailure(result); + CheckRecipeResult validationResult = validateRecipe(recipe); + if (!validationResult.wasSuccessful()) { + return CalculationResult.ofFailure(validationResult); } - ParallelHelper helper = createParallelHelper(recipe); - OverclockCalculator calculator = createOverclockCalculator(recipe); - helper.setCalculator(calculator); - helper.build(); + ProcessingResult processingResult = createProcessingHelper(recipe).process(); - if (!helper.getResult() - .wasSuccessful()) { - return CalculationResult.ofFailure(helper.getResult()); + if (!processingResult.wasSuccessful()) { + return CalculationResult.ofFailure(processingResult.getResult()); } - return CalculationResult.ofSuccess(applyRecipe(recipe, helper, calculator, result)); + return CalculationResult.ofSuccess(applyRecipe(recipe, processingResult)); } /** @@ -398,8 +446,7 @@ private CalculationResult validateAndCalculateRecipe(@Nonnull GTRecipe recipe) { * At this point, inputs have been already consumed. */ @Nonnull - private CheckRecipeResult applyRecipe(@Nonnull GTRecipe recipe, @Nonnull ParallelHelper helper, - @Nonnull OverclockCalculator calculator, @Nonnull CheckRecipeResult result) { + private CheckRecipeResult applyRecipe(@Nonnull GTRecipe recipe, @Nonnull ProcessingResult result) { if (recipe.mCanBeBuffered) { lastRecipe = recipe; } else { @@ -414,7 +461,7 @@ private CheckRecipeResult applyRecipe(@Nonnull GTRecipe recipe, @Nonnull Paralle return CheckRecipeResultRegistry.DURATION_OVERFLOW; } - calculatedEut = calculator.getConsumption(); + calculatedEUt = calculator.getConsumption(); double finalDuration = calculateDuration(recipe, helper, calculator); if (finalDuration >= Integer.MAX_VALUE) { @@ -473,36 +520,29 @@ protected CheckRecipeResult validateRecipe(@Nonnull GTRecipe recipe) { * Override to tweak parallel logic if needed. */ @Nonnull - protected ParallelHelper createParallelHelper(@Nonnull GTRecipe recipe) { - return new ParallelHelper().setRecipe(recipe) - .setItemInputs(inputItems) - .setFluidInputs(inputFluids) - .setAvailableEUt(availableVoltage * availableAmperage) - .setMachine(machine, protectItems, protectFluids) - .setRecipeLocked(recipeLockableMachine, isRecipeLocked) - .setMaxParallel(maxParallel) - .setEUtModifier(euModifier) - .enableBatchMode(batchSize) + protected ProcessingHelper createProcessingHelper(@Nonnull GTRecipe recipe) { + return new ProcessingHelper().setRecipe(recipe) + .setItemInputs(this.inputItems) + .setFluidInputs(this.inputFluids) + .setAvailableEUt(this.availableVoltage * this.availableAmperage) + .setMachine(this.machine, this.protectItems, this.protectFluids) + .setRecipeLocked(this.recipeLockableMachine, this.isRecipeLocked) + .setMaxParallels(this.maxParallel) + .setEUtModifier(this.eutModifier) + .setDurationSupplier(this.durationSupplier) + .setOverclock(this.overclock) + .setOCEUtModifierSupplier(this.ocEUtModifierSupplier) + .setOCDurationModifierSupplier(this.ocDurationModifierSupplier) + .setBatchMode(this.batchSize > 1) + .setBatchModifier(this.batchSize) + .setHeatOC(this.heatOC) + .setHeatDiscount(this.heatDiscount) + .setHeatDiscountMultiplier(this.heatDiscountMultiplier) + .setMachineHeat(this.machineHeat) .setConsumption(true) .setOutputCalculation(true); } - /** - * Override to tweak overclock logic if needed. - */ - @Nonnull - protected OverclockCalculator createOverclockCalculator(@Nonnull GTRecipe recipe) { - return new OverclockCalculator().setRecipeEUt(recipe.mEUt) - .setAmperage(availableAmperage) - .setEUt(availableVoltage) - .setDuration(recipe.mDuration) - .setSpeedBoost(speedBoost) - .setEUtDiscount(euModifier) - .setAmperageOC(amperageOC) - .setDurationDecreasePerOC(overClockTimeReduction) - .setEUtIncreasePerOC(overClockPowerIncrease); - } - /** * Override to perform additional logic when recipe starts. *

@@ -532,8 +572,8 @@ public int getDuration() { return duration; } - public long getCalculatedEut() { - return calculatedEut; + public long getCalculatedEUt() { + return calculatedEUt; } public int getCurrentParallels() { diff --git a/src/main/java/gregtech/api/metatileentity/implementations/MTEExtendedPowerMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/MTEExtendedPowerMultiBlockBase.java index 9ff7f34fe3a..9e1243ec06b 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/MTEExtendedPowerMultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/MTEExtendedPowerMultiBlockBase.java @@ -129,7 +129,7 @@ protected CheckRecipeResult postCheckRecipe(@Nonnull CheckRecipeResult result, @Override protected void setEnergyUsage(ProcessingLogic processingLogic) { - lEUt = processingLogic.getCalculatedEut(); + lEUt = processingLogic.getCalculatedEUt(); if (lEUt > 0) { lEUt = (-lEUt); } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java index 98b41a62f21..8ebdaa942eb 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java @@ -93,7 +93,7 @@ import gregtech.api.util.GTWaila; import gregtech.api.util.OutputHatchWrapper; import gregtech.api.util.OverclockCalculator; -import gregtech.api.util.ParallelHelper; +import gregtech.api.util.ProcessingHelper; import gregtech.api.util.VoidProtectionHelper; import gregtech.api.util.shutdown.ShutDownReason; import gregtech.api.util.shutdown.ShutDownReasonRegistry; @@ -992,7 +992,7 @@ protected CheckRecipeResult checkRecipeForCustomHatches(CheckRecipeResult lastRe @Nonnull protected CheckRecipeResult postCheckRecipe(@Nonnull CheckRecipeResult result, @Nonnull ProcessingLogic processingLogic) { - if (result.wasSuccessful() && processingLogic.getCalculatedEut() > Integer.MAX_VALUE) { + if (result.wasSuccessful() && processingLogic.getCalculatedEUt() > Integer.MAX_VALUE) { return CheckRecipeResultRegistry.POWER_OVERFLOW; } return result; @@ -1004,7 +1004,7 @@ protected CheckRecipeResult postCheckRecipe(@Nonnull CheckRecipeResult result, */ protected void setEnergyUsage(ProcessingLogic processingLogic) { // getCalculatedEut() is guaranteed to not exceed int by postCheckRecipe() - mEUt = (int) processingLogic.getCalculatedEut(); + mEUt = (int) processingLogic.getCalculatedEUt(); if (mEUt > 0) { mEUt = (-mEUt); } @@ -2198,7 +2198,7 @@ public boolean checkExoticAndNormalEnergyHatches() { * If void protection is enabled, it also checks for {@link #protectsExcessItem()} and * {@link #protectsExcessFluid()}, so you don't need to call them along with this method. *

- * If you're using {@link ParallelHelper}, it will handle void protection and return 0 parallel + * If you're using {@link ProcessingHelper}, it will handle void protection and return 0 parallel * if all the output cannot be dumped into buses / hatches. In that case you won't use this method. */ protected boolean canOutputAll(@Nonnull GTRecipe recipe) { diff --git a/src/main/java/gregtech/api/util/ParallelHelper.java b/src/main/java/gregtech/api/util/ParallelHelper.java deleted file mode 100644 index 99e7cac569f..00000000000 --- a/src/main/java/gregtech/api/util/ParallelHelper.java +++ /dev/null @@ -1,656 +0,0 @@ -package gregtech.api.util; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Objects; -import java.util.Random; -import java.util.function.Function; - -import javax.annotation.Nonnull; - -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; - -import gregtech.api.interfaces.tileentity.IRecipeLockable; -import gregtech.api.interfaces.tileentity.IVoidable; -import gregtech.api.objects.XSTR; -import gregtech.api.recipe.RecipeMap; -import gregtech.api.recipe.check.CheckRecipeResult; -import gregtech.api.recipe.check.CheckRecipeResultRegistry; -import gregtech.api.recipe.check.SingleRecipeCheck; - -@SuppressWarnings({ "unused", "UnusedReturnValue" }) -public class ParallelHelper { - - private static final double MAX_BATCH_MODE_TICK_TIME = 128; - /** - * Machine used for calculation - */ - private IVoidable machine; - /** - * Machine used for single recipe locking calculation - */ - private IRecipeLockable singleRecipeMachine; - /** - * Is locked to a single recipe? - */ - private boolean isRecipeLocked; - /** - * Recipe used when trying to calculate parallels - */ - private GTRecipe recipe; - /** - * EUt available to the multiblock (This should be the total eut available) - */ - private long availableEUt; - /** - * The current parallel possible for the multiblock - */ - private int currentParallel = 0; - /** - * The maximum possible parallel possible for the multiblock - */ - private int maxParallel = 1; - /** - * The Batch Modifier applied when batch mode is enabled. 1 does nothing. 2 doubles max possible - * parallel, but also duration - */ - private int batchModifier = 1; - /** - * The inputs of the multiblock for the current recipe check - */ - private ItemStack[] itemInputs; - /** - * The outputs of the recipe with the applied parallel - */ - private ItemStack[] itemOutputs; - /** - * The inputs of the multiblock for the current recipe check - */ - private FluidStack[] fluidInputs; - /** - * The outputs of the recipe with the applied parallel - */ - private FluidStack[] fluidOutputs; - /** - * Does the multi have void protection enabled for items - */ - private boolean protectExcessItem; - /** - * Does the multi have void protection enabled for fluids - */ - private boolean protectExcessFluid; - /** - * Should the Parallel Helper automatically consume for the multi - */ - private boolean consume; - /** - * Is batch mode turned on? - */ - private boolean batchMode; - /** - * Should the Parallel Helper automatically calculate the outputs of the recipe with current parallel? - */ - private boolean calculateOutputs; - /** - * Has the Parallel Helper been built? - */ - private boolean built; - /** - * What is the duration multiplier with batch mode enabled - */ - private double durationMultiplier; - /** - * Modifier which is applied on the recipe eut. Useful for GT++ machines - */ - private double eutModifier = 1; - /** - * Multiplier that is applied on the output chances - */ - private double chanceMultiplier = 1; - /** - * Multiplier by which the output will be multiplied - */ - private int outputMultiplier = 1; - /** - * Method for calculating max parallel from given inputs. - */ - private MaxParallelCalculator maxParallelCalculator = GTRecipe::maxParallelCalculatedByInputs; - /** - * Method for consuming inputs after determining how many parallels it can execute. - */ - private InputConsumer inputConsumer = GTRecipe::consumeInput; - - /** - * Calculator to use for overclocking - */ - private OverclockCalculator calculator; - @Nonnull - private CheckRecipeResult result = CheckRecipeResultRegistry.NONE; - - private Function customItemOutputCalculation; - - private Function customFluidOutputCalculation; - - public ParallelHelper() {} - - /** - * Sets machine, with current configuration for void protection mode. - */ - @Nonnull - public ParallelHelper setMachine(IVoidable machine) { - return setMachine(machine, machine.protectsExcessItem(), machine.protectsExcessFluid()); - } - - /** - * Sets machine, with void protection mode forcibly. - */ - @Nonnull - public ParallelHelper setMachine(IVoidable machine, boolean protectExcessItem, boolean protectExcessFluid) { - this.protectExcessItem = protectExcessItem; - this.protectExcessFluid = protectExcessFluid; - this.machine = machine; - return this; - } - - /** - * Sets the recipe, which will be used for the parallel calculation - */ - @Nonnull - public ParallelHelper setRecipe(@Nonnull GTRecipe aRecipe) { - recipe = Objects.requireNonNull(aRecipe); - return this; - } - - @Nonnull - public ParallelHelper setRecipeLocked(IRecipeLockable singleRecipeMachine, boolean isRecipeLocked) { - this.singleRecipeMachine = singleRecipeMachine; - this.isRecipeLocked = isRecipeLocked; - return this; - } - - /** - * Sets the items available for the recipe check - */ - @Nonnull - public ParallelHelper setItemInputs(ItemStack... aItemInputs) { - this.itemInputs = aItemInputs; - return this; - } - - /** - * Sets the fluid inputs available for the recipe check - */ - @Nonnull - public ParallelHelper setFluidInputs(FluidStack... aFluidInputs) { - this.fluidInputs = aFluidInputs; - return this; - } - - /** - * Sets the available eut when trying for more parallels - */ - @Nonnull - public ParallelHelper setAvailableEUt(long aAvailableEUt) { - this.availableEUt = aAvailableEUt; - return this; - } - - /** - * Sets the modifier for recipe eut. 1 does nothing 0.9 is 10% less. 1.1 is 10% more - */ - @Nonnull - public ParallelHelper setEUtModifier(double aEUtModifier) { - this.eutModifier = aEUtModifier; - return this; - } - - /** - * Sets the multiplier that is applied on output chances. 1 does nothing. 0.9 is 10% less. 1.1 is 10% more. - * Only useful for item outputs for sure. - */ - @Nonnull - public ParallelHelper setChanceMultiplier(double chanceMultiplier) { - this.chanceMultiplier = chanceMultiplier; - return this; - } - - /** - * Sets the item/fluid output multiplier. 1 does nothing. 2 doubles the item and fluid outputs. - */ - @Nonnull - public ParallelHelper setOutputMultiplier(int outputMultiplier) { - this.outputMultiplier = outputMultiplier; - return this; - } - - @Nonnull - public ParallelHelper setCalculator(OverclockCalculator calculator) { - this.calculator = calculator; - return this; - } - - /** - * Set if we should consume inputs or not when trying for parallels - * - * @param consume Should we consume inputs - */ - @Nonnull - public ParallelHelper setConsumption(boolean consume) { - this.consume = consume; - return this; - } - - /** - * Sets the MaxParallel a multi can handle - */ - @Nonnull - public ParallelHelper setMaxParallel(int maxParallel) { - this.maxParallel = maxParallel; - return this; - } - - /** - * Enables Batch mode. Can do up to an additional processed recipes of mCurrentParallel * mBatchModifier A batch - * modifier of 1 does nothing - */ - @Nonnull - public ParallelHelper enableBatchMode(int batchModifier) { - this.batchMode = batchModifier > 1; - this.batchModifier = batchModifier; - return this; - } - - /** - * Sets if we should calculate outputs with the parallels we found or not - * - * @param calculateOutputs Should we calculate outputs with the helper or not - */ - @Nonnull - public ParallelHelper setOutputCalculation(boolean calculateOutputs) { - this.calculateOutputs = calculateOutputs; - return this; - } - - /** - * Set a custom way to calculate item outputs. You are given the amount of parallels and must return an ItemStack - * array - */ - @Nonnull - public ParallelHelper setCustomItemOutputCalculation(Function custom) { - customItemOutputCalculation = custom; - return this; - } - - /** - * Set a custom way to calculate item outputs. You are given the amount of parallels and must return a FluidStack - * array - */ - @Nonnull - public ParallelHelper setCustomFluidOutputCalculation(Function custom) { - customFluidOutputCalculation = custom; - return this; - } - - /** - * Sets method for calculating max parallel from given inputs. - */ - public ParallelHelper setMaxParallelCalculator(MaxParallelCalculator maxParallelCalculator) { - this.maxParallelCalculator = maxParallelCalculator; - return this; - } - - /** - * Sets method for consuming inputs after determining how many parallels it can execute. - */ - public ParallelHelper setInputConsumer(InputConsumer inputConsumer) { - this.inputConsumer = inputConsumer; - return this; - } - - /** - * Finishes the GT_ParallelHelper. Anything changed after this will not effect anything - */ - @Nonnull - public ParallelHelper build() { - if (built) { - throw new IllegalStateException("Tried to build twice"); - } - if (recipe == null) { - throw new IllegalStateException("Recipe is not set"); - } - built = true; - determineParallel(); - return this; - } - - /** - * @return The current parallels possible by the multiblock - */ - public int getCurrentParallel() { - if (!built) { - throw new IllegalStateException("Tried to get parallels before building"); - } - return currentParallel; - } - - /** - * @return The duration multiplier if batch mode was enabled for the multiblock - */ - public double getDurationMultiplierDouble() { - if (!built) { - throw new IllegalStateException("Tried to get duration multiplier before building"); - } - if (batchMode && durationMultiplier > 0) { - return durationMultiplier; - } - return 1; - } - - /** - * @return The ItemOutputs from the recipe - */ - @Nonnull - public ItemStack[] getItemOutputs() { - if (!built || !calculateOutputs) { - throw new IllegalStateException( - "Tried to get item outputs before building or without enabling calculation of outputs"); - } - return itemOutputs; - } - - /** - * @return The FluidOutputs from the recipe - */ - @Nonnull - public FluidStack[] getFluidOutputs() { - if (!built || !calculateOutputs) { - throw new IllegalStateException( - "Tried to get fluid outputs before building or without enabling calculation of outputs"); - } - return fluidOutputs; - } - - /** - * @return The result of why a recipe could've failed or succeeded - */ - @Nonnull - public CheckRecipeResult getResult() { - if (!built) { - throw new IllegalStateException("Tried to get recipe result before building"); - } - return result; - } - - /** - * Called by build(). Determines the parallels and everything else that needs to be done at build time - */ - protected void determineParallel() { - if (maxParallel <= 0) { - return; - } - if (itemInputs == null) { - itemInputs = new ItemStack[0]; - } - if (fluidInputs == null) { - fluidInputs = new FluidStack[0]; - } - - if (!consume) { - copyInputs(); - } - - if (calculator == null) { - calculator = new OverclockCalculator().setEUt(availableEUt) - .setRecipeEUt(recipe.mEUt) - .setDuration(recipe.mDuration) - .setEUtDiscount(eutModifier); - } - - final int tRecipeEUt = (int) Math.ceil(recipe.mEUt * eutModifier); - if (availableEUt < tRecipeEUt) { - result = CheckRecipeResultRegistry.insufficientPower(tRecipeEUt); - return; - } - - // Save the original max parallel before calculating our overclocking under 1 tick - int originalMaxParallel = maxParallel; - calculator.setParallel(originalMaxParallel); - double tickTimeAfterOC = calculator.calculateDurationUnderOneTick(); - if (tickTimeAfterOC < 1) { - maxParallel = GTUtility.safeInt((long) (maxParallel / tickTimeAfterOC), 0); - } - - int maxParallelBeforeBatchMode = maxParallel; - if (batchMode) { - maxParallel = GTUtility.safeInt((long) maxParallel * batchModifier, 0); - } - - final ItemStack[] truncatedItemOutputs = recipe.mOutputs != null - ? Arrays.copyOfRange(recipe.mOutputs, 0, Math.min(machine.getItemOutputLimit(), recipe.mOutputs.length)) - : new ItemStack[0]; - final FluidStack[] truncatedFluidOutputs = recipe.mFluidOutputs != null ? Arrays - .copyOfRange(recipe.mFluidOutputs, 0, Math.min(machine.getFluidOutputLimit(), recipe.mFluidOutputs.length)) - : new FluidStack[0]; - - SingleRecipeCheck recipeCheck = null; - SingleRecipeCheck.Builder tSingleRecipeCheckBuilder = null; - if (isRecipeLocked && singleRecipeMachine != null) { - recipeCheck = singleRecipeMachine.getSingleRecipeCheck(); - if (recipeCheck == null) { - // Machine is configured to lock to a single recipe, but haven't built the recipe checker yet. - // Build the checker on next successful recipe. - RecipeMap recipeMap = singleRecipeMachine.getRecipeMap(); - if (recipeMap != null) { - tSingleRecipeCheckBuilder = SingleRecipeCheck.builder(recipeMap) - .setBefore(itemInputs, fluidInputs); - } - } - } - - // Let's look at how many parallels we can get with void protection - if (protectExcessItem || protectExcessFluid) { - if (machine == null) { - throw new IllegalStateException("Tried to calculate void protection, but machine is not set"); - } - VoidProtectionHelper voidProtectionHelper = new VoidProtectionHelper(); - voidProtectionHelper.setMachine(machine) - .setItemOutputs(truncatedItemOutputs) - .setFluidOutputs(truncatedFluidOutputs) - .setChangeGetter(recipe::getOutputChance) - .setOutputMultiplier(outputMultiplier) - .setChanceMultiplier(chanceMultiplier) - .setMaxParallel(maxParallel) - .build(); - maxParallel = Math.min(voidProtectionHelper.getMaxParallel(), maxParallel); - if (voidProtectionHelper.isItemFull()) { - result = CheckRecipeResultRegistry.ITEM_OUTPUT_FULL; - return; - } - if (voidProtectionHelper.isFluidFull()) { - result = CheckRecipeResultRegistry.FLUID_OUTPUT_FULL; - return; - } - } - - maxParallelBeforeBatchMode = Math.min(maxParallel, maxParallelBeforeBatchMode); - - // determine normal parallel - int actualMaxParallel = tRecipeEUt > 0 ? (int) Math.min(maxParallelBeforeBatchMode, availableEUt / tRecipeEUt) - : maxParallelBeforeBatchMode; - if (recipeCheck != null) { - currentParallel = recipeCheck.checkRecipeInputs(true, actualMaxParallel, itemInputs, fluidInputs); - } else { - currentParallel = (int) maxParallelCalculator.calculate(recipe, actualMaxParallel, fluidInputs, itemInputs); - if (currentParallel > 0) { - if (tSingleRecipeCheckBuilder != null) { - // If recipe checker is not built yet, build and set it - inputConsumer.consume(recipe, 1, fluidInputs, itemInputs); - SingleRecipeCheck builtCheck = tSingleRecipeCheckBuilder.setAfter(itemInputs, fluidInputs) - .setRecipe(recipe) - .build(); - singleRecipeMachine.setSingleRecipeCheck(builtCheck); - inputConsumer.consume(recipe, currentParallel - 1, fluidInputs, itemInputs); - } else { - inputConsumer.consume(recipe, currentParallel, fluidInputs, itemInputs); - } - } - } - - if (currentParallel <= 0) { - result = CheckRecipeResultRegistry.INTERNAL_ERROR; - return; - } - - calculator.setCurrentParallel(currentParallel) - .calculate(); - // If Batch Mode is enabled determine how many extra parallels we can get - if (batchMode && currentParallel > 0 && calculator.getDuration() < MAX_BATCH_MODE_TICK_TIME) { - int tExtraParallels; - double batchMultiplierMax = MAX_BATCH_MODE_TICK_TIME / calculator.getDuration(); - final int maxExtraParallels = (int) Math.floor( - Math.min( - currentParallel * Math.min(batchMultiplierMax - 1, batchModifier - 1), - maxParallel - currentParallel)); - if (recipeCheck != null) { - tExtraParallels = recipeCheck.checkRecipeInputs(true, maxExtraParallels, itemInputs, fluidInputs); - } else { - tExtraParallels = (int) maxParallelCalculator - .calculate(recipe, maxExtraParallels, fluidInputs, itemInputs); - inputConsumer.consume(recipe, tExtraParallels, fluidInputs, itemInputs); - } - durationMultiplier = 1.0f + (float) tExtraParallels / currentParallel; - currentParallel += tExtraParallels; - } - - // If we want to calculate outputs we do it here - if (calculateOutputs && currentParallel > 0) { - calculateItemOutputs(truncatedItemOutputs); - calculateFluidOutputs(truncatedFluidOutputs); - } - result = CheckRecipeResultRegistry.SUCCESSFUL; - } - - protected void copyInputs() { - ItemStack[] itemInputsToUse; - FluidStack[] fluidInputsToUse; - itemInputsToUse = new ItemStack[itemInputs.length]; - for (int i = 0; i < itemInputs.length; i++) { - itemInputsToUse[i] = itemInputs[i].copy(); - } - fluidInputsToUse = new FluidStack[fluidInputs.length]; - for (int i = 0; i < fluidInputs.length; i++) { - fluidInputsToUse[i] = fluidInputs[i].copy(); - } - itemInputs = itemInputsToUse; - fluidInputs = fluidInputsToUse; - } - - private void calculateItemOutputs(ItemStack[] truncatedItemOutputs) { - if (customItemOutputCalculation != null) { - itemOutputs = customItemOutputCalculation.apply(currentParallel); - return; - } - if (truncatedItemOutputs.length == 0) return; - ArrayList itemOutputsList = new ArrayList<>(); - for (int i = 0; i < truncatedItemOutputs.length; i++) { - if (recipe.getOutput(i) == null) continue; - ItemStack origin = recipe.getOutput(i) - .copy(); - final long itemStackSize = origin.stackSize; - double chancedOutputMultiplier = calculateChancedOutputMultiplier( - (int) (recipe.getOutputChance(i) * chanceMultiplier), - currentParallel); - long items = (long) Math.ceil(itemStackSize * chancedOutputMultiplier * outputMultiplier); - addItemsLong(itemOutputsList, origin, items); - } - itemOutputs = itemOutputsList.toArray(new ItemStack[0]); - } - - private void calculateFluidOutputs(FluidStack[] truncatedFluidOutputs) { - if (customFluidOutputCalculation != null) { - fluidOutputs = customFluidOutputCalculation.apply(currentParallel); - return; - } - if (truncatedFluidOutputs.length == 0) return; - ArrayList fluidOutputsList = new ArrayList<>(); - for (int i = 0; i < truncatedFluidOutputs.length; i++) { - if (recipe.getFluidOutput(i) == null) continue; - FluidStack origin = recipe.getFluidOutput(i) - .copy(); - long fluids = (long) this.outputMultiplier * origin.amount * currentParallel; - - addFluidsLong(fluidOutputsList, origin, fluids); - } - fluidOutputs = fluidOutputsList.toArray(new FluidStack[0]); - } - - private static final Random rand = new Random(); - - public static double calculateChancedOutputMultiplier(int chanceInt, int parallel) { - // Multiply the integer part of the chance directly with parallel - double multiplier = Math.floorDiv(chanceInt, 10000) * parallel; - int transformedChanceInt = chanceInt % 10000; - if (transformedChanceInt == 0) return multiplier; - // Calculation of the Decimal Part of chance - double chance = transformedChanceInt / 10000.0; - double mean = parallel * chance; - double stdDev = Math.sqrt(parallel * chance * (1 - chance)); - // Check if everything within 3 standard deviations of mean is within the range - // of possible values (0 ~ currentParallel) - boolean isSuitableForFittingWithNormalDistribution = mean - 3 * stdDev >= 0 && mean + 3 * stdDev <= parallel; - if (isSuitableForFittingWithNormalDistribution) { - // Use Normal Distribution to fit Binomial Distribution - double tMultiplier = stdDev * rand.nextGaussian() + mean; - multiplier += Math.max(Math.min(tMultiplier, parallel), 0); - } else { - // Do Binomial Distribution by loop - for (int roll = 0; roll < parallel; roll++) { - if (transformedChanceInt > XSTR.XSTR_INSTANCE.nextInt(10000)) { - multiplier += 1; - } - } - } - return multiplier; - } - - public static void addItemsLong(ArrayList itemList, ItemStack origin, long amount) { - if (amount > 0) { - while (amount > Integer.MAX_VALUE) { - ItemStack item = origin.copy(); - item.stackSize = Integer.MAX_VALUE; - itemList.add(item); - amount -= Integer.MAX_VALUE; - } - ItemStack item = origin.copy(); - item.stackSize = (int) amount; - itemList.add(item); - } - } - - public static void addFluidsLong(ArrayList fluidList, FluidStack origin, long amount) { - if (amount > 0) { - while (amount > Integer.MAX_VALUE) { - FluidStack fluid = origin.copy(); - fluid.amount = Integer.MAX_VALUE; - fluidList.add(fluid); - amount -= Integer.MAX_VALUE; - } - FluidStack fluid = origin.copy(); - fluid.amount = (int) amount; - fluidList.add(fluid); - } - } - - @FunctionalInterface - public interface MaxParallelCalculator { - - double calculate(GTRecipe recipe, int maxParallel, FluidStack[] fluids, ItemStack[] items); - } - - @FunctionalInterface - public interface InputConsumer { - - void consume(GTRecipe recipe, int amountMultiplier, FluidStack[] aFluidInputs, ItemStack[] aInputs); - } -} diff --git a/src/main/java/gregtech/api/util/ProcessingHelper.java b/src/main/java/gregtech/api/util/ProcessingHelper.java new file mode 100644 index 00000000000..1fe0e3fca9b --- /dev/null +++ b/src/main/java/gregtech/api/util/ProcessingHelper.java @@ -0,0 +1,757 @@ +package gregtech.api.util; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Objects; +import java.util.Random; +import java.util.function.Function; + +import javax.annotation.Nonnull; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +import gregtech.api.interfaces.tileentity.IRecipeLockable; +import gregtech.api.interfaces.tileentity.IVoidable; +import gregtech.api.objects.XSTR; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.recipe.check.SingleRecipeCheck; + +@SuppressWarnings({ "unused", "UnusedReturnValue" }) +public class ProcessingHelper { + private static final double MAX_BATCH_MODE_TICK_TIME = 128; + private static final int HEAT_DISCOUNT_THRESHOLD = 900; + private static final double OC_EUT_MODIFIER = 4; + protected static final double OC_DURATION_MODIFIER = 0.5; + /** + * Machine used for calculation + */ + private IVoidable machine; + /** + * Machine used for single recipe locking calculation + */ + private IRecipeLockable singleRecipeMachine; + /** + * Is locked to a single recipe? + */ + private boolean isRecipeLocked; + /** + * Recipe used when trying to calculate parallels + */ + private GTRecipe recipe; + /** + * EUt available to the multiblock (This should be the total eut available) + */ + private long availableEUt; + /** + * The current parallel possible for the multiblock + */ + private int currentParallel = 0; + /** + * The maximum possible parallel possible for the multiblock + */ + private int maxParallels = 1; + /** + * The Batch Modifier applied when batch mode is enabled. 1 does nothing. 2 doubles max possible + * parallel, but also duration + */ + private int batchModifier = 1; + /** + * The inputs of the multiblock for the current recipe check + */ + private ItemStack[] itemInputs; + /** + * The outputs of the recipe with the applied parallel + */ + private ItemStack[] itemOutputs; + /** + * The inputs of the multiblock for the current recipe check + */ + private FluidStack[] fluidInputs; + /** + * The outputs of the recipe with the applied parallel + */ + private FluidStack[] fluidOutputs; + /** + * Does the multi have void protection enabled for items + */ + private boolean protectExcessItem; + /** + * Does the multi have void protection enabled for fluids + */ + private boolean protectExcessFluid; + /** + * Should the Parallel Helper automatically consume for the multi + */ + private boolean consume; + /** + * Is batch mode turned on? + */ + private boolean batchMode; + /** + * Should the Parallel Helper automatically calculate the outputs of the recipe with current parallel? + */ + private boolean calculateOutputs; + /** + * Has the Parallel Helper been built? + */ + private boolean built; + /** + * What is the duration multiplier with batch mode enabled + */ + private double durationMultiplier; + /** + * Modifier which is applied on the recipe eut. Useful for GT++ machines + */ + private double eutModifier = 1; + /** + * Modifier which is applied the recipe duration. Useful for GT++ machines + */ + private double durationModifier = 1; + /** + * A supplier used for machines which have a custom way of calculating base duration, like Neutron Activator + */ + private Function durationSupplier; + /** + * Does this machine perform overclocks? + */ + private boolean overclock; + protected Function ocEUtModifierSupplier; + protected Function ocDurationModifierSupplier; + /** + * Multiplier that is applied on the output chances + */ + private double chanceMultiplier = 1; + /** + * Multiplier by which the output will be multiplied + */ + private int outputMultiplier = 1; + /** + * Are perfect heat overclocks enabled? + */ + private boolean heatOC; + /** + * Are heat discounts enabled? + */ + private boolean heatDiscount; + /** + * Energy discount if heatDiscount is used. Applied for every 900 degrees above the recipe requirement. + */ + private double heatDiscountMultiplier; + /** + * Heat of the machine used for processing. + */ + private int machineHeat; + /** + * Method for calculating max parallel from given inputs. + */ + private MaxParallelCalculator maxParallelCalculator = GTRecipe::maxParallelCalculatedByInputs; + /** + * Method for consuming inputs after determining how many parallels it can execute. + */ + private InputConsumer inputConsumer = GTRecipe::consumeInput; + + @Nonnull + private CheckRecipeResult result = CheckRecipeResultRegistry.NONE; + + private Function customItemOutputCalculation; + + private Function customFluidOutputCalculation; + + public ProcessingHelper() {} + + /** + * Sets machine, with current configuration for void protection mode. + */ + @Nonnull + public ProcessingHelper setMachine(IVoidable machine) { + return setMachine(machine, machine.protectsExcessItem(), machine.protectsExcessFluid()); + } + + /** + * Sets machine, with void protection mode forcibly. + */ + @Nonnull + public ProcessingHelper setMachine(IVoidable machine, boolean protectExcessItem, boolean protectExcessFluid) { + this.protectExcessItem = protectExcessItem; + this.protectExcessFluid = protectExcessFluid; + this.machine = machine; + return this; + } + + /** + * Sets the recipe, which will be used for the parallel calculation + */ + @Nonnull + public ProcessingHelper setRecipe(@Nonnull GTRecipe aRecipe) { + recipe = Objects.requireNonNull(aRecipe); + return this; + } + + @Nonnull + public ProcessingHelper setRecipeLocked(IRecipeLockable singleRecipeMachine, boolean isRecipeLocked) { + this.singleRecipeMachine = singleRecipeMachine; + this.isRecipeLocked = isRecipeLocked; + return this; + } + + /** + * Sets the items available for the recipe check + */ + @Nonnull + public ProcessingHelper setItemInputs(ItemStack... aItemInputs) { + this.itemInputs = aItemInputs; + return this; + } + + /** + * Sets the fluid inputs available for the recipe check + */ + @Nonnull + public ProcessingHelper setFluidInputs(FluidStack... aFluidInputs) { + this.fluidInputs = aFluidInputs; + return this; + } + + /** + * Sets the available eut when trying for more parallels + */ + @Nonnull + public ProcessingHelper setAvailableEUt(long aAvailableEUt) { + this.availableEUt = aAvailableEUt; + return this; + } + + /** + * Sets the modifier for recipe eut. 1 does nothing 0.9 is 10% less. 1.1 is 10% more + */ + @Nonnull + public ProcessingHelper setEUtModifier(double aEUtModifier) { + this.eutModifier = aEUtModifier; + return this; + } + + /** + * Sets the modifier for recipe duration. 1 does nothing, 2 is twice as slow, 0.5 is twice as fast + */ + @Nonnull + public ProcessingHelper setDurationModifier(double durationModifier) { + this.durationModifier = durationModifier; + return this; + } + + /** + * Set the supplier used for machines which have a custom way of calculating base duration, like Neutron Activator + */ + @Nonnull + public ProcessingHelper setDurationSupplier(Function durationSupplier) { + this.durationSupplier = durationSupplier; + return this; + } + + /** + * Sets whether the machine performs overclocks. + */ + @Nonnull + public ProcessingHelper setOverclock(boolean overclock) { + this.overclock = overclock; + return this; + } + + @Nonnull + public ProcessingHelper setOCEUtModifierSupplier(Function ocEUtModifierSupplier) { + this.ocEUtModifierSupplier = ocEUtModifierSupplier; + return this; + } + + @Nonnull + public ProcessingHelper setOCDurationModifierSupplier(Function ocDurationModifierSupplier) { + this.ocDurationModifierSupplier = ocDurationModifierSupplier; + return this; + } + + /** + * Sets the multiplier that is applied on output chances. 1 does nothing. 0.9 is 10% less. 1.1 is 10% more. + * Only useful for item outputs for sure. + */ + @Nonnull + public ProcessingHelper setChanceMultiplier(double chanceMultiplier) { + this.chanceMultiplier = chanceMultiplier; + return this; + } + + /** + * Sets the item/fluid output multiplier. 1 does nothing. 2 doubles the item and fluid outputs. + */ + @Nonnull + public ProcessingHelper setOutputMultiplier(int outputMultiplier) { + this.outputMultiplier = outputMultiplier; + return this; + } + + /** + * Set if we should consume inputs or not when trying for parallels + * + * @param consume Should we consume inputs + */ + @Nonnull + public ProcessingHelper setConsumption(boolean consume) { + this.consume = consume; + return this; + } + + /** + * Sets the MaxParallel a multi can handle + */ + @Nonnull + public ProcessingHelper setMaxParallels(int maxParallels) { + this.maxParallels = maxParallels; + return this; + } + + /** + * Enables Batch mode, allowing additional recipes to be processed in parallel + * with proportionally increased processing time. Processes up to mCurrentParallel * BatchModifier recipes. + */ + @Nonnull + public ProcessingHelper setBatchMode(boolean batchMode) { + this.batchMode = batchMode; + return this; + } + + /** + * Sets the batch modifier, which determines how many additional recipes + * can be processed in parallel when Batch Mode is enabled. + **/ + @Nonnull + public ProcessingHelper setBatchModifier(int batchModifier) { + this.batchModifier = batchModifier; + return this; + } + + /** + * Sets if we should calculate outputs with the parallels we found or not + * + * @param calculateOutputs Should we calculate outputs with the helper or not + */ + @Nonnull + public ProcessingHelper setOutputCalculation(boolean calculateOutputs) { + this.calculateOutputs = calculateOutputs; + return this; + } + + /** + * Set a custom way to calculate item outputs. You are given the amount of parallels and must return an ItemStack + * array + */ + @Nonnull + public ProcessingHelper setCustomItemOutputCalculation(Function custom) { + customItemOutputCalculation = custom; + return this; + } + + /** + * Set a custom way to calculate item outputs. You are given the amount of parallels and must return a FluidStack + * array + */ + @Nonnull + public ProcessingHelper setCustomFluidOutputCalculation(Function custom) { + customFluidOutputCalculation = custom; + return this; + } + + /** + * Sets method for calculating max parallel from given inputs. + */ + public ProcessingHelper setMaxParallelCalculator(MaxParallelCalculator maxParallelCalculator) { + this.maxParallelCalculator = maxParallelCalculator; + return this; + } + + /** + * Sets method for consuming inputs after determining how many parallels it can execute. + */ + public ProcessingHelper setInputConsumer(InputConsumer inputConsumer) { + this.inputConsumer = inputConsumer; + return this; + } + + @Nonnull + public ProcessingHelper setHeatOC(boolean heatOC) { + this.heatOC = heatOC; + return this; + } + + @Nonnull + public ProcessingHelper setHeatDiscount(boolean heatDiscount) { + this.heatDiscount = heatDiscount; + return this; + } + + @Nonnull + public ProcessingHelper setHeatDiscountMultiplier(double heatDiscountMultiplier) { + this.heatDiscountMultiplier = heatDiscountMultiplier; + return this; + } + + @Nonnull + public ProcessingHelper setMachineHeat(int machineHeat) { + this.machineHeat = machineHeat; + return this; + } + + /** + * @return The current parallels possible by the multiblock + */ + public int getCurrentParallel() { + if (!built) { + throw new IllegalStateException("Tried to get parallels before building"); + } + return currentParallel; + } + + /** + * @return The duration multiplier if batch mode was enabled for the multiblock + */ + public double getDurationMultiplierDouble() { + if (!built) { + throw new IllegalStateException("Tried to get duration multiplier before building"); + } + if (batchMode && durationMultiplier > 0) { + return durationMultiplier; + } + return 1; + } + + /** + * @return The ItemOutputs from the recipe + */ + @Nonnull + public ItemStack[] getItemOutputs() { + if (!built || !calculateOutputs) { + throw new IllegalStateException( + "Tried to get item outputs before building or without enabling calculation of outputs"); + } + return itemOutputs; + } + + /** + * @return The FluidOutputs from the recipe + */ + @Nonnull + public FluidStack[] getFluidOutputs() { + if (!built || !calculateOutputs) { + throw new IllegalStateException( + "Tried to get fluid outputs before building or without enabling calculation of outputs"); + } + return fluidOutputs; + } + + /** + * @return The result of why a recipe could've failed or succeeded + */ + @Nonnull + public CheckRecipeResult getResult() { + if (!built) { + throw new IllegalStateException("Tried to get recipe result before building"); + } + return result; + } + + /** + * Called by build(). Determines the parallels and everything else that needs to be done at build time + */ + public ProcessingResult process() { + // Sanitize inputs + this.itemInputs = this.itemInputs == null ? new ItemStack[0] : this.itemInputs; + this.fluidInputs = this.fluidInputs == null ? new FluidStack[0] : this.fluidInputs; + + // If not consuming, perform deep copy + if (!this.consume) { + this.itemInputs = Arrays.stream(this.itemInputs) + .map(ItemStack::copy) + .toArray(ItemStack[]::new); + this.fluidInputs = Arrays.stream(this.fluidInputs) + .map(FluidStack::copy) + .toArray(FluidStack[]::new); + } + + // Truncate and sanitize the outputs + final ItemStack[] truncatedItemOutputs = this.recipe.mOutputs == null ? new ItemStack[0] + : Arrays.copyOfRange( + this.recipe.mOutputs, + 0, + Math.min(this.machine.getItemOutputLimit(), this.recipe.mOutputs.length)); + final FluidStack[] truncatedFluidOutputs = this.recipe.mFluidOutputs == null ? new FluidStack[0] + : Arrays.copyOfRange( + this.recipe.mFluidOutputs, + 0, + Math.min(this.machine.getFluidOutputLimit(), this.recipe.mFluidOutputs.length)); + + // Calculate heat discount + final double heatDiscount = this.heatDiscount ? Math.pow( + this.heatDiscountMultiplier, + Math.max(0, (this.recipe.mSpecialValue - this.machineHeat) / HEAT_DISCOUNT_THRESHOLD)) : 1; + + // Check whether there is sufficient energy + final int EUt = (int) Math.ceil(this.recipe.mEUt * this.eutModifier * heatDiscount); + if (this.availableEUt < EUt) { + return ProcessingResult.failure(CheckRecipeResultRegistry.insufficientPower(EUt)); + } + + // Determine parallels before sub-tick and batch + int parallels = EUt > 0 ? (int) Math.min(this.maxParallels, this.availableEUt / EUt) : this.maxParallels; + + // Determine duration using speed modifier or using custom supplier + double duration = this.durationSupplier == null ? this.recipe.mDuration * this.durationModifier + : this.durationSupplier.apply(this.recipe); + + if (this.overclock) { + double ocEUtModifier = ocEUtModifierSupplier == null ? OC_EUT_MODIFIER : ocEUtModifierSupplier.apply(0); + double ocDurationModifier = ocDurationModifierSupplier == null ? OC_DURATION_MODIFIER : ocDurationModifierSupplier.apply(0); + } + + // public double calculateDurationUnderOneTick() { + // if (noOverclock) return durationInDouble; + // double heatDiscountMultiplier = calculateHeatDiscountMultiplier(); + // if (hasAtLeastOneSupplierBeenSet) { + // int overclockCount = 0; + // double currentEutIncrease = eutIncreasePerOCSupplier.apply(overclockCount + 1); + // double currentDurationDecrease = durationDecreasePerOCSupplier.apply(overclockCount + 1); + // double machinePower = calculateMachinePower(); + // double recipePower = calculateRecipePower(heatDiscountMultiplier); + // while (machinePower > recipePower * currentEutIncrease + // && (!limitOverclocks || overclockCount < maxOverclocks)) { + // recipePower *= currentEutIncrease; + // durationInDouble /= currentDurationDecrease; + // overclockCount++; + // currentEutIncrease = eutIncreasePerOCSupplier.apply(overclockCount + 1); + // currentDurationDecrease = durationDecreasePerOCSupplier.apply(overclockCount + 1); + // } + // } else { + // int maxOverclockCount = calculateAmountOfOverclocks( + // calculateMachinePowerTier(), + // calculateRecipePowerTier(heatDiscountMultiplier)); + // if (limitOverclocks) maxOverclockCount = Math.min(maxOverclocks, maxOverclockCount); + // int heatOverclocks = Math.min(calculateMaxAmountOfHeatOverclocks(), maxOverclockCount); + // durationInDouble /= Math.pow(durationDecreasePerOC, maxOverclockCount - heatOverclocks) + // * Math.pow(durationDecreasePerHeatOC, heatOverclocks); + // } + // return durationInDouble; + // } + + // TODO + // double overclockedDuration; + // int subTickParallels; + // if (overclockedDuration < 1) { + // subTickParallels = GTUtility.safeInt((long) (maxParallels / overclockedDuration), 0); + // } + + // int batchParallels; + // if (batchMode) { + // batchParallels = GTUtility.safeInt((long) maxParallels * batchModifier, 0); + // } + + // todo + // SingleRecipeCheck recipeCheck = null; + // SingleRecipeCheck.Builder tSingleRecipeCheckBuilder = null; + // if (isRecipeLocked && singleRecipeMachine != null) { + // recipeCheck = singleRecipeMachine.getSingleRecipeCheck(); + // if (recipeCheck == null) { + // // Machine is configured to lock to a single recipe, but haven't built the recipe checker yet. + // // Build the checker on next successful recipe. + // RecipeMap recipeMap = singleRecipeMachine.getRecipeMap(); + // if (recipeMap != null) { + // tSingleRecipeCheckBuilder = SingleRecipeCheck.builder(recipeMap) + // .setBefore(itemInputs, fluidInputs); + // } + // } + // } + + // Let's look at how many parallels we can get with void protection + // if (this.protectExcessItem || this.protectExcessFluid) { + // if (this.machine == null) { + // throw new IllegalStateException("Tried to calculate void protection, but machine is not set"); + // } + // VoidProtectionHelper voidProtectionHelper = new VoidProtectionHelper(); + // voidProtectionHelper.setMachine(machine) + // .setItemOutputs(truncatedItemOutputs) + // .setFluidOutputs(truncatedFluidOutputs) + // .setChangeGetter(recipe::getOutputChance) + // .setOutputMultiplier(outputMultiplier) + // .setChanceMultiplier(chanceMultiplier) + // .setMaxParallel(maxParallels) + // .build(); + // maxParallels = Math.min(voidProtectionHelper.getMaxParallel(), maxParallels); + // if (voidProtectionHelper.isItemFull()) { + // return ProcessingResult.failure(CheckRecipeResultRegistry.ITEM_OUTPUT_FULL); + // } + // if (voidProtectionHelper.isFluidFull()) { + // return ProcessingResult.failure(CheckRecipeResultRegistry.FLUID_OUTPUT_FULL); + // } + // } + // + // maxParallelBeforeBatchMode = Math.min(maxParallels, maxParallelBeforeBatchMode); +// +// if (recipeCheck != null) { +// currentParallel = recipeCheck.checkRecipeInputs(true, actualMaxParallel, itemInputs, fluidInputs); +// } else { +// currentParallel = (int) maxParallelCalculator.calculate(recipe, actualMaxParallel, fluidInputs, itemInputs); +// if (currentParallel > 0) { +// if (tSingleRecipeCheckBuilder != null) { +// // If recipe checker is not built yet, build and set it +// inputConsumer.consume(recipe, 1, fluidInputs, itemInputs); +// SingleRecipeCheck builtCheck = tSingleRecipeCheckBuilder.setAfter(itemInputs, fluidInputs) +// .setRecipe(recipe) +// .build(); +// singleRecipeMachine.setSingleRecipeCheck(builtCheck); +// inputConsumer.consume(recipe, currentParallel - 1, fluidInputs, itemInputs); +// } else { +// inputConsumer.consume(recipe, currentParallel, fluidInputs, itemInputs); +// } +// } +// } +// +// if (currentParallel <= 0) { +// result = CheckRecipeResultRegistry.INTERNAL_ERROR; +// return; +// } +// +// calculator.setCurrentParallel(currentParallel) +// .calculate(); +// // If Batch Mode is enabled determine how many extra parallels we can get +// if (batchMode && currentParallel > 0 && calculator.getDuration() < MAX_BATCH_MODE_TICK_TIME) { +// int tExtraParallels; +// double batchMultiplierMax = MAX_BATCH_MODE_TICK_TIME / calculator.getDuration(); +// final int maxExtraParallels = (int) Math.floor( +// Math.min( +// currentParallel * Math.min(batchMultiplierMax - 1, batchModifier - 1), +// maxParallels - currentParallel)); +// if (recipeCheck != null) { +// tExtraParallels = recipeCheck.checkRecipeInputs(true, maxExtraParallels, itemInputs, fluidInputs); +// } else { +// tExtraParallels = (int) maxParallelCalculator +// .calculate(recipe, maxExtraParallels, fluidInputs, itemInputs); +// inputConsumer.consume(recipe, tExtraParallels, fluidInputs, itemInputs); +// } +// durationMultiplier = 1.0f + (float) tExtraParallels / currentParallel; +// currentParallel += tExtraParallels; +// } +// +// // If we want to calculate outputs we do it here +// if (calculateOutputs && currentParallel > 0) { +// calculateItemOutputs(truncatedItemOutputs); +// calculateFluidOutputs(truncatedFluidOutputs); +// } + return ProcessingResult.success(CheckRecipeResultRegistry.SUCCESSFUL); + } + + private void calculateItemOutputs(ItemStack[] truncatedItemOutputs) { + if (customItemOutputCalculation != null) { + itemOutputs = customItemOutputCalculation.apply(currentParallel); + return; + } + if (truncatedItemOutputs.length == 0) return; + ArrayList itemOutputsList = new ArrayList<>(); + for (int i = 0; i < truncatedItemOutputs.length; i++) { + if (recipe.getOutput(i) == null) continue; + ItemStack origin = recipe.getOutput(i) + .copy(); + final long itemStackSize = origin.stackSize; + double chancedOutputMultiplier = calculateChancedOutputMultiplier( + (int) (recipe.getOutputChance(i) * chanceMultiplier), + currentParallel); + long items = (long) Math.ceil(itemStackSize * chancedOutputMultiplier * outputMultiplier); + addItemsLong(itemOutputsList, origin, items); + } + itemOutputs = itemOutputsList.toArray(new ItemStack[0]); + } + + private void calculateFluidOutputs(FluidStack[] truncatedFluidOutputs) { + if (customFluidOutputCalculation != null) { + fluidOutputs = customFluidOutputCalculation.apply(currentParallel); + return; + } + if (truncatedFluidOutputs.length == 0) return; + ArrayList fluidOutputsList = new ArrayList<>(); + for (int i = 0; i < truncatedFluidOutputs.length; i++) { + if (recipe.getFluidOutput(i) == null) continue; + FluidStack origin = recipe.getFluidOutput(i) + .copy(); + long fluids = (long) this.outputMultiplier * origin.amount * currentParallel; + + addFluidsLong(fluidOutputsList, origin, fluids); + } + fluidOutputs = fluidOutputsList.toArray(new FluidStack[0]); + } + + private static final Random rand = new Random(); + + public static double calculateChancedOutputMultiplier(int chanceInt, int parallel) { + // Multiply the integer part of the chance directly with parallel + double multiplier = Math.floorDiv(chanceInt, 10000) * parallel; + int transformedChanceInt = chanceInt % 10000; + if (transformedChanceInt == 0) return multiplier; + // Calculation of the Decimal Part of chance + double chance = transformedChanceInt / 10000.0; + double mean = parallel * chance; + double stdDev = Math.sqrt(parallel * chance * (1 - chance)); + // Check if everything within 3 standard deviations of mean is within the range + // of possible values (0 ~ currentParallel) + boolean isSuitableForFittingWithNormalDistribution = mean - 3 * stdDev >= 0 && mean + 3 * stdDev <= parallel; + if (isSuitableForFittingWithNormalDistribution) { + // Use Normal Distribution to fit Binomial Distribution + double tMultiplier = stdDev * rand.nextGaussian() + mean; + multiplier += Math.max(Math.min(tMultiplier, parallel), 0); + } else { + // Do Binomial Distribution by loop + for (int roll = 0; roll < parallel; roll++) { + if (transformedChanceInt > XSTR.XSTR_INSTANCE.nextInt(10000)) { + multiplier += 1; + } + } + } + return multiplier; + } + + public static void addItemsLong(ArrayList itemList, ItemStack origin, long amount) { + if (amount > 0) { + while (amount > Integer.MAX_VALUE) { + ItemStack item = origin.copy(); + item.stackSize = Integer.MAX_VALUE; + itemList.add(item); + amount -= Integer.MAX_VALUE; + } + ItemStack item = origin.copy(); + item.stackSize = (int) amount; + itemList.add(item); + } + } + + public static void addFluidsLong(ArrayList fluidList, FluidStack origin, long amount) { + if (amount > 0) { + while (amount > Integer.MAX_VALUE) { + FluidStack fluid = origin.copy(); + fluid.amount = Integer.MAX_VALUE; + fluidList.add(fluid); + amount -= Integer.MAX_VALUE; + } + FluidStack fluid = origin.copy(); + fluid.amount = (int) amount; + fluidList.add(fluid); + } + } + + @FunctionalInterface + public interface MaxParallelCalculator { + + double calculate(GTRecipe recipe, int maxParallel, FluidStack[] fluids, ItemStack[] items); + } + + @FunctionalInterface + public interface InputConsumer { + + void consume(GTRecipe recipe, int amountMultiplier, FluidStack[] aFluidInputs, ItemStack[] aInputs); + } +} diff --git a/src/main/java/gregtech/api/util/ProcessingResult.java b/src/main/java/gregtech/api/util/ProcessingResult.java new file mode 100644 index 00000000000..4b979d75262 --- /dev/null +++ b/src/main/java/gregtech/api/util/ProcessingResult.java @@ -0,0 +1,30 @@ +package gregtech.api.util; + +import gregtech.api.recipe.check.CheckRecipeResult; + +public class ProcessingResult { + + private final boolean success; + private final CheckRecipeResult result; + + private ProcessingResult(boolean success, CheckRecipeResult result) { + this.success = success; + this.result = result; + } + + public static ProcessingResult success(CheckRecipeResult result) { + return new ProcessingResult(true, result); + } + + public static ProcessingResult failure(CheckRecipeResult result) { + return new ProcessingResult(false, result); + } + + public boolean wasSuccessful() { + return success; + } + + public CheckRecipeResult getResult() { + return result; + } +} diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEAssemblyLine.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEAssemblyLine.java index d090cb1eac8..c53cd5de991 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEAssemblyLine.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEAssemblyLine.java @@ -61,7 +61,7 @@ import gregtech.api.util.IGTHatchAdder; import gregtech.api.util.MultiblockTooltipBuilder; import gregtech.api.util.OverclockCalculator; -import gregtech.api.util.ParallelHelper; +import gregtech.api.util.ProcessingHelper; import gregtech.api.util.VoidProtectionHelper; public class MTEAssemblyLine extends MTEExtendedPowerMultiBlockBase implements ISurvivalConstructable { @@ -362,7 +362,7 @@ public CheckRecipeResult checkProcessing() { } result = CheckRecipeResultRegistry.SUCCESSFUL; ArrayList outputs = new ArrayList<>(); - ParallelHelper.addItemsLong(outputs, tRecipe.mOutput, (long) tRecipe.mOutput.stackSize * maxParallel); + ProcessingHelper.addItemsLong(outputs, tRecipe.mOutput, (long) tRecipe.mOutput.stackSize * maxParallel); mOutputItems = outputs.toArray(new ItemStack[0]); break; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEDistillationTower.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEDistillationTower.java index e736415be48..06332aee352 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEDistillationTower.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEDistillationTower.java @@ -188,7 +188,7 @@ public boolean isCorrectMachinePart(ItemStack aStack) { @Override protected ProcessingLogic createProcessingLogic() { - return new ProcessingLogic(); + return new ProcessingLogic().setOverclock(true); } protected void onCasingFound() { diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEElectricBlastFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEElectricBlastFurnace.java index f69008c97d5..801b472a045 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEElectricBlastFurnace.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEElectricBlastFurnace.java @@ -51,7 +51,6 @@ import gregtech.api.util.GTRecipe; import gregtech.api.util.GTUtility; import gregtech.api.util.MultiblockTooltipBuilder; -import gregtech.api.util.OverclockCalculator; public class MTEElectricBlastFurnace extends MTEAbstractMultiFurnace implements ISurvivalConstructable { @@ -166,22 +165,16 @@ public IStructureDefinition getStructureDefinition() { @Override protected ProcessingLogic createProcessingLogic() { return new ProcessingLogic() { - - @Nonnull - @Override - protected OverclockCalculator createOverclockCalculator(@Nonnull GTRecipe recipe) { - return super.createOverclockCalculator(recipe).setRecipeHeat(recipe.mSpecialValue) - .setMachineHeat(mHeatingCapacity) - .setHeatOC(true) - .setHeatDiscount(true); - } - @Override protected @Nonnull CheckRecipeResult validateRecipe(@Nonnull GTRecipe recipe) { return recipe.mSpecialValue <= mHeatingCapacity ? CheckRecipeResultRegistry.SUCCESSFUL : CheckRecipeResultRegistry.insufficientHeat(recipe.mSpecialValue); } - }; + }.setOverclock(true) + .setHeatOC(true) + .setHeatDiscount(true) + .setHeatDiscountMultiplier(0.95) + .setMachineHeat(this.mHeatingCapacity); } @Override diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEFusionComputer.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEFusionComputer.java index 17a55c45204..f2389c93653 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEFusionComputer.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEFusionComputer.java @@ -74,7 +74,7 @@ import gregtech.api.util.GTUtility; import gregtech.api.util.MultiblockTooltipBuilder; import gregtech.api.util.OverclockCalculator; -import gregtech.api.util.ParallelHelper; +import gregtech.api.util.ProcessingHelper; import gregtech.api.util.shutdown.ShutDownReason; import gregtech.api.util.shutdown.ShutDownReasonRegistry; import gregtech.common.tileentities.machines.multi.drone.MTEHatchDroneDownLink; @@ -314,9 +314,9 @@ protected ProcessingLogic createProcessingLogic() { @NotNull @Override - protected ParallelHelper createParallelHelper(@NotNull GTRecipe recipe) { + protected ProcessingHelper createProcessingHelper(@NotNull GTRecipe recipe) { // When the fusion first loads and is still processing, it does the recipe check without consuming. - return super.createParallelHelper(recipe).setConsumption(!mRunningOnLoad); + return super.createProcessingHelper(recipe).setConsumption(!mRunningOnLoad); } @NotNull diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEImplosionCompressor.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEImplosionCompressor.java index 5a0155b12fe..fa4ec5d89b8 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEImplosionCompressor.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEImplosionCompressor.java @@ -117,7 +117,7 @@ public boolean isCorrectMachinePart(ItemStack aStack) { @Override protected ProcessingLogic createProcessingLogic() { - return new ProcessingLogic(); + return new ProcessingLogic().setOverclock(true); } @Override diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEIndustrialBrewery.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEIndustrialBrewery.java index 8f2c6d6c240..f125c4c5eb0 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEIndustrialBrewery.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEIndustrialBrewery.java @@ -195,7 +195,9 @@ protected void setProcessingLogicPower(ProcessingLogic logic) { @Override protected ProcessingLogic createProcessingLogic() { - return new ProcessingLogic().setSpeedBonus(1F / 1.5F) + return new ProcessingLogic() + .setOverclock(true) + .setSpeedBonus(1F / 1.5F) .setMaxParallelSupplier(this::getMaxParallelRecipes); } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEIndustrialElectromagneticSeparator.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEIndustrialElectromagneticSeparator.java index d4bcd9e2f2e..e4cea422178 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEIndustrialElectromagneticSeparator.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEIndustrialElectromagneticSeparator.java @@ -282,7 +282,7 @@ protected CheckRecipeResult validateRecipe(@Nonnull GTRecipe recipe) { if (magnetTier != null) { if (!mExoticEnergyHatches.isEmpty() && !magnetTier.supportsExotic) return SimpleCheckRecipeResult.ofFailure("electromagnet_insufficient"); - euModifier = magnetTier.euModifier; + eutModifier = magnetTier.euModifier; speedBoost = magnetTier.speedBoost; return CheckRecipeResultRegistry.SUCCESSFUL; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEIndustrialExtractor.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEIndustrialExtractor.java index 9cf147b4f48..33d9e737092 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEIndustrialExtractor.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEIndustrialExtractor.java @@ -211,7 +211,7 @@ public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack a protected ProcessingLogic createProcessingLogic() { return new ProcessingLogic().setSpeedBonus(1F / 3F) .setMaxParallelSupplier(this::getMaxParallelRecipes) - .setEuModifier(0.85F); + .setEUtModifier(0.85F); } public int getMaxParallelRecipes() { diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEIndustrialLaserEngraver.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEIndustrialLaserEngraver.java index 767d765e7f9..adb70b7b881 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEIndustrialLaserEngraver.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEIndustrialLaserEngraver.java @@ -368,7 +368,7 @@ public ProcessingLogic clear() { return super.clear(); } }.setSpeedBonus(1F / 3.5F) - .setEuModifier(0.8F) + .setEUtModifier(0.8F) .setMaxParallelSupplier(this::getMaxParallelRecipes); } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTELargeChemicalReactor.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTELargeChemicalReactor.java index 4eb9ad48409..0de33b07f9a 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTELargeChemicalReactor.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTELargeChemicalReactor.java @@ -165,7 +165,7 @@ public RecipeMap getRecipeMap() { @Override protected ProcessingLogic createProcessingLogic() { - return new ProcessingLogic().enablePerfectOverclock(); + return new ProcessingLogic().setPerfectOverclock(); } @Override diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTELargeFluidExtractor.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTELargeFluidExtractor.java index d0f807c173f..a6b841b4f8d 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTELargeFluidExtractor.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTELargeFluidExtractor.java @@ -207,7 +207,7 @@ protected void setProcessingLogicPower(ProcessingLogic logic) { logic.setAmperageOC(true); logic.setAvailableVoltage(GTUtility.roundUpVoltage(this.getMaxInputVoltage())); logic.setAvailableAmperage(1); - logic.setEuModifier(getEUMultiplier()); + logic.setEUtModifier(getEUMultiplier()); logic.setMaxParallel(getParallels()); logic.setSpeedBonus(1.0f / getSpeedBonus()); } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiAutoclave.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiAutoclave.java index 6cd585859d2..6be717f5544 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiAutoclave.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiAutoclave.java @@ -320,7 +320,7 @@ protected ProcessingLogic createProcessingLogic() { @Override @Nonnull public CheckRecipeResult process() { - euModifier = euModifier(fluidPipeTier); + eutModifier = euModifier(fluidPipeTier); speedBoost = speedBoost(getCoilTier()); return super.process(); } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiLathe.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiLathe.java index ea42aea04a0..3627cf0c4bf 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiLathe.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiLathe.java @@ -251,7 +251,7 @@ public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack a @Override protected ProcessingLogic createProcessingLogic() { return new ProcessingLogic().setSpeedBonus(1F / 4F) - .setEuModifier(0.8F) + .setEUtModifier(0.8F) .setMaxParallelSupplier(this::getMaxParallelRecipes); } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java index ee5b8b52f2d..ff15f70e820 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java @@ -340,7 +340,7 @@ protected CheckRecipeResult validateRecipe(@NotNull GTRecipe recipe) { return super.validateRecipe(recipe); } }.setMaxParallelSupplier(this::getMaxParallelRecipes) - .setEuModifier(0.8F); + .setEUtModifier(0.8F); } @Override diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEOilCracker.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEOilCracker.java index 885d9e90fe0..4f08d05800e 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEOilCracker.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEOilCracker.java @@ -175,7 +175,7 @@ protected ProcessingLogic createProcessingLogic() { @Nonnull @Override public CheckRecipeResult process() { - setEuModifier(1.0F - Math.min(0.1F * (heatLevel.getTier() + 1), 0.5F)); + setEUtModifier(1.0F - Math.min(0.1F * (heatLevel.getTier() + 1), 0.5F)); return super.process(); } }; diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEPCBFactory.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEPCBFactory.java index 0e53903caa8..8d9ebe8c612 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEPCBFactory.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEPCBFactory.java @@ -91,7 +91,7 @@ import gregtech.api.util.IGTHatchAdder; import gregtech.api.util.MultiblockTooltipBuilder; import gregtech.api.util.OverclockCalculator; -import gregtech.api.util.ParallelHelper; +import gregtech.api.util.ProcessingHelper; import gregtech.api.util.shutdown.ShutDownReasonRegistry; import gregtech.common.blocks.BlockCasings8; @@ -589,7 +589,7 @@ protected CheckRecipeResult validateRecipe(@Nonnull GTRecipe recipe) { @Nonnull @Override protected OverclockCalculator createOverclockCalculator(@Nonnull GTRecipe recipe) { - return super.createOverclockCalculator(recipe).setNoOverclock(isNoOC()) + return super.createOverclockCalculator(recipe) .setEUtDiscount(Math.sqrt(mUpgradesInstalled == 0 ? 1 : mUpgradesInstalled)) .setSpeedBoost(getDurationMultiplierFromRoughness()) .setDurationDecreasePerOC(mOCTier2 ? 4.0 : 2.0); @@ -597,16 +597,12 @@ protected OverclockCalculator createOverclockCalculator(@Nonnull GTRecipe recipe @Nonnull @Override - protected ParallelHelper createParallelHelper(@Nonnull GTRecipe recipe) { - return super.createParallelHelper(recipe) + protected ProcessingHelper createProcessingHelper(@Nonnull GTRecipe recipe) { + return super.createProcessingHelper(recipe) .setEUtModifier((float) Math.sqrt(mUpgradesInstalled == 0 ? 1 : mUpgradesInstalled)) .setChanceMultiplier(mRoughnessMultiplier); } - }; - } - - private boolean isNoOC() { - return !mOCTier1 && !mOCTier2; + }.setOverclock(this.mOCTier1 || this.mOCTier2); } private double getDurationMultiplierFromRoughness() { @@ -622,7 +618,7 @@ public boolean onRunningTick(ItemStack aStack) { } if (ticker % 20 == 0) { - if (!isNoOC()) { + if (this.mOCTier1 || this.mOCTier2) { FluidStack tFluid = mOCTier1 ? GTModHandler.getDistilledWater(COOLANT_CONSUMED_PER_SEC) : Materials.SuperCoolant.getFluid(COOLANT_CONSUMED_PER_SEC); if (!drain(mCoolantInputHatch, tFluid, true)) { 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 ab9ba172095..3f0f4394f6d 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEPlasmaForge.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEPlasmaForge.java @@ -83,7 +83,7 @@ import gregtech.api.util.GTUtility; import gregtech.api.util.MultiblockTooltipBuilder; import gregtech.api.util.OverclockCalculator; -import gregtech.api.util.ParallelHelper; +import gregtech.api.util.ProcessingHelper; import tectech.thing.gui.TecTechUITextures; public class MTEPlasmaForge extends MTEExtendedPowerMultiBlockBase implements ISurvivalConstructable { @@ -762,8 +762,7 @@ protected ProcessingLogic createProcessingLogic() { @Nonnull @Override protected OverclockCalculator createOverclockCalculator(@Nonnull GTRecipe recipe) { - overclockCalculator = super.createOverclockCalculator(recipe).setRecipeHeat(recipe.mSpecialValue) - .setMachineHeat(mHeatingCapacity); + overclockCalculator = super.createOverclockCalculator(recipe).setRecipeHeat(recipe.mSpecialValue); if (discount == maximum_discount && convergence) { if (doesRecipeHaveNativeCatInput || isEnoughCatalystPresent) { overclockCalculator = overclockCalculator.enablePerfectOC(); @@ -774,8 +773,8 @@ protected OverclockCalculator createOverclockCalculator(@Nonnull GTRecipe recipe @NotNull @Override - protected ParallelHelper createParallelHelper(@Nonnull GTRecipe recipe) { - return super.createParallelHelper(recipeAfterAdjustments(recipe)); + protected ProcessingHelper createProcessingHelper(@Nonnull GTRecipe recipe) { + return super.createProcessingHelper(recipeAfterAdjustments(recipe)); } @Override @@ -783,7 +782,7 @@ protected ParallelHelper createParallelHelper(@Nonnull GTRecipe recipe) { return recipe.mSpecialValue <= mHeatingCapacity ? CheckRecipeResultRegistry.SUCCESSFUL : CheckRecipeResultRegistry.insufficientHeat(recipe.mSpecialValue); } - }; + }.setMachineHeat(this.mHeatingCapacity); } @Nonnull diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java b/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java index f595e0b16d8..a48ed06c850 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java @@ -599,7 +599,7 @@ protected CheckRecipeResult validateRecipe(@NotNull GTRecipe recipe) { return super.validateRecipe(recipe); } }.setMaxParallelSupplier(this::getMaxParallelRecipes) - .setEuModifier(0.7F) + .setEUtModifier(0.7F) .setSpeedBonus(0.2F); } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEHIPCompressor.java b/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEHIPCompressor.java index 0c716e975a3..ba9b1235e7f 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEHIPCompressor.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEHIPCompressor.java @@ -369,14 +369,14 @@ protected ProcessingLogic createProcessingLogic() { @Override protected CheckRecipeResult validateRecipe(@NotNull GTRecipe recipe) { setSpeedBonus(1F / 3.5F); - setEuModifier(0.75F); + setEUtModifier(0.75F); int recipeReq = recipe.getMetadataOrDefault(CompressionTierKey.INSTANCE, 0); // Nerf when heated if (overheated) { setSpeedBonus(2.5F); - setEuModifier(1.1F); + setEUtModifier(1.1F); } // If HIP required, check for overheat and potentially crash diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEIndustrialCompressor.java b/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEIndustrialCompressor.java index bd8fc806cbc..d6dfb112785 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEIndustrialCompressor.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEIndustrialCompressor.java @@ -202,7 +202,7 @@ protected CheckRecipeResult validateRecipe(@NotNull GTRecipe recipe) { } }.setSpeedBonus(1F / 2F) .setMaxParallelSupplier(this::getMaxParallelRecipes) - .setEuModifier(0.9F); + .setEUtModifier(0.9F); } public int getMaxParallelRecipes() { diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/MTEAmazonPackager.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/MTEAmazonPackager.java index c1e245350af..1007b71e39e 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/MTEAmazonPackager.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/MTEAmazonPackager.java @@ -159,7 +159,7 @@ public Collection> getAvailableRecipeMaps() { @Override protected ProcessingLogic createProcessingLogic() { return new ProcessingLogic().setSpeedBonus(1F / 6F) - .setEuModifier(0.75F) + .setEUtModifier(0.75F) .setMaxParallelSupplier(this::getMaxParallelRecipes); } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialAlloySmelter.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialAlloySmelter.java index 873fa99ecfe..b6536a7c71d 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialAlloySmelter.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialAlloySmelter.java @@ -204,14 +204,14 @@ protected ProcessingLogic createProcessingLogic() { @Override protected OverclockCalculator createOverclockCalculator(@NotNull GTRecipe recipe) { return super.createOverclockCalculator(recipe).setSpeedBoost(100.0 / (100 + 5 * mLevel)) - .setHeatOC(true) - .setRecipeHeat(0) - // Need to multiply by 2 because heat OC is done only once every 1800 and this one does it once - // every - // 900 - .setMachineHeat((int) (getCoilLevel().getHeat() * 2)); + .setRecipeHeat(0); } - }.setMaxParallelSupplier(this::getMaxParallelRecipes); + }.setHeatOC(true) + .setHeatDiscount(false) + // Requires doubling because heat OC is normally done every 1800 degrees, but this machine does it every + // 900. + .setMachineHeat((int) (getCoilLevel().getHeat() * 2)) + .setMaxParallelSupplier(this::getMaxParallelRecipes); } public HeatingCoilLevel getCoilLevel() { diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialCentrifuge.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialCentrifuge.java index 19895c83742..5e1b109cda1 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialCentrifuge.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialCentrifuge.java @@ -175,7 +175,7 @@ public RecipeMap getRecipeMap() { @Override protected ProcessingLogic createProcessingLogic() { - return new ProcessingLogic().setEuModifier(0.9F) + return new ProcessingLogic().setEUtModifier(0.9F) .setSpeedBonus(1F / 2.25F) .setMaxParallelSupplier(this::getMaxParallelRecipes); } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialChisel.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialChisel.java index bffce15245f..d0577a8a0a0 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialChisel.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialChisel.java @@ -294,7 +294,7 @@ protected Stream findRecipeMatches(@Nullable RecipeMap map) { return GTStreamUtil.ofNullable(getRecipe()); } }.setSpeedBonus(1F / 3F) - .setEuModifier(0.75F) + .setEUtModifier(0.75F) .setMaxParallelSupplier(this::getMaxParallelRecipes); } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialCokeOven.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialCokeOven.java index e7aab5d0f72..c8f71bb5fbe 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialCokeOven.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialCokeOven.java @@ -191,7 +191,7 @@ protected ProcessingLogic createProcessingLogic() { @Override protected void setupProcessingLogic(ProcessingLogic logic) { super.setupProcessingLogic(logic); - logic.setEuModifier((100F - (GTUtility.getTier(getMaxInputVoltage()) * 4)) / 100F); + logic.setEUtModifier((100F - (GTUtility.getTier(getMaxInputVoltage()) * 4)) / 100F); } @Override diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialCuttingMachine.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialCuttingMachine.java index 907c895770e..e1e42b6d964 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialCuttingMachine.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialCuttingMachine.java @@ -184,7 +184,7 @@ public int getRecipeCatalystPriority() { @Override protected ProcessingLogic createProcessingLogic() { return new ProcessingLogic().setSpeedBonus(1F / 3F) - .setEuModifier(0.75F) + .setEUtModifier(0.75F) .setMaxParallelSupplier(this::getMaxParallelRecipes); } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialDehydrator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialDehydrator.java index 7d2eac943de..39a17594a47 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialDehydrator.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialDehydrator.java @@ -48,7 +48,6 @@ import gregtech.api.recipe.check.CheckRecipeResultRegistry; import gregtech.api.util.GTRecipe; import gregtech.api.util.MultiblockTooltipBuilder; -import gregtech.api.util.OverclockCalculator; import gregtech.common.pollution.PollutionConfig; import gtPlusPlus.api.recipe.GTPPRecipeMaps; import gtPlusPlus.core.block.ModBlocks; @@ -222,17 +221,12 @@ protected CheckRecipeResult validateRecipe(@NotNull GTRecipe recipe) { return recipe.mSpecialValue <= getCoilLevel().getHeat() ? CheckRecipeResultRegistry.SUCCESSFUL : CheckRecipeResultRegistry.insufficientHeat(recipe.mSpecialValue); } - - @NotNull - @Override - protected OverclockCalculator createOverclockCalculator(@NotNull GTRecipe recipe) { - return super.createOverclockCalculator(recipe).setHeatOC(true) - .setHeatDiscount(true) - .setRecipeHeat(recipe.mSpecialValue) - .setMachineHeat((int) getCoilLevel().getHeat()); - } - }.setSpeedBonus(1F / 2.2F) - .setEuModifier(0.5F) + }.setHeatOC(true) + .setHeatDiscount(true) + .setHeatDiscountMultiplier(0.95) + .setMachineHeat((int) getCoilLevel().getHeat()) + .setSpeedBonus(1F / 2.2F) + .setEUtModifier(0.5F) .setMaxParallelSupplier(this::getMaxParallelRecipes); } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialFluidHeater.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialFluidHeater.java index 5766a973142..58b1d4a04dd 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialFluidHeater.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialFluidHeater.java @@ -166,7 +166,7 @@ public RecipeMap getRecipeMap() { @Override protected ProcessingLogic createProcessingLogic() { return new ProcessingLogic().setSpeedBonus(1F / 2.2F) - .setEuModifier(0.9F) + .setEUtModifier(0.9F) .setMaxParallelSupplier(this::getMaxParallelRecipes); } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialMultiMachine.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialMultiMachine.java index f8117df4802..c6055ee0e65 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialMultiMachine.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialMultiMachine.java @@ -346,7 +346,7 @@ protected CheckRecipeResult validateRecipe(@NotNull GTRecipe recipe) { return super.validateRecipe(recipe); } }.setSpeedBonus(1F / 3.5F) - .setEuModifier(0.8F) + .setEUtModifier(0.8F) .setMaxParallelSupplier(this::getMaxParallelRecipes); } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialSifter.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialSifter.java index fca1e1d16f1..3c0c50b4c92 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialSifter.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialSifter.java @@ -188,7 +188,7 @@ public void onPreTick(final IGregTechTileEntity aBaseMetaTileEntity, final long @Override protected ProcessingLogic createProcessingLogic() { return new ProcessingLogic().setSpeedBonus(1F / 5F) - .setEuModifier(0.75F) + .setEUtModifier(0.75F) .setMaxParallelSupplier(this::getMaxParallelRecipes); } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialThermalCentrifuge.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialThermalCentrifuge.java index 5b69b59a50b..5f1914f7df1 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialThermalCentrifuge.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialThermalCentrifuge.java @@ -156,7 +156,7 @@ public RecipeMap getRecipeMap() { @Override protected ProcessingLogic createProcessingLogic() { return new ProcessingLogic().setSpeedBonus(1F / 2.5F) - .setEuModifier(0.8F) + .setEUtModifier(0.8F) .setMaxParallelSupplier(this::getMaxParallelRecipes); } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialWireMill.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialWireMill.java index da6ace66776..e04d7eaf4d1 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialWireMill.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialWireMill.java @@ -161,7 +161,7 @@ public int getRecipeCatalystPriority() { @Override protected ProcessingLogic createProcessingLogic() { return new ProcessingLogic().setSpeedBonus(1F / 3F) - .setEuModifier(0.75F) + .setEUtModifier(0.75F) .setMaxParallelSupplier(this::getMaxParallelRecipes); } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIsaMill.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIsaMill.java index f09d57236ba..00a0782aedf 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIsaMill.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIsaMill.java @@ -519,6 +519,6 @@ public CheckRecipeResult process() { } return result; } - }.enablePerfectOverclock(); + }.setPerfectOverclock(); } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTESpargeTower.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTESpargeTower.java index f9a4f39e87b..37543d4f04a 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTESpargeTower.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTESpargeTower.java @@ -41,7 +41,7 @@ import gregtech.api.recipe.RecipeMap; import gregtech.api.util.GTRecipe; import gregtech.api.util.MultiblockTooltipBuilder; -import gregtech.api.util.ParallelHelper; +import gregtech.api.util.ProcessingHelper; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.recipe.GTPPRecipeMaps; import gtPlusPlus.core.block.ModBlocks; @@ -194,8 +194,8 @@ protected ProcessingLogic createProcessingLogic() { return new ProcessingLogic() { @Override - protected @NotNull ParallelHelper createParallelHelper(@NotNull GTRecipe recipe) { - return super.createParallelHelper(modifyRecipe(recipe)); + protected @NotNull ProcessingHelper createProcessingHelper(@NotNull GTRecipe recipe) { + return super.createProcessingHelper(modifyRecipe(recipe)); } private GTRecipe modifyRecipe(GTRecipe recipe) { diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEndustrialElectrolyzer.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEndustrialElectrolyzer.java index 912cfb0cad3..a5e5e2f08dd 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEndustrialElectrolyzer.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEndustrialElectrolyzer.java @@ -149,7 +149,7 @@ public RecipeMap getRecipeMap() { @Override protected ProcessingLogic createProcessingLogic() { return new ProcessingLogic().setSpeedBonus(1F / 2.8F) - .setEuModifier(0.9F) + .setEUtModifier(0.9F) .setMaxParallelSupplier(this::getMaxParallelRecipes); } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/MTEAdvDistillationTower.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/MTEAdvDistillationTower.java index 3719d02bd17..a866e6c19bd 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/MTEAdvDistillationTower.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/MTEAdvDistillationTower.java @@ -391,7 +391,7 @@ protected ProcessingLogic createProcessingLogic() { @Override protected void setupProcessingLogic(ProcessingLogic logic) { super.setupProcessingLogic(logic); - logic.setEuModifier(mMode == Mode.Distillery ? 0.15F : 1F); + logic.setEUtModifier(mMode == Mode.Distillery ? 0.15F : 1F); logic.setSpeedBonus(mMode == Mode.Distillery ? 1F / 2F : 1F / 3.5F); } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/MTEAdvEBF.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/MTEAdvEBF.java index 71f84c4ea29..e9238b380d1 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/MTEAdvEBF.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/MTEAdvEBF.java @@ -49,7 +49,6 @@ import gregtech.api.util.GTRecipe; import gregtech.api.util.GTUtility; import gregtech.api.util.MultiblockTooltipBuilder; -import gregtech.api.util.OverclockCalculator; import gregtech.api.util.shutdown.ShutDownReasonRegistry; import gregtech.common.pollution.PollutionConfig; import gtPlusPlus.core.block.ModBlocks; @@ -245,17 +244,10 @@ protected CheckRecipeResult validateRecipe(@NotNull GTRecipe recipe) { return recipe.mSpecialValue <= getCoilLevel().getHeat() ? CheckRecipeResultRegistry.SUCCESSFUL : CheckRecipeResultRegistry.insufficientHeat(recipe.mSpecialValue); } - - @NotNull - @Override - protected OverclockCalculator createOverclockCalculator(@NotNull GTRecipe recipe) { - return super.createOverclockCalculator(recipe).setHeatOC(true) - .setHeatDiscount(true) - .setRecipeHeat(recipe.mSpecialValue) - .setMachineHeat((int) getCoilLevel().getHeat()); - } - }.setSpeedBonus(1F / 2.2F) - .setEuModifier(0.9F) + }.setHeatOC(true) + .setHeatDiscount(true) + .setSpeedBonus(1F / 2.2F) + .setEUtModifier(0.9F) .setMaxParallelSupplier(this::getMaxParallelRecipes); } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/MTEAdvFusionMk4.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/MTEAdvFusionMk4.java index aa6e66c9ca8..ba455bb4554 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/MTEAdvFusionMk4.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/MTEAdvFusionMk4.java @@ -106,7 +106,7 @@ public int getFusionCoilMeta() { @Override protected ProcessingLogic createProcessingLogic() { - return super.createProcessingLogic().enablePerfectOverclock(); + return super.createProcessingLogic().setPerfectOverclock(); } @Override diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/MTEAdvFusionMk5.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/MTEAdvFusionMk5.java index 90946f54401..c375fad3e76 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/MTEAdvFusionMk5.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/MTEAdvFusionMk5.java @@ -106,7 +106,7 @@ public int getFusionCoilMeta() { @Override protected ProcessingLogic createProcessingLogic() { - return super.createProcessingLogic().enablePerfectOverclock(); + return super.createProcessingLogic().setPerfectOverclock(); } @Override diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEElementalDuplicator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEElementalDuplicator.java index 5a6392785c5..b6dd4b31a84 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEElementalDuplicator.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEElementalDuplicator.java @@ -297,7 +297,7 @@ public boolean isCorrectMachinePart(final ItemStack aStack) { @Override protected ProcessingLogic createProcessingLogic() { return new ProcessingLogic().setSpeedBonus(1F / 2F) - .enablePerfectOverclock() + .setPerfectOverclock() .setMaxParallelSupplier(this::getMaxParallelRecipes); } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEFrothFlotationCell.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEFrothFlotationCell.java index b7963b6cc94..5153ec16a44 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEFrothFlotationCell.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEFrothFlotationCell.java @@ -233,7 +233,7 @@ protected CheckRecipeResult validateRecipe(@NotNull GTRecipe recipe) { } return CheckRecipeResultRegistry.SUCCESSFUL; } - }.enablePerfectOverclock(); + }.setPerfectOverclock(); } /* diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEIndustrialFishingPond.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEIndustrialFishingPond.java index d61800b139f..adf012965fc 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEIndustrialFishingPond.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEIndustrialFishingPond.java @@ -45,7 +45,7 @@ import gregtech.api.util.GTUtility; import gregtech.api.util.MultiblockTooltipBuilder; import gregtech.api.util.OverclockCalculator; -import gregtech.api.util.ParallelHelper; +import gregtech.api.util.ProcessingHelper; import gregtech.api.util.ReflectionUtil; import gregtech.common.pollution.PollutionConfig; import gtPlusPlus.api.recipe.GTPPRecipeMaps; @@ -251,16 +251,16 @@ protected boolean filtersFluid() { OverclockCalculator calculator = new OverclockCalculator().setRecipeEUt(g.mEUt) .setEUt(tEnergy) .setDuration(g.mDuration); - ParallelHelper helper = new ParallelHelper().setRecipe(g) + ProcessingHelper helper = new ProcessingHelper().setRecipe(g) .setItemInputs(tItemInputs) .setFluidInputs(tFluidInputs) .setAvailableEUt(tEnergy) - .setMaxParallel(getMaxParallelRecipes()) + .setMaxParallels(getMaxParallelRecipes()) .setConsumption(true) .setOutputCalculation(true) .setMachine(this) - .enableBatchMode(batchMode ? 128 : 1) - .setCalculator(calculator); + .setBatchMode(batchMode) + .setBatchModifier(128); helper.build(); diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEIndustrialRockBreaker.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEIndustrialRockBreaker.java index 79c445e1978..8ffbca6d216 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEIndustrialRockBreaker.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEIndustrialRockBreaker.java @@ -213,7 +213,7 @@ protected CheckRecipeResult validateRecipe(@NotNull GTRecipe recipe) { return CheckRecipeResultRegistry.SUCCESSFUL; } }.setSpeedBonus(1 / 3.0) - .setEuModifier(0.75) + .setEUtModifier(0.75) .setMaxParallelSupplier(this::getMaxParallelRecipes); } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEMassFabricator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEMassFabricator.java index 9ac356b7078..f2e43a7e86f 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEMassFabricator.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEMassFabricator.java @@ -305,14 +305,14 @@ protected Stream findRecipeMatches(@Nullable RecipeMap map) { } return super.findRecipeMatches(map); } - }.setEuModifier(0.8F) + }.setEUtModifier(0.8F) .setMaxParallelSupplier(this::getMaxParallelRecipes); } @Override protected void setupProcessingLogic(ProcessingLogic logic) { super.setupProcessingLogic(logic); - logic.enablePerfectOverclock(); + logic.setPerfectOverclock(); } @Override diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEQuantumForceTransformer.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEQuantumForceTransformer.java index 2b44ec03e2e..1a7d4f71ae5 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEQuantumForceTransformer.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEQuantumForceTransformer.java @@ -15,9 +15,9 @@ import static gregtech.api.util.GTRecipeBuilder.BUCKETS; import static gregtech.api.util.GTRecipeBuilder.INGOTS; import static gregtech.api.util.GTStructureUtility.buildHatchAdder; -import static gregtech.api.util.ParallelHelper.addFluidsLong; -import static gregtech.api.util.ParallelHelper.addItemsLong; -import static gregtech.api.util.ParallelHelper.calculateChancedOutputMultiplier; +import static gregtech.api.util.ProcessingHelper.addFluidsLong; +import static gregtech.api.util.ProcessingHelper.addItemsLong; +import static gregtech.api.util.ProcessingHelper.calculateChancedOutputMultiplier; import java.util.ArrayList; import java.util.Arrays; @@ -75,7 +75,7 @@ import gregtech.api.util.GTUtility; import gregtech.api.util.IGTHatchAdder; import gregtech.api.util.MultiblockTooltipBuilder; -import gregtech.api.util.ParallelHelper; +import gregtech.api.util.ProcessingHelper; import gtPlusPlus.api.recipe.GTPPRecipeMaps; import gtPlusPlus.core.block.ModBlocks; import gtPlusPlus.core.material.MaterialsElements; @@ -438,8 +438,8 @@ protected CheckRecipeResult validateRecipe(@NotNull GTRecipe recipe) { @NotNull @Override - public ParallelHelper createParallelHelper(@Nonnull GTRecipe recipe) { - return super.createParallelHelper(recipe).setCustomItemOutputCalculation(parallel -> { + public ProcessingHelper createProcessingHelper(@Nonnull GTRecipe recipe) { + return super.createProcessingHelper(recipe).setCustomItemOutputCalculation(parallel -> { ArrayList items = new ArrayList<>(); for (int i = 0; i < recipe.mOutputs.length; i++) { diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEThermalBoiler.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEThermalBoiler.java index 9c92bb24c76..ef12251e034 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEThermalBoiler.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEThermalBoiler.java @@ -42,7 +42,7 @@ import gregtech.api.util.GTLog; import gregtech.api.util.GTRecipe; import gregtech.api.util.MultiblockTooltipBuilder; -import gregtech.api.util.ParallelHelper; +import gregtech.api.util.ProcessingHelper; import gregtech.common.pollution.PollutionConfig; import gtPlusPlus.api.recipe.GTPPRecipeMaps; import gtPlusPlus.core.block.ModBlocks; @@ -134,7 +134,7 @@ protected Stream findRecipeMatches(@Nullable RecipeMap map) { @NotNull @Override - protected ParallelHelper createParallelHelper(@Nonnull GTRecipe recipe) { + protected ProcessingHelper createProcessingHelper(@Nonnull GTRecipe recipe) { GTRecipe adjustedRecipe = recipe.copy(); // Hack the recipe logic to not consume water, so that we can explode. @@ -154,7 +154,7 @@ protected ParallelHelper createParallelHelper(@Nonnull GTRecipe recipe) { } } } - return super.createParallelHelper(adjustedRecipe); + return super.createProcessingHelper(adjustedRecipe); } }; } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTETreeFarm.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTETreeFarm.java index 85849832d4c..ef18d8b0a93 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTETreeFarm.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTETreeFarm.java @@ -375,7 +375,7 @@ public CheckRecipeResult process() { } duration = TICKS_PER_OPERATION; - calculatedEut = GTValues.VP[tier]; + calculatedEUt = GTValues.VP[tier]; for (Mode mode : MODE_VALUES) { if (outputPerMode.get(mode) != null) { diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/MTEAlgaePondBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/MTEAlgaePondBase.java index 3f22b85c59d..0f0d631e491 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/MTEAlgaePondBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/MTEAlgaePondBase.java @@ -358,7 +358,7 @@ protected CheckRecipeResult validateRecipe(@NotNull GTRecipe recipe) { } return CheckRecipeResultRegistry.SUCCESSFUL; } - }.setEuModifier(0F) + }.setEUtModifier(0F) .setMaxParallelSupplier(this::getMaxParallelRecipes); } diff --git a/src/main/java/tectech/thing/metaTileEntity/multi/MTEEyeOfHarmony.java b/src/main/java/tectech/thing/metaTileEntity/multi/MTEEyeOfHarmony.java index ea1f38a0d2a..eb41997bfa0 100644 --- a/src/main/java/tectech/thing/metaTileEntity/multi/MTEEyeOfHarmony.java +++ b/src/main/java/tectech/thing/metaTileEntity/multi/MTEEyeOfHarmony.java @@ -10,7 +10,7 @@ import static gregtech.api.enums.HatchElement.OutputHatch; import static gregtech.api.util.GTStructureUtility.buildHatchAdder; import static gregtech.api.util.GTUtility.formatNumbers; -import static gregtech.api.util.ParallelHelper.calculateChancedOutputMultiplier; +import static gregtech.api.util.ProcessingHelper.calculateChancedOutputMultiplier; import static gregtech.common.misc.WirelessNetworkManager.addEUToGlobalEnergyMap; import static gregtech.common.misc.WirelessNetworkManager.strongCheckOrAddUser; import static java.lang.Math.exp; diff --git a/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTEExoticModule.java b/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTEExoticModule.java index 71e68ae91b7..b4be1da2db7 100644 --- a/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTEExoticModule.java +++ b/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTEExoticModule.java @@ -171,7 +171,7 @@ protected CheckRecipeResult validateRecipe(@NotNull GTRecipe recipe) { @NotNull @Override protected CheckRecipeResult onRecipeStart(@NotNull GTRecipe recipe) { - EUt = calculatedEut; + EUt = calculatedEUt; powerForRecipe = BigInteger.valueOf(EUt) .multiply(BigInteger.valueOf(duration * actualParallel)); @@ -203,7 +203,7 @@ protected void setProcessingLogicPower(ProcessingLogic logic) { logic.setAvailableAmperage(Integer.MAX_VALUE); logic.setAmperageOC(false); logic.setSpeedBonus(getSpeedBonus()); - logic.setEuModifier(getEnergyDiscount()); + logic.setEUtModifier(getEnergyDiscount()); } @Override diff --git a/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTEMoltenModule.java b/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTEMoltenModule.java index a7080a4fe1a..393762725c7 100644 --- a/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTEMoltenModule.java +++ b/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTEMoltenModule.java @@ -73,8 +73,6 @@ protected CheckRecipeResult validateRecipe(@NotNull GTRecipe recipe) { protected OverclockCalculator createOverclockCalculator(@NotNull GTRecipe recipe) { return super.createOverclockCalculator(recipe).setEUt(getProcessingVoltage()) .setRecipeHeat(recipe.mSpecialValue) - .setHeatOC(true) - .setHeatDiscount(true) .setMachineHeat(Math.max(recipe.mSpecialValue, getHeatForOC())) .setHeatDiscountMultiplier(getHeatEnergyDiscount()) .setDurationDecreasePerOC(getOverclockTimeFactor()); @@ -84,19 +82,21 @@ protected OverclockCalculator createOverclockCalculator(@NotNull GTRecipe recipe @NotNull @Override protected CheckRecipeResult onRecipeStart(@NotNull GTRecipe recipe) { - if (!addEUToGlobalEnergyMap(userUUID, -calculatedEut * duration)) { - return CheckRecipeResultRegistry.insufficientPower(calculatedEut * duration); + if (!addEUToGlobalEnergyMap(userUUID, -calculatedEUt * duration)) { + return CheckRecipeResultRegistry.insufficientPower(calculatedEUt * duration); } addToPowerTally( - BigInteger.valueOf(calculatedEut) + BigInteger.valueOf(calculatedEUt) .multiply(BigInteger.valueOf(duration))); addToRecipeTally(calculatedParallels); currentParallel = calculatedParallels; - EUt = calculatedEut; + EUt = calculatedEUt; overwriteCalculatedEut(0); return CheckRecipeResultRegistry.SUCCESSFUL; } - }; + }.setHeatOC(true) + .setHeatDiscount(true) + .setHeatDiscountMultiplier(0.95); } @Override @@ -106,7 +106,7 @@ protected void setProcessingLogicPower(ProcessingLogic logic) { logic.setAmperageOC(false); logic.setMaxParallel(getMaxParallel()); logic.setSpeedBonus(getSpeedBonus()); - logic.setEuModifier(getEnergyDiscount()); + logic.setEUtModifier(getEnergyDiscount()); } @Override diff --git a/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTEPlasmaModule.java b/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTEPlasmaModule.java index 48a4388048f..dddaec84a01 100644 --- a/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTEPlasmaModule.java +++ b/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTEPlasmaModule.java @@ -91,15 +91,15 @@ protected CheckRecipeResult validateRecipe(@NotNull GTRecipe recipe) { @Override protected CheckRecipeResult onRecipeStart(@NotNull GTRecipe recipe) { wirelessEUt = (long) recipe.mEUt * maxParallel; - if (!addEUToGlobalEnergyMap(userUUID, -calculatedEut * duration)) { + if (!addEUToGlobalEnergyMap(userUUID, -calculatedEUt * duration)) { return CheckRecipeResultRegistry.insufficientPower(wirelessEUt * recipe.mDuration); } addToPowerTally( - BigInteger.valueOf(calculatedEut) + BigInteger.valueOf(calculatedEUt) .multiply(BigInteger.valueOf(duration))); addToRecipeTally(calculatedParallels); currentParallel = calculatedParallels; - EUt = calculatedEut; + EUt = calculatedEUt; overwriteCalculatedEut(0); return CheckRecipeResultRegistry.SUCCESSFUL; } @@ -120,7 +120,7 @@ protected void setProcessingLogicPower(ProcessingLogic logic) { logic.setAmperageOC(false); logic.setMaxParallel(getMaxParallel()); logic.setSpeedBonus(getSpeedBonus()); - logic.setEuModifier(getEnergyDiscount()); + logic.setEUtModifier(getEnergyDiscount()); } @Override diff --git a/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTESmeltingModule.java b/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTESmeltingModule.java index c1bd1502eb3..c37e2e0dbef 100644 --- a/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTESmeltingModule.java +++ b/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTESmeltingModule.java @@ -107,17 +107,17 @@ protected CheckRecipeResult validateRecipe(@NotNull GTRecipe recipe) { @NotNull @Override protected CheckRecipeResult onRecipeStart(@NotNull GTRecipe recipe) { - if (!addEUToGlobalEnergyMap(userUUID, -calculatedEut * duration)) { - return CheckRecipeResultRegistry.insufficientPower(calculatedEut * duration); + if (!addEUToGlobalEnergyMap(userUUID, -calculatedEUt * duration)) { + return CheckRecipeResultRegistry.insufficientPower(calculatedEUt * duration); } addToPowerTally( - BigInteger.valueOf(calculatedEut) + BigInteger.valueOf(calculatedEUt) .multiply(BigInteger.valueOf(duration))); if (!furnaceMode) { addToRecipeTally(calculatedParallels); } currentParallel = calculatedParallels; - EUt = calculatedEut; + EUt = calculatedEUt; overwriteCalculatedEut(0); return CheckRecipeResultRegistry.SUCCESSFUL; } @@ -127,13 +127,13 @@ protected CheckRecipeResult onRecipeStart(@NotNull GTRecipe recipe) { protected OverclockCalculator createOverclockCalculator(@NotNull GTRecipe recipe) { return super.createOverclockCalculator(recipe).setEUt(getProcessingVoltage()) .setRecipeHeat(recipe.mSpecialValue) - .setHeatOC(true) - .setHeatDiscount(true) - .setMachineHeat(Math.max(recipe.mSpecialValue, getHeatForOC())) + .setMachineHeat(Math.max(recipe.mSpecialValue, getHeatForOC())) // TODO .setHeatDiscountMultiplier(getHeatEnergyDiscount()) .setDurationDecreasePerOC(getOverclockTimeFactor()); } - }; + }.setHeatOC(true) + .setHeatDiscount(true) + .setHeatDiscountMultiplier(0.95); } @Override @@ -143,7 +143,7 @@ protected void setProcessingLogicPower(ProcessingLogic logic) { logic.setAmperageOC(false); logic.setMaxParallel(getMaxParallel()); logic.setSpeedBonus(getSpeedBonus()); - logic.setEuModifier(getEnergyDiscount()); + logic.setEUtModifier(getEnergyDiscount()); } @Override