Skip to content
Open
Changes from all commits
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 @@ -2,28 +2,35 @@

import com.gregtechceu.gtceu.api.GTValues;
import com.gregtechceu.gtceu.api.capability.recipe.*;
import com.gregtechceu.gtceu.api.gui.GuiTextures;
import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
import com.gregtechceu.gtceu.api.machine.MetaMachine;
import com.gregtechceu.gtceu.api.machine.TickableSubscription;
import com.gregtechceu.gtceu.api.machine.feature.IExplosionMachine;
import com.gregtechceu.gtceu.api.machine.feature.IMuiMachine;
import com.gregtechceu.gtceu.api.machine.feature.IRecipeLogicMachine;
import com.gregtechceu.gtceu.api.machine.feature.multiblock.IDisplayUIMachine;
import com.gregtechceu.gtceu.api.machine.multiblock.WorkableMultiblockMachine;
import com.gregtechceu.gtceu.api.machine.trait.RecipeLogic;
import com.gregtechceu.gtceu.api.mui.base.drawable.IKey;
import com.gregtechceu.gtceu.api.mui.factory.PosGuiData;
import com.gregtechceu.gtceu.api.mui.utils.Alignment;
import com.gregtechceu.gtceu.api.mui.value.sync.PanelSyncManager;
import com.gregtechceu.gtceu.api.mui.widget.ParentWidget;
import com.gregtechceu.gtceu.api.mui.widgets.ButtonWidget;
import com.gregtechceu.gtceu.api.mui.widgets.TextWidget;
import com.gregtechceu.gtceu.api.mui.widgets.layout.Flow;
import com.gregtechceu.gtceu.api.recipe.GTRecipe;
import com.gregtechceu.gtceu.api.recipe.ingredient.FluidIngredient;
import com.gregtechceu.gtceu.api.recipe.modifier.ModifierFunction;
import com.gregtechceu.gtceu.api.recipe.modifier.RecipeModifier;
import com.gregtechceu.gtceu.client.mui.screen.ModularPanel;
import com.gregtechceu.gtceu.client.mui.screen.UISettings;
import com.gregtechceu.gtceu.common.data.GTMaterials;
import com.gregtechceu.gtceu.common.data.mui.GTMuiWidgets;
import com.gregtechceu.gtceu.common.mui.GTGuiTextures;
import com.gregtechceu.gtceu.config.ConfigHolder;
import com.gregtechceu.gtceu.syncsystem.annotations.SaveField;
import com.gregtechceu.gtceu.syncsystem.annotations.SyncToClient;

import com.lowdragmc.lowdraglib.gui.texture.IGuiTexture;
import com.lowdragmc.lowdraglib.gui.util.ClickData;
import com.lowdragmc.lowdraglib.gui.widget.ComponentPanelWidget;

import net.minecraft.ChatFormatting;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.Direction;
Expand All @@ -35,6 +42,7 @@
import net.minecraft.util.Mth;
import net.minecraft.world.level.material.Fluids;

import com.mojang.blaze3d.platform.InputConstants;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -45,17 +53,22 @@

