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

Port Multiblocks to MUI2 #2672

Draft
wants to merge 100 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
ac2dbea
start
TechLord22 Jul 9, 2024
02b6d13
add KeyUtil for handling IKeys
ghzdude Nov 19, 2024
0e562f9
multiblocks have `createUIFactory` to override for custom ui
ghzdude Nov 19, 2024
8cc8b08
`coloredTanslation()` -> `coloredLang()`
ghzdude Nov 19, 2024
d048557
remove generic for MultiblockUIFactory
ghzdude Nov 19, 2024
cc2a157
initial work on indicator widget
ghzdude Nov 19, 2024
4dbe0f6
help i am in syncing hell
ghzdude Nov 20, 2024
ef8d92a
remove todo
ghzdude Nov 20, 2024
e7479f3
sync certain values
ghzdude Nov 21, 2024
845bb9e
simplify slightly
ghzdude Nov 21, 2024
af2610b
sike i don't need ByteSyncValue
ghzdude Nov 21, 2024
54b1cab
structure formed is already synced
ghzdude Nov 21, 2024
d49f0f9
try sync progress
ghzdude Nov 21, 2024
afc1b53
progress works
ghzdude Nov 21, 2024
64519c7
fix args properly
ghzdude Nov 22, 2024
f8447a2
update large boiler
ghzdude Nov 22, 2024
5f04c5d
create ui factory at build instead of constructor
ghzdude Nov 22, 2024
1c0b9e8
update large combustion
ghzdude Nov 22, 2024
548aab5
pass in builder instead of list
ghzdude Nov 22, 2024
955d720
improve blinking logo a bit
ghzdude Nov 22, 2024
455bfba
switch to builder instead of list for warning/error
ghzdude Nov 22, 2024
80e4ead
add/improve javadocs
ghzdude Nov 23, 2024
b71cb40
remove reset and make internal methods private
ghzdude Nov 24, 2024
1e226cc
sync fuel needed and rotor stats
ghzdude Nov 24, 2024
232b929
rename and reorganize KeyUtil methods
ghzdude Nov 25, 2024
6ea0939
always return cache for client and default for server
ghzdude Nov 26, 2024
c96342a
make display text dynamically updated
ghzdude Nov 26, 2024
d661e6b
comments, use margin instead of padding, align
ghzdude Nov 26, 2024
07460ae
make and use builder methods instead of anonynous classes
ghzdude Nov 28, 2024
47c9ac8
move builder from MultiblockDisplayTextPort into MultiblockUIFactory
ghzdude Nov 28, 2024
9e67892
make builder static again
ghzdude Nov 28, 2024
50e7f21
simplify compound consumer
ghzdude Nov 28, 2024
ad87d0f
fix water for boiler
ghzdude Nov 28, 2024
8c1ba43
fix lubricant for LCE
ghzdude Nov 28, 2024
142e9d2
fix large turbine
ghzdude Nov 28, 2024
844e530
fix maint and obstruction
ghzdude Nov 28, 2024
0e73e55
improve int array sync value
ghzdude Nov 28, 2024
3eedd6f
improve compound consumers
ghzdude Nov 28, 2024
4ebbecc
start work on fixing display
ghzdude Nov 28, 2024
df39923
fix display tooltips
ghzdude Nov 28, 2024
858690c
use dynamic keys again
ghzdude Nov 28, 2024
c367f74
simplify display checking
ghzdude Nov 29, 2024
4b72562
add tooltip for no flex
ghzdude Nov 29, 2024
52e0a2b
improve value syncing greatly
ghzdude Nov 29, 2024
0164831
fix LCE fuel name + spotless
ghzdude Nov 29, 2024
1ae77ef
remove unused datacode
ghzdude Nov 29, 2024
22d5e9a
no need to sync temp
ghzdude Nov 29, 2024
85673d3
rework builder to use IDrawables
ghzdude Nov 29, 2024
751ac38
simplify ifs
ghzdude Nov 29, 2024
bf926db
move tooltip setting to right method
ghzdude Nov 29, 2024
b828a99
fix packages
ghzdude Nov 29, 2024
2f88707
make fluid drill lang colored
ghzdude Nov 29, 2024
8ae7830
port Fusion Reactor + textures
ghzdude Dec 2, 2024
8478b34
sync harder
ghzdude Dec 2, 2024
694a39f
improve EBF `formStructure()` a bit
ghzdude Dec 2, 2024
99b9049
remove unused datacode
ghzdude Dec 3, 2024
0f6c419
create new class for display that behaves similar to AdvancedTextWidget
ghzdude Dec 5, 2024
aa2bdce
add new case for status
ghzdude Dec 5, 2024
cf20cb9
improve drawing a bit
ghzdude Dec 5, 2024
a40a634
add change listener
ghzdude Dec 5, 2024
d247cd6
fix rebase
ghzdude Jan 8, 2025
2ac7847
only construct key array if lengths are different
ghzdude Jan 8, 2025
6e6658d
try to utilize new key methods
ghzdude Jan 8, 2025
42950c8
improve key util methods some more
ghzdude Jan 8, 2025
4b99741
simplify status keys
ghzdude Jan 8, 2025
88624bd
forgor flow
ghzdude Jan 8, 2025
19120fb
port to rich text
ghzdude Jan 9, 2025
9b4ded3
fix npe
ghzdude Jan 9, 2025
084a8f1
fix indicator tooltips
ghzdude Jan 10, 2025
5dbf56a
fix energy container line
ghzdude Jan 10, 2025
93bcda5
port pyrolyse and multismelter
ghzdude Jan 10, 2025
2ebe72f
fix potential npe when fixing args
ghzdude Jan 10, 2025
4d991c2
add mixin to set cache in constructor
ghzdude Jan 10, 2025
9ed22e3
no longer need to call this
ghzdude Jan 10, 2025
b95a6a3
cleanup
ghzdude Jan 10, 2025
0cbce26
make adding status keys actually translate
ghzdude Jan 10, 2025
b122013
port HPCA, research station, cracking unit
ghzdude Jan 10, 2025
7d15218
port processing array
ghzdude Jan 10, 2025
ad11e81
go back to drawable list
ghzdude Jan 14, 2025
f077938
update note
ghzdude Jan 14, 2025
614f3d2
merge text related mixins under one class
ghzdude Jan 17, 2025
d2cbaa3
create better impl for keys with tooltips
ghzdude Jan 17, 2025
ba57233
implement key serialization
ghzdude Jan 17, 2025
9734645
remove note
ghzdude Jan 17, 2025
d426f48
remove most dynamic keys
ghzdude Jan 17, 2025
60c175c
fix npe when serializing null arrays
ghzdude Jan 17, 2025
cc37182
no need to sync energy container
ghzdude Jan 17, 2025
fb3cfcb
add helper method for array access
ghzdude Jan 17, 2025
223a03b
address todo for dynamic color tooltip
ghzdude Jan 18, 2025
7c06d9b
this class is no longer necessary
ghzdude Jan 18, 2025
e00e835
add method overload
ghzdude Jan 29, 2025
766ccae
simplify DrawableSerializer
ghzdude Jan 29, 2025
27cb4bb
add method for additional children to the screen
ghzdude Jan 29, 2025
aefa4aa
remove custom screen
ghzdude Jan 29, 2025
87fdbca
remove unused method
ghzdude Jan 29, 2025
b6e34a6
Move the PSS to the new MUI2 display text methods
Zorbatron Jan 30, 2025
50dc0b5
simplify progress bars a bit
ghzdude Jan 30, 2025
12ad632
add extra space to lines
ghzdude Jan 30, 2025
901c7b6
Pass guiData to `MultiblockUIFactory#createFlexButton`
Zorbatron Jan 30, 2025
a82d411
move trifunction back to bifunction and remove panel parameter
ghzdude Jan 30, 2025
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 @@ -142,7 +142,7 @@ public String getRecipeFluidInputInfo() {
int ocAmount = GTUtility.safeCastLongToInt(getMaxVoltage() / recipe.getEUt());
int neededAmount = ocAmount * requiredFluidInput.amount;
if (rotorHolder != null && rotorHolder.hasRotor()) {
neededAmount /= (rotorHolder.getTotalEfficiency() / 100.0);
neededAmount /= (int) (rotorHolder.getTotalEfficiency() / 100.0);
} else if (rotorHolder != null && !rotorHolder.hasRotor()) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ public GTGuiTheme getUITheme() {
}

@Override
public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager guiSyncManager) {
public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager panelSyncManager) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import gregtech.api.capability.IMultipleTankHandler;
import gregtech.api.capability.impl.EnergyContainerList;
import gregtech.api.capability.impl.MultiblockFuelRecipeLogic;
import gregtech.api.metatileentity.multiblock.ui.MultiblockUIFactory;
import gregtech.api.mui.sync.FixedIntArraySyncValue;
import gregtech.api.recipes.RecipeMap;
import gregtech.api.util.GTUtility;
import gregtech.api.util.TextComponentUtil;
Expand All @@ -16,8 +18,13 @@
import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;

