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 90 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
e8e19a2
start
TechLord22 Jul 9, 2024
edd59f9
add KeyUtil for handling IKeys
ghzdude Nov 19, 2024
aa9c63e
multiblocks have `createUIFactory` to override for custom ui
ghzdude Nov 19, 2024
9836bcf
`coloredTanslation()` -> `coloredLang()`
ghzdude Nov 19, 2024
2197a15
remove generic for MultiblockUIFactory
ghzdude Nov 19, 2024
2650bc3
initial work on indicator widget
ghzdude Nov 19, 2024
a70891a
help i am in syncing hell
ghzdude Nov 20, 2024
16134d7
remove todo
ghzdude Nov 20, 2024
dab21e8
sync certain values
ghzdude Nov 21, 2024
27294f6
simplify slightly
ghzdude Nov 21, 2024
84ff8ed
sike i don't need ByteSyncValue
ghzdude Nov 21, 2024
710e598
structure formed is already synced
ghzdude Nov 21, 2024
52aea74
try sync progress
ghzdude Nov 21, 2024
7ee951f
progress works
ghzdude Nov 21, 2024
d982a6c
fix args properly
ghzdude Nov 22, 2024
6fd3a2a
update large boiler
ghzdude Nov 22, 2024
5c24871
create ui factory at build instead of constructor
ghzdude Nov 22, 2024
1c16ca7
update large combustion
ghzdude Nov 22, 2024
8956458
pass in builder instead of list
ghzdude Nov 22, 2024
942053d
improve blinking logo a bit
ghzdude Nov 22, 2024
c2dccca
switch to builder instead of list for warning/error
ghzdude Nov 22, 2024
70c7e73
add/improve javadocs
ghzdude Nov 23, 2024
b9f1a93
remove reset and make internal methods private
ghzdude Nov 24, 2024
2b4eff2
sync fuel needed and rotor stats
ghzdude Nov 24, 2024
b8c5cbb
rename and reorganize KeyUtil methods
ghzdude Nov 25, 2024
f4ec7f9
always return cache for client and default for server
ghzdude Nov 26, 2024
8809600
make display text dynamically updated
ghzdude Nov 26, 2024
a393364
comments, use margin instead of padding, align
ghzdude Nov 26, 2024
8b1302f
make and use builder methods instead of anonynous classes
ghzdude Nov 28, 2024
50bdd93
move builder from MultiblockDisplayTextPort into MultiblockUIFactory
ghzdude Nov 28, 2024
b751377
make builder static again
ghzdude Nov 28, 2024
ae37a25
simplify compound consumer
ghzdude Nov 28, 2024
55f0a99
fix water for boiler
ghzdude Nov 28, 2024
6d5a1d4
fix lubricant for LCE
ghzdude Nov 28, 2024
e9dcb54
fix large turbine
ghzdude Nov 28, 2024
b3a7da8
fix maint and obstruction
ghzdude Nov 28, 2024
ec8c29a
improve int array sync value
ghzdude Nov 28, 2024
db97290
improve compound consumers
ghzdude Nov 28, 2024
e693e92
start work on fixing display
ghzdude Nov 28, 2024
c60043f
fix display tooltips
ghzdude Nov 28, 2024
02a4f34
use dynamic keys again
ghzdude Nov 28, 2024
69fc4f9
simplify display checking
ghzdude Nov 29, 2024
101ef1a
add tooltip for no flex
ghzdude Nov 29, 2024
6a01344
improve value syncing greatly
ghzdude Nov 29, 2024
1b330cf
fix LCE fuel name + spotless
ghzdude Nov 29, 2024
6445fc4
remove unused datacode
ghzdude Nov 29, 2024
87e8354
no need to sync temp
ghzdude Nov 29, 2024
8c8ca6b
rework builder to use IDrawables
ghzdude Nov 29, 2024
9b6e22b
simplify ifs
ghzdude Nov 29, 2024
17dd6e2
move tooltip setting to right method
ghzdude Nov 29, 2024
5c86084
fix packages
ghzdude Nov 29, 2024
23dc023
make fluid drill lang colored
ghzdude Nov 29, 2024
b33fbc2
port Fusion Reactor + textures
ghzdude Dec 2, 2024
6dce94f
sync harder
ghzdude Dec 2, 2024
93dd2ff
improve EBF `formStructure()` a bit
ghzdude Dec 2, 2024
b80647b
remove unused datacode
ghzdude Dec 3, 2024
986072e
create new class for display that behaves similar to AdvancedTextWidget
ghzdude Dec 5, 2024
fa1eb98
add new case for status
ghzdude Dec 5, 2024
93bfb53
improve drawing a bit
ghzdude Dec 5, 2024
8943cda
add change listener
ghzdude Dec 5, 2024
9b2c421
fix rebase
ghzdude Jan 8, 2025
d841b3e
only construct key array if lengths are different
ghzdude Jan 8, 2025
3956c92
try to utilize new key methods
ghzdude Jan 8, 2025
b9a4517
improve key util methods some more
ghzdude Jan 8, 2025
dbdcd51
simplify status keys
ghzdude Jan 8, 2025
36a9249
forgor flow
ghzdude Jan 8, 2025
daf83c9
port to rich text
ghzdude Jan 9, 2025
4dad110
fix npe
ghzdude Jan 9, 2025
6379bd3
fix indicator tooltips
ghzdude Jan 10, 2025
015c82b
fix energy container line
ghzdude Jan 10, 2025
e103f9c
port pyrolyse and multismelter
ghzdude Jan 10, 2025
5e4f7fd
fix potential npe when fixing args
ghzdude Jan 10, 2025
f2fe4fe
add mixin to set cache in constructor
ghzdude Jan 10, 2025
9c6e901
no longer need to call this
ghzdude Jan 10, 2025
8ef121e
cleanup
ghzdude Jan 10, 2025
1a6cab4
make adding status keys actually translate
ghzdude Jan 10, 2025
7bf7c3c
port HPCA, research station, cracking unit
ghzdude Jan 10, 2025
b65f4f0
port processing array
ghzdude Jan 10, 2025
7e56ccc
go back to drawable list
ghzdude Jan 14, 2025
689cb57
update note
ghzdude Jan 14, 2025
5e561f1
merge text related mixins under one class
ghzdude Jan 17, 2025
7b2bda0
create better impl for keys with tooltips
ghzdude Jan 17, 2025
babf194
implement key serialization
ghzdude Jan 17, 2025
c05bd78
remove note
ghzdude Jan 17, 2025
fd64222
remove most dynamic keys
ghzdude Jan 17, 2025
eeb068d
fix npe when serializing null arrays
ghzdude Jan 17, 2025
b7de2a6
no need to sync energy container
ghzdude Jan 17, 2025
6e486e5
add helper method for array access
ghzdude Jan 17, 2025
37af081
address todo for dynamic color tooltip
ghzdude Jan 18, 2025
2e8eff4
this class is no longer necessary
ghzdude Jan 18, 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((panel, 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
Loading