Skip to content

Commit

Permalink
More work
Browse files Browse the repository at this point in the history
A lot of machines still require setters for their ProcessingLogic.
  • Loading branch information
Julia Dijkstra committed Jan 30, 2025
1 parent 40cc188 commit 0cc90da
Show file tree
Hide file tree
Showing 58 changed files with 320 additions and 209 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ protected CheckRecipeResult validateRecipe(@NotNull GTRecipe recipe) {
protected ProcessingHelper createProcessingHelper(@NotNull GTRecipe recipe) {
return super.createProcessingHelper(recipeWithMultiplier(recipe, inputFluids));
}
};
}.setOverclock(true);
}

protected GTRecipe recipeWithMultiplier(GTRecipe recipe, FluidStack[] fluidInputs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ public Collection<RecipeMap<?>> getAvailableRecipeMaps() {
@Override
protected ProcessingLogic createProcessingLogic() {
return new ProcessingLogic() {

@Override
@Nonnull
protected CheckRecipeResult validateRecipe(@Nonnull GTRecipe recipe) {
Expand All @@ -323,7 +322,8 @@ protected CheckRecipeResult validateRecipe(@Nonnull GTRecipe recipe) {
}
return CheckRecipeResultRegistry.SUCCESSFUL;
}
}.enablePerfectOverclock();
}.setOverclock(true)
.setPerfectOverclock();
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ protected ProcessingLogic createProcessingLogic() {
? CheckRecipeResultRegistry.SUCCESSFUL
: CheckRecipeResultRegistry.insufficientHeat(recipe.mSpecialValue);
}
}.setHeatOC(true)
}.setOverclock(true)
.setHeatOC(true)
.setHeatDiscount(true)
.setHeatDiscountMultiplier(0.95)
.setMachineHeat(MTEMegaBlastFurnace.this.mHeatingCapacity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -223,15 +220,10 @@ public RecipeMap<OilCrackerBackend> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,9 @@ public SubspaceCoolingFluid findSubspaceCoolingFluid() {
protected ProcessingLogic createProcessingLogic() {
currentCoolingFluid = findSubspaceCoolingFluid();

return new ProcessingLogic().setHeatOC(true)
return new ProcessingLogic()
.setOverclock(true)
.setHeatOC(true)
.setHeatDiscount(false)
.setMachineHeat(currentCoolingFluid == null ? 0 : currentCoolingFluid.perfectOverclocks * 1800)
.setMaxParallel(Configuration.Multiblocks.megaMachinesMax);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ protected OverclockCalculator createOverclockCalculator(@NotNull GTRecipe recipe
int overclockAmount = Tier - recipe.mSpecialValue;
return super.createOverclockCalculator(recipe).limitOverclockCount(overclockAmount);
}
}.enablePerfectOverclock();
}.setPerfectOverclock();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand All @@ -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
Expand Down
82 changes: 56 additions & 26 deletions src/main/java/gregtech/api/logic/ProcessingLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -31,7 +32,6 @@
*/
@SuppressWarnings({ "unused", "UnusedReturnValue" })
public class ProcessingLogic {

// Traits
protected IVoidable machine;
protected IRecipeLockable recipeLockableMachine;
Expand All @@ -44,16 +44,22 @@ public class ProcessingLogic {
protected Supplier<Integer> maxParallelSupplier;
protected int batchSize = 1;
protected Supplier<RecipeMap<?>> 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<GTRecipe, Double> durationSupplier;

// Overclock related parameters
protected boolean overclock;
protected Function<Integer, Double> ocEUtModifierSupplier;
protected Function<Integer, Double> ocDurationModifierSupplier;

// Heat related parameters
protected boolean heatOC;
protected boolean heatDiscount;
Expand All @@ -63,7 +69,7 @@ public class ProcessingLogic {
// Calculated results
protected ItemStack[] outputItems;
protected FluidStack[] outputFluids;
protected long calculatedEut;
protected long calculatedEUt;
protected int duration;
protected int calculatedParallels = 0;

Expand Down Expand Up @@ -179,8 +185,8 @@ public ProcessingLogic setRecipeMapSupplier(Supplier<RecipeMap<?>> supplier) {
return this;
}

public ProcessingLogic setEuModifier(double modifier) {
this.euModifier = modifier;
public ProcessingLogic setEUtModifier(double eutModifier) {
this.eutModifier = eutModifier;
return this;
}

Expand All @@ -189,6 +195,33 @@ public ProcessingLogic setSpeedBonus(double speedModifier) {
return this;
}

public ProcessingLogic setDurationSupplier(Function<GTRecipe, Double> durationSupplier) {
this.durationSupplier = durationSupplier;
return this;
}

public ProcessingLogic setOverclock(boolean overclock) {
this.overclock = overclock;
return this;
}

public ProcessingLogic setOCEUtModifierSupplier(Function<Integer, Double> ocEUtModifierSupplier) {
this.ocEUtModifierSupplier = ocEUtModifierSupplier;
return this;
}

public ProcessingLogic setOCDurationModifierSupplier(Function<Integer, Double> 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
Expand All @@ -214,11 +247,11 @@ public ProcessingLogic setVoidProtection(boolean protectItems, boolean protectFl
return this;
}

public ProcessingLogic setOverclock(double timeReduction, double powerIncrease) {
this.overClockTimeReduction = timeReduction;
this.overClockPowerIncrease = powerIncrease;
return this;
}
// public ProcessingLogic setOverclock(double timeReduction, double powerIncrease) {
// this.overClockTimeReduction = timeReduction;
// this.overClockPowerIncrease = powerIncrease;
// return this;
// }

public ProcessingLogic setHeatOC(boolean heatOC) {
this.heatOC = heatOC;
Expand All @@ -240,13 +273,6 @@ public ProcessingLogic setMachineHeat(int machineHeat) {
return this;
}

/**
* Sets overclock ratio to 4/4.
*/
public ProcessingLogic enablePerfectOverclock() {
return this.setOverclock(4.0, 4.0);
}

/**
* Sets whether the multi should use amperage to OC or not.
*/
Expand Down Expand Up @@ -279,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;
}

Expand All @@ -302,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;
Expand Down Expand Up @@ -435,7 +461,7 @@ private CheckRecipeResult applyRecipe(@Nonnull GTRecipe recipe, @Nonnull Process
return CheckRecipeResultRegistry.DURATION_OVERFLOW;
}

calculatedEut = calculator.getConsumption();
calculatedEUt = calculator.getConsumption();

double finalDuration = calculateDuration(recipe, helper, calculator);
if (finalDuration >= Integer.MAX_VALUE) {
Expand Down Expand Up @@ -502,7 +528,11 @@ protected ProcessingHelper createProcessingHelper(@Nonnull GTRecipe recipe) {
.setMachine(this.machine, this.protectItems, this.protectFluids)
.setRecipeLocked(this.recipeLockableMachine, this.isRecipeLocked)
.setMaxParallels(this.maxParallel)
.setEUtModifier(this.euModifier)
.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)
Expand Down Expand Up @@ -542,8 +572,8 @@ public int getDuration() {
return duration;
}

public long getCalculatedEut() {
return calculatedEut;
public long getCalculatedEUt() {
return calculatedEUt;
}

public int getCurrentParallels() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
Loading

0 comments on commit 0cc90da

Please sign in to comment.