import com.cleanroommc.modularui.api.drawable.IKey;
import com.cleanroommc.modularui.screen.RichTooltip;
import com.cleanroommc.modularui.value.sync.StringSyncValue;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
Expand Down Expand Up @@ -51,6 +58,22 @@ protected void addDisplayText(List<ITextComponent> textList) {
.addWorkingStatusLine();
}

@Override
protected void configureDisplayText(MultiblockUIFactory.Builder builder) {
MultiblockFuelRecipeLogic recipeLogic = (MultiblockFuelRecipeLogic) recipeMapWorkable;

builder.setWorkingStatus(recipeLogic.isWorkingEnabled(), recipeLogic.isActive())
.addEnergyProductionLine(getMaxVoltage(), recipeLogic.getRecipeEUt())
.addFuelNeededLine(recipeLogic.getRecipeFluidInputInfo(), recipeLogic.getPreviousRecipeDuration())
.addWorkingStatusLine();
}

@Override
protected void configureWarningText(MultiblockUIFactory.Builder builder) {
builder.addLowDynamoTierLine(isDynamoTierTooLow())
.addMaintenanceProblemLines(getMaintenanceProblems());
}

protected long getMaxVoltage() {
IEnergyContainer energyContainer = recipeMapWorkable.getEnergyContainer();
if (energyContainer != null && energyContainer.getEnergyCapacity() > 0) {
Expand Down Expand Up @@ -138,6 +161,7 @@ protected int[] getTotalFluidAmount(FluidStack testStack, IMultipleTankHandler m
return new int[] { fluidAmount, fluidCapacity };
}

@Deprecated
protected void addFuelText(List<ITextComponent> textList) {
// Fuel
int fuelStored = 0;
Expand Down Expand Up @@ -170,4 +194,26 @@ protected void addFuelText(List<ITextComponent> textList) {
"0 / 0 L"));
}
}

