Skip to content

Commit

Permalink
fix ECE oxygen boosting (#2211)
Browse files Browse the repository at this point in the history
  • Loading branch information
screret committed Dec 5, 2024
1 parent 5960949 commit a2d2f82
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ public Builder addMufflerObstructedLine(boolean isObstructed) {
* Added if structure is formed, the machine is active, and the passed fuelName parameter is not null.
*/
public Builder addFuelNeededLine(String fuelName, int previousRecipeDuration) {
if (!isStructureFormed || !isActive)
if (!isStructureFormed || !isActive || fuelName == null)
return this;
Component fuelNeeded = Component.literal(fuelName).withStyle(ChatFormatting.RED);
Component numTicks = Component.literal(FormattingUtil.formatNumbers(previousRecipeDuration))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public enum Status {
@Nullable
@Getter
@Persisted
@DescSynced
protected GTRecipe lastRecipe;
/**
* safe, it is the original recipe before
Expand Down Expand Up @@ -285,7 +286,7 @@ protected void doDamping() {
}
}

protected Iterator<GTRecipe> searchRecipe() {
public Iterator<GTRecipe> searchRecipe() {
return machine.getRecipeType().searchRecipe(this.machine);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public ResearchStationMachine getMachine() {
// Custom recipe matching logic to override output space test
@Nullable
@Override
protected Iterator<GTRecipe> searchRecipe() {
public Iterator<GTRecipe> searchRecipe() {
IRecipeCapabilityHolder holder = this.machine;
if (!holder.hasProxies()) return null;
var iterator = machine.getRecipeType().getLookup().getRecipeIterator(holder, recipe -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@
import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
import com.gregtechceu.gtceu.api.machine.MetaMachine;
import com.gregtechceu.gtceu.api.machine.feature.ITieredMachine;
import com.gregtechceu.gtceu.api.machine.multiblock.MultiblockDisplayText;
import com.gregtechceu.gtceu.api.machine.multiblock.WorkableElectricMultiblockMachine;
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.logic.OCParams;
import com.gregtechceu.gtceu.api.recipe.logic.OCResult;
import com.gregtechceu.gtceu.data.material.GTMaterials;
import com.gregtechceu.gtceu.data.recipe.GTRecipeModifiers;
import com.gregtechceu.gtceu.data.recipe.builder.GTRecipeBuilder;
import com.gregtechceu.gtceu.utils.FormattingUtil;

import com.lowdragmc.lowdraglib.syncdata.annotation.DescSynced;
import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder;

import net.minecraft.ChatFormatting;
import net.minecraft.MethodsReturnNonnullByDefault;
Expand All @@ -25,11 +31,13 @@
import net.minecraft.network.chat.Style;
import net.neoforged.neoforge.fluids.FluidStack;

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

import java.util.Iterator;
import java.util.List;

import javax.annotation.ParametersAreNonnullByDefault;
Expand All @@ -43,13 +51,17 @@
@MethodsReturnNonnullByDefault
public class LargeCombustionEngineMachine extends WorkableElectricMultiblockMachine implements ITieredMachine {

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 LUBRICANT_STACK = GTMaterials.Lubricant.getFluid(1);

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

public LargeCombustionEngineMachine(IMachineBlockEntity holder, int tier) {
Expand Down Expand Up @@ -112,14 +124,14 @@ public static GTRecipe recipeModifier(MetaMachine machine, @NotNull GTRecipe rec
if (EUt > 0 && engineMachine.getLubricantRecipe().matchRecipe(engineMachine).isSuccess() &&
!engineMachine.isIntakesObstructed()) {
var maxParallel = (int) (engineMachine.getOverclockVoltage() / EUt); // get maximum parallel
var parallelResult = GTRecipeModifiers.fastParallel(engineMachine, recipe, maxParallel, false);
var parallelResult = GTRecipeModifiers.accurateParallel(engineMachine, recipe, maxParallel, false);
long eut;
if (engineMachine.isOxygenBoosted) { // boost production
long eut = (long) (EUt * parallelResult.getSecond() * (engineMachine.isExtreme() ? 2 : 1.5));
result.init(-eut, recipe.duration, 1, params.getOcAmount());
eut = (long) (EUt * parallelResult.getSecond() * (engineMachine.isExtreme() ? 2 : 1.5));
} else {
long eut = EUt * parallelResult.getSecond();
result.init(-eut, recipe.duration, 1, params.getOcAmount());
eut = EUt * parallelResult.getSecond();
}
result.init(-eut, recipe.duration, 1, params.getOcAmount());
return recipe;
}
}
Expand Down Expand Up @@ -158,29 +170,41 @@ public boolean dampingWhenWaiting() {

@Override
public void addDisplayText(List<Component> textList) {
super.addDisplayText(textList);
if (isFormed()) {
if (isBoostAllowed()) {
if (!isExtreme()) {
if (isOxygenBoosted) {
textList.add(Component.translatable("gtceu.multiblock.large_combustion_engine.oxygen_boosted"));
} else {
textList.add(Component
.translatable("gtceu.multiblock.large_combustion_engine.supply_oxygen_to_boost"));
}
} else {
if (isOxygenBoosted) {
textList.add(Component
.translatable("gtceu.multiblock.large_combustion_engine.liquid_oxygen_boosted"));
} else {
textList.add(Component.translatable(
"gtceu.multiblock.large_combustion_engine.supply_liquid_oxygen_to_boost"));
MultiblockDisplayText.Builder builder = MultiblockDisplayText.builder(textList, isFormed())
.setWorkingStatus(recipeLogic.isWorkingEnabled(), recipeLogic.isActive());

if (isExtreme()) {
builder.addEnergyProductionLine(GTValues.V[tier + 1],
recipeLogic.getLastRecipe() != null ? RecipeHelper.getOutputEUt(recipeLogic.getLastRecipe()) : 0);
} else {
builder.addEnergyProductionAmpsLine(GTValues.V[tier] * 3, 3);
}

builder.addFuelNeededLine(getRecipeFluidInputInfo(), recipeLogic.getDuration())
.addCustom(tl -> {
if (isFormed() && isOxygenBoosted) {
String key = isExtreme() ? "gtceu.multiblock.large_combustion_engine.liquid_oxygen_boosted" :
"gtceu.multiblock.large_combustion_engine.oxygen_boosted";
tl.add(Component.translatable(key).withStyle(ChatFormatting.AQUA));
}
}
} else {
textList.add(Component.translatable("gtceu.multiblock.large_combustion_engine.boost_disallowed"));
}
})
.addWorkingStatusLine();
}

@Nullable
public String getRecipeFluidInputInfo() {
// Previous Recipe is always null on first world load, so try to acquire a new recipe
GTRecipe recipe = recipeLogic.getLastRecipe();
if (recipe == null) {
Iterator<GTRecipe> iterator = recipeLogic.searchRecipe();
recipe = iterator != null && iterator.hasNext() ? iterator.next() : null;
if (recipe == null) return null;
}
FluidStack requiredFluidInput = RecipeHelper.getInputFluids(recipe).get(0);

int ocAmount = Ints.saturatedCast(getMaxVoltage() / RecipeHelper.getOutputEUt(recipe));
int neededAmount = (int) (ocAmount * requiredFluidInput.getAmount());
return ChatFormatting.RED + FormattingUtil.formatNumbers(neededAmount) + "mB";
}

@Override
Expand All @@ -193,4 +217,9 @@ public void attachTooltips(TooltipsPanel tooltipsPanel) {
this::isIntakesObstructed,
() -> null));
}

@Override
public ManagedFieldHolder getFieldHolder() {
return MANAGED_FIELD_HOLDER;
}
}

0 comments on commit a2d2f82

Please sign in to comment.