@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class LargeBoilerMachine extends WorkableMultiblockMachine implements IExplosionMachine, IDisplayUIMachine {
public class LargeBoilerMachine extends WorkableMultiblockMachine implements IExplosionMachine, IMuiMachine {

public static final int TICKS_PER_STEAM_GENERATION = 5;

@Getter
public final int maxTemperature, heatSpeed;
@SaveField
@Getter
private int currentTemperature, throttle;
@SyncToClient
private int currentTemperature;
@SaveField
@Getter
private int throttle;
@Nullable
protected TickableSubscription temperatureSubs;
@SyncToClient
private int steamGenerated;

public LargeBoilerMachine(IMachineBlockEntity holder, int maxTemperature, int heatSpeed, Object... args) {
Expand Down Expand Up @@ -118,17 +131,20 @@ protected void updateCurrentTemperature() {
if (getOffsetTimer() % 10 == 0) {
if (currentTemperature < getMaxTemperature()) {
currentTemperature = Mth.clamp(currentTemperature + heatSpeed * 10, 0, getMaxTemperature());
syncDataHolder.markClientSyncFieldDirty("currentTemperature");
}
}
} else if (currentTemperature > 0) {
currentTemperature -= getCoolDownRate();
syncDataHolder.markClientSyncFieldDirty("currentTemperature");
}

if (isFormed() && getOffsetTimer() % TICKS_PER_STEAM_GENERATION == 0) {
var maxDrain = currentTemperature * throttle * TICKS_PER_STEAM_GENERATION /
(ConfigHolder.INSTANCE.machines.largeBoilers.steamPerWater * 100);
if (currentTemperature < 100) {
steamGenerated = 0;
syncDataHolder.markClientSyncFieldDirty("steamGenerated");
} else if (maxDrain > 0) { // if maxDrain is 0 because throttle is too low, skip trying to make steam
// drain water
var drainWater = List.of(FluidIngredient.of(Fluids.WATER, maxDrain));
Expand All @@ -145,6 +161,7 @@ protected void updateCurrentTemperature() {
maxDrain - drainWater.get(0).getAmount();

steamGenerated = drained * ConfigHolder.INSTANCE.machines.largeBoilers.steamPerWater;
syncDataHolder.markClientSyncFieldDirty("steamGenerated");

if (drained > 0) {
// fill steam
Expand Down Expand Up @@ -187,6 +204,7 @@ public boolean onWorking() {
boolean value = super.onWorking();
if (currentTemperature < getMaxTemperature()) {
currentTemperature = Math.max(1, currentTemperature);
syncDataHolder.markClientSyncFieldDirty("currentTemperature");
updateSteamSubscription();
}
return value;
Expand All @@ -198,7 +216,7 @@ public boolean onWorking() {
* Does not modify recipe. Real recipe duration is determined by
* {@link LargeBoilerRecipeLogic#modifyFuelBurnTime(int)}
* </p>
*
*
* @param machine a {@link LargeBoilerMachine}
* @param recipe recipe
* @return A {@link ModifierFunction} for the given Large Boiler and recipe
Expand All @@ -208,10 +226,11 @@ public static ModifierFunction recipeModifier(@NotNull MetaMachine machine, @Not
}

public void addDisplayText(List<Component> textList) {
IDisplayUIMachine.super.addDisplayText(textList);
// IDisplayUIMachine.super.addDisplayText(textList);
Style STYLE_WHITE = Style.EMPTY.withColor(ChatFormatting.WHITE);
if (isFormed()) {
textList.add(Component.translatable("gtceu.multiblock.large_boiler.temperature",
currentTemperature + 274, maxTemperature + 274));
currentTemperature + 274, maxTemperature + 274).setStyle(STYLE_WHITE));
textList.add(Component.translatable("gtceu.multiblock.large_boiler.steam_output",
steamGenerated / TICKS_PER_STEAM_GENERATION));

Expand All @@ -220,27 +239,57 @@ public void addDisplayText(List<Component> textList) {
.withStyle(Style.EMPTY.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
Component.translatable("gtceu.multiblock.large_boiler.throttle.tooltip"))));
textList.add(throttleText);

var buttonText = Component.translatable("gtceu.multiblock.large_boiler.throttle_modify");
buttonText.append(" ");
buttonText.append(ComponentPanelWidget.withButton(Component.literal("[-]"), "sub"));
buttonText.append(" ");
buttonText.append(ComponentPanelWidget.withButton(Component.literal("[+]"), "add"));
textList.add(buttonText);
} else {
textList.add(Component.translatable("gtceu.multiblock.invalid_structure").setStyle(STYLE_WHITE));
}
}

public void handleDisplayClick(String componentData, ClickData clickData) {
if (!clickData.isRemote) {
int result = componentData.equals("add") ? 5 : -5;
this.throttle = Mth.clamp(throttle + result, 25, 100);
this.getRecipeLogic().modifyFuelBurnTime(this.throttle);
}
}

@Override
public IGuiTexture getScreenTexture() {
return GuiTextures.DISPLAY_STEAM.get(maxTemperature > 800);
public ModularPanel buildUI(PosGuiData data, PanelSyncManager syncManager, UISettings settings) {
return new ModularPanel(getDefinition().getName())
// size(200, 172)
.child(GTMuiWidgets.createTitleBar(getDefinition(), 176))
.bindPlayerInventory()
.child(Flow.row()
.coverChildrenHeight()
.margin(5)
.childPadding(5)
.child(Flow.column()
.crossAxisAlignment(Alignment.CrossAxis.START)
.padding(5)
.background(
(maxTemperature > 800) ? GTGuiTextures.DISPLAY : GTGuiTextures.DISPLAY_BRONZE)
.height(80)
.child(new TextWidget<>(IKey.dynamic(() -> {
List<Component> text = new ArrayList<>();
addDisplayText(text);
return text.stream()
.map(Component::copy)
.reduce((a, b) -> a.append("\n").append(b))
.orElse(Component.empty());
})))
.childIf(isFormed(), new ParentWidget<>().child(Flow.row().coverChildren().marginTop(1)
.child(new TextWidget<>(
IKey.lang("gtceu.multiblock.large_boiler.throttle_modify"))
.style(ChatFormatting.WHITE).marginRight(5))
.child(new ButtonWidget<>().height(8).onMousePressed((x, y, button) -> {
if (button == InputConstants.MOUSE_BUTTON_LEFT) {
this.throttle = Mth.clamp(throttle - 5, 25, 100);
this.getRecipeLogic().modifyFuelBurnTime(this.throttle);
}
return true;
}).background(IKey.str("[-]").style(ChatFormatting.YELLOW))
.hoverBackground(IKey.str("[-]").style(ChatFormatting.YELLOW)))
.child(new ButtonWidget<>().height(8).marginLeft(2)
.onMousePressed((x, y, button) -> {
if (button == InputConstants.MOUSE_BUTTON_LEFT) {
this.throttle = Mth.clamp(throttle + 5, 25, 100);
this.getRecipeLogic().modifyFuelBurnTime(this.throttle);
}
return true;
}).background(IKey.str("[+]").style(ChatFormatting.YELLOW))
.hoverBackground(IKey.str("[+]").style(ChatFormatting.YELLOW)))

))));
}

public static class LargeBoilerRecipeLogic extends RecipeLogic {
Expand Down