Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ECE oxygen boosting #2211

Merged
merged 3 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,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 origin recipe before {@link IRecipeLogicMachine#fullModifyRecipe(GTRecipe, OCParams, OCResult)}'
Expand Down Expand Up @@ -284,7 +285,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
@@ -1,5 +1,6 @@
package com.gregtechceu.gtceu.common.machine.multiblock.generator;

import com.google.common.primitives.Ints;
import com.gregtechceu.gtceu.api.GTValues;
import com.gregtechceu.gtceu.api.capability.recipe.IO;
import com.gregtechceu.gtceu.api.fluids.store.FluidStorageKeys;
Expand All @@ -9,7 +10,11 @@
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.feature.multiblock.IRotorHolderMachine;
import com.gregtechceu.gtceu.api.machine.multiblock.MultiblockControllerMachine;
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;
Expand All @@ -18,8 +23,11 @@
import com.gregtechceu.gtceu.common.data.GTRecipeModifiers;
import com.gregtechceu.gtceu.data.recipe.builder.GTRecipeBuilder;

import com.gregtechceu.gtceu.utils.FormattingUtil;
import com.lowdragmc.lowdraglib.side.fluid.FluidStack;

import com.lowdragmc.lowdraglib.syncdata.annotation.DescSynced;
import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder;
import net.minecraft.ChatFormatting;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.Direction;
Expand All @@ -31,6 +39,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

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

import javax.annotation.ParametersAreNonnullByDefault;
Expand All @@ -44,13 +53,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 @@ -113,14 +126,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 = (long) (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 @@ -159,29 +172,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 @@ -194,4 +219,9 @@ public void attachTooltips(TooltipsPanel tooltipsPanel) {
this::isIntakesObstructed,
() -> null));
}

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