/**
* @param tooltip the tooltip to populate
* @param amounts the sync value containing an array of [fuel stored, fuel capacity]
* @param fuelNameValue the name of the fuel
*/
protected void createFuelTooltip(@NotNull RichTooltip tooltip, @NotNull FixedIntArraySyncValue amounts,
@NotNull StringSyncValue fuelNameValue) {
if (isStructureFormed()) {
Fluid fluid = fuelNameValue.getStringValue() == null ? null :
FluidRegistry.getFluid(fuelNameValue.getStringValue());
if (fluid == null) {
tooltip.addLine(IKey.lang("gregtech.multiblock.large_combustion_engine.fuel_none"));
} else {
tooltip.addLine(
IKey.lang("gregtech.multiblock.large_combustion_engine.fuel_amount", amounts.getValue(0),
amounts.getValue(1), fluid.getLocalizedName(new FluidStack(fluid, 1))));
}
} else {
tooltip.addLine(IKey.lang("gregtech.multiblock.invalid_structure"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@

import gregtech.api.gui.GuiTextures;
import gregtech.api.gui.resources.TextureArea;
import gregtech.api.mui.GTGuiTextures;

import net.minecraft.util.text.ITextComponent;

import com.cleanroommc.modularui.drawable.UITexture;
import com.cleanroommc.modularui.screen.Tooltip;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

import java.util.List;

@ApiStatus.ScheduledForRemoval
@Deprecated
public interface IProgressBarMultiblock {

default boolean showProgressBar() {
Expand All @@ -24,14 +32,26 @@ default int getNumProgressBars() {
double getFillPercentage(int index);

/** Textures for the progress bar(s). */
@Deprecated
default TextureArea getProgressBarTexture(int index) {
return GuiTextures.PROGRESS_BAR_MULTI_ENERGY_YELLOW;
}

default UITexture getProgressBarTexture2(int index) {
return GTGuiTextures.PROGRESS_BAR_MULTI_ENERGY_YELLOW;
}

default int getProgressBarTextureHeight(int index) {
return 18;
}

/**
* Add hover text to your progress bar(s).
*
* @param index The index, 0, 1, or 2, of your progress bar. Only relevant if you have multiple bars.
*/
@Deprecated
default void addBarHoverText(List<ITextComponent> hoverList, int index) {}

default void addBarHoverText2(@NotNull Tooltip tooltip, int index) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
import gregtech.api.capability.GregtechDataCodes;
import gregtech.api.capability.GregtechTileCapabilities;
import gregtech.api.capability.IMultipleRecipeMaps;
import gregtech.api.gui.GuiTextures;
import gregtech.api.gui.Widget;
import gregtech.api.gui.widgets.ImageCycleButtonWidget;
import gregtech.api.metatileentity.multiblock.ui.MultiblockUIFactory;
import gregtech.api.mui.GTGuiTextures;
import gregtech.api.pattern.TraceabilityPredicate;
import gregtech.api.recipes.RecipeMap;
import gregtech.api.util.LocalizationUtils;

import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
Expand All @@ -25,7 +23,9 @@
import net.minecraftforge.fml.relauncher.SideOnly;

import codechicken.lib.raytracer.CuboidRayTraceResult;
import org.jetbrains.annotations.NotNull;
import com.cleanroommc.modularui.api.drawable.IKey;
import com.cleanroommc.modularui.value.sync.IntSyncValue;
import com.cleanroommc.modularui.widgets.CycleButtonWidget;
import org.jetbrains.annotations.Nullable;

import java.util.List;
Expand Down Expand Up @@ -133,17 +133,27 @@ public TraceabilityPredicate autoAbilities(boolean checkEnergyIn, boolean checkM
}

@Override
protected @NotNull Widget getFlexButton(int x, int y, int width, int height) {
if (getAvailableRecipeMaps() != null && getAvailableRecipeMaps().length > 1) {
return new ImageCycleButtonWidget(x, y, width, height, GuiTextures.BUTTON_MULTI_MAP,
getAvailableRecipeMaps().length, this::getRecipeMapIndex, this::setRecipeMapIndex)
.shouldUseBaseBackground().singleTexture()
.setTooltipHoverString(i -> LocalizationUtils
.format("gregtech.multiblock.multiple_recipemaps.header") + " " +
LocalizationUtils.format(
"recipemap." + getAvailableRecipeMaps()[i].getUnlocalizedName() + ".name"));
}
return super.getFlexButton(x, y, width, height);
protected MultiblockUIFactory createUIFactory() {
IntSyncValue recipeMapValue = new IntSyncValue(this::getRecipeMapIndex, this::setRecipeMapIndex);
return super.createUIFactory()
.createFlexButton((guiData, syncManager) -> {
if (getAvailableRecipeMaps() == null || getAvailableRecipeMaps().length <= 1)
return null;

return new CycleButtonWidget()
// .textureGetter(i -> GTGuiTextures.BUTTON_MULTI_MAP)
.overlay(GTGuiTextures.BUTTON_MULTI_MAP)
.background(GTGuiTextures.BUTTON)
// TODO find out why this needs to be called
.disableHoverBackground()
.value(recipeMapValue)
.length(getAvailableRecipeMaps().length)
.tooltip(tooltip -> tooltip.setAutoUpdate(true))
.tooltipBuilder(t -> t.addLine(IKey.comp(
IKey.lang("gregtech.multiblock.multiple_recipemaps.value",
IKey.lang(getAvailableRecipeMaps()[recipeMapValue.getIntValue()]
.getTranslationKey())))));
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import gregtech.api.capability.*;
import gregtech.api.gui.GuiTextures;
import gregtech.api.gui.ModularUI;
import gregtech.api.gui.Widget;
import gregtech.api.gui.Widget.ClickData;
import gregtech.api.gui.resources.TextureArea;
import gregtech.api.gui.widgets.AdvancedTextWidget;
import gregtech.api.gui.widgets.ImageCycleButtonWidget;
import gregtech.api.gui.widgets.ImageWidget;
import gregtech.api.gui.widgets.IndicatorImageWidget;
import gregtech.api.gui.widgets.ProgressWidget;
import gregtech.api.metatileentity.multiblock.ui.MultiblockUIFactory;
import gregtech.api.pattern.PatternMatchContext;
import gregtech.api.pattern.TraceabilityPredicate;
import gregtech.api.unification.OreDictUnifier;
Expand All @@ -33,10 +33,14 @@
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import com.cleanroommc.modularui.factory.PosGuiData;
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

import java.util.*;
import java.util.function.BiFunction;

import static gregtech.api.capability.GregtechDataCodes.IS_WORKING;
import static gregtech.api.capability.GregtechDataCodes.STORE_TAPED;
Expand All @@ -46,6 +50,7 @@ public abstract class MultiblockWithDisplayBase extends MultiblockControllerBase
private static final String NBT_VOIDING_MODE = "VoidingMode";
private static final String NBT_VOIDING_ITEMS = "VoidingItems";
private static final String NBT_VOIDING_FLUIDS = "VoidingFluids";
private MultiblockUIFactory uiFactory;

private boolean voidingItems = false;
private boolean voidingFluids = false;
Expand Down Expand Up @@ -366,6 +371,7 @@ protected TraceabilityPredicate maintenancePredicate() {
* each element of list is displayed on new line
* to use translation, use TextComponentTranslation
*/
@Deprecated
protected void addDisplayText(List<ITextComponent> textList) {
MultiblockDisplayText.builder(textList, isStructureFormed());
}
Expand Down Expand Up @@ -458,7 +464,7 @@ protected ModularUI.Builder createUITemplate(EntityPlayer entityPlayer) {
if (shouldShowVoidingModeButton()) {
builder.widget(new ImageCycleButtonWidget(173, 161, 18, 18, GuiTextures.BUTTON_VOID_MULTIBLOCK,
4, this::getVoidingMode, this::setVoidingMode)
.setTooltipHoverString(MultiblockWithDisplayBase::getVoidingModeTooltip));
.setTooltipHoverString(this::getVoidingModeTooltip));
} else {
builder.widget(new ImageWidget(173, 161, 18, 18, GuiTextures.BUTTON_VOID_NONE)
.setTooltip("gregtech.gui.multiblock_voiding_not_supported"));
Expand All @@ -483,15 +489,17 @@ protected ModularUI.Builder createUITemplate(EntityPlayer entityPlayer) {
}

/**
* Add a custom third button to the Multiblock UI. By default, this is a placeholder
* stating that there is no additional functionality for this Multiblock.
* Add a custom third button to the Multiblock UI. By default, this is a placeholder stating that there is no
* additional functionality for this Multiblock.
* <br>
* <br>
* Parameters should be passed directly to the created widget. Size will be 18x18.
*
* @deprecated override {@link MultiblockUIFactory#createFlexButton(BiFunction)}
*/
@Deprecated
@SuppressWarnings("SameParameterValue")
@NotNull
protected Widget getFlexButton(int x, int y, int width, int height) {
protected gregtech.api.gui.@NotNull Widget getFlexButton(int x, int y, int width, int height) {
return new ImageWidget(x, y, width, height, GuiTextures.BUTTON_NO_FLEX)
.setTooltip("gregtech.multiblock.universal.no_flex_button");
}
Expand All @@ -512,6 +520,7 @@ protected Widget getFlexButton(int x, int y, int width, int height) {
* Returns a list of text indicating any current warnings in this Multiblock.
* Recommended to only display warnings if the structure is already formed.
*/
@Deprecated
protected void addWarningText(List<ITextComponent> textList) {
MultiblockDisplayText.builder(textList, isStructureFormed(), false)
.addMaintenanceProblemLines(getMaintenanceProblems());
Expand All @@ -521,20 +530,21 @@ protected void addWarningText(List<ITextComponent> textList) {
* Returns a list of translation keys indicating any current errors in this Multiblock.
* Prioritized over any warnings provided by {@link MultiblockWithDisplayBase#addWarningText}.
*/
@Deprecated
protected void addErrorText(List<ITextComponent> textList) {
MultiblockDisplayText.builder(textList, isStructureFormed())
.addMufflerObstructedLine(hasMufflerMechanics() && !isMufflerFaceFree());
}

protected boolean shouldShowVoidingModeButton() {
public boolean shouldShowVoidingModeButton() {
return true;
}

protected int getVoidingMode() {
public final int getVoidingMode() {
return voidingMode.ordinal();
}

protected void setVoidingMode(int mode) {
public final void setVoidingMode(int mode) {
this.voidingMode = VoidingMode.VALUES[mode];

this.voidingFluids = mode >= 2;
Expand All @@ -551,10 +561,34 @@ protected void setVoidingMode(int mode) {
markDirty();
}

protected static String getVoidingModeTooltip(int mode) {
public @NotNull String getVoidingModeTooltip(int mode) {
return VoidingMode.VALUES[mode].getName();
}

@Override
public boolean usesMui2() {
return true;
}

protected void configureDisplayText(MultiblockUIFactory.Builder builder) {}

protected void configureErrorText(MultiblockUIFactory.Builder builder) {}

protected void configureWarningText(MultiblockUIFactory.Builder builder) {}

protected MultiblockUIFactory createUIFactory() {
return new MultiblockUIFactory(this)
.configureDisplayText(this::configureDisplayText)
.configureWarningText(this::configureWarningText)
.configureErrorText(this::configureErrorText);
}

@Override
public final ModularPanel buildUI(PosGuiData guiData, PanelSyncManager panelSyncManager) {
if (uiFactory == null) uiFactory = createUIFactory();
return this.uiFactory.buildUI(guiData, panelSyncManager);
}

@Override
protected ModularUI createUI(EntityPlayer entityPlayer) {
return createUITemplate(entityPlayer).build(getHolder(), entityPlayer);
Expand Down
Loading