Skip to content

Commit

Permalink
Combustion Engine Logic Fixes (#2287)
Browse files Browse the repository at this point in the history
  • Loading branch information
YoungOnionMC authored Nov 7, 2024
1 parent 7d7bf54 commit c74f36d
Showing 1 changed file with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.gregtechceu.gtceu.api.machine.multiblock.WorkableMultiblockMachine;
import com.gregtechceu.gtceu.api.recipe.GTRecipe;
import com.gregtechceu.gtceu.api.recipe.RecipeHelper;
import com.gregtechceu.gtceu.api.recipe.content.ContentModifier;
import com.gregtechceu.gtceu.api.recipe.logic.OCParams;
import com.gregtechceu.gtceu.api.recipe.logic.OCResult;
import com.gregtechceu.gtceu.common.data.GTMaterials;
Expand All @@ -33,7 +34,6 @@

import com.google.common.primitives.Ints;
import lombok.Getter;
import lombok.val;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -54,15 +54,16 @@ public class LargeCombustionEngineMachine extends WorkableElectricMultiblockMach
protected static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(
LargeCombustionEngineMachine.class, WorkableMultiblockMachine.MANAGED_FIELD_HOLDER);

private static final FluidStack OXYGEN_STACK = GTMaterials.Oxygen.getFluid(20);
private static final FluidStack LIQUID_OXYGEN_STACK = GTMaterials.Oxygen.getFluid(FluidStorageKeys.LIQUID, 80);
private static final FluidStack OXYGEN_STACK = GTMaterials.Oxygen.getFluid(1);
private static final FluidStack LIQUID_OXYGEN_STACK = GTMaterials.Oxygen.getFluid(FluidStorageKeys.LIQUID, 4);
private static final FluidStack LUBRICANT_STACK = GTMaterials.Lubricant.getFluid(1);

@Getter
private final int tier;
// runtime
@DescSynced
private boolean isOxygenBoosted = false;
private int runningTimer = 0;

public LargeCombustionEngineMachine(IMachineBlockEntity holder, int tier) {
super(holder);
Expand Down Expand Up @@ -131,6 +132,14 @@ public static GTRecipe recipeModifier(MetaMachine machine, @NotNull GTRecipe rec
} else {
eut = EUt * parallelResult.getSecond();
}

recipe = new GTRecipe(recipe.recipeType, recipe.id,
recipe.copyContents(recipe.inputs, ContentModifier.multiplier(parallelResult.getSecond())),
recipe.copyContents(recipe.outputs, ContentModifier.multiplier(parallelResult.getSecond())),
recipe.tickInputs, recipe.tickOutputs, recipe.inputChanceLogics, recipe.outputChanceLogics,
recipe.tickInputChanceLogics, recipe.tickOutputChanceLogics, recipe.conditions,
recipe.ingredientActions, recipe.data, recipe.duration, recipe.isFuel, recipe.recipeCategory);

result.init(-eut, recipe.duration, 1, params.getOcAmount());
return recipe;
}
Expand All @@ -142,20 +151,24 @@ public static GTRecipe recipeModifier(MetaMachine machine, @NotNull GTRecipe rec
public boolean onWorking() {
boolean value = super.onWorking();
// check lubricant
val totalContinuousRunningTime = recipeLogic.getTotalContinuousRunningTime();
if ((totalContinuousRunningTime == 1 || totalContinuousRunningTime % 72 == 0)) {

if (runningTimer % 72 == 0) {
// insufficient lubricant
if (!getLubricantRecipe().handleRecipeIO(IO.IN, this, this.recipeLogic.getChanceCaches())) {
recipeLogic.interruptRecipe();
return false;
}
}
// check boost fluid
if ((totalContinuousRunningTime == 1 || totalContinuousRunningTime % 20 == 0) && isBoostAllowed()) {
if (isBoostAllowed()) {
var boosterRecipe = getBoostRecipe();
this.isOxygenBoosted = boosterRecipe.matchRecipe(this).isSuccess() &&
boosterRecipe.handleRecipeIO(IO.IN, this, this.recipeLogic.getChanceCaches());
}

runningTimer++;
if (runningTimer > 72000) runningTimer %= 72000; // reset once every hour of running

return value;
}

Expand Down

0 comments on commit c74f36d

Please sign in to comment.