Skip to content

Commit fd64222

Browse files
committed
remove most dynamic keys
use overridable methods for screen/indicator remove initial syncing for ui
1 parent c05bd78 commit fd64222

17 files changed

+498
-570
lines changed

src/main/java/gregtech/api/metatileentity/multiblock/FuelMultiblockController.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import gregtech.api.capability.IMultipleTankHandler;
66
import gregtech.api.capability.impl.EnergyContainerList;
77
import gregtech.api.capability.impl.MultiblockFuelRecipeLogic;
8+
import gregtech.api.metatileentity.multiblock.ui.MultiblockUIFactory;
89
import gregtech.api.mui.sync.FixedIntArraySyncValue;
910
import gregtech.api.recipes.RecipeMap;
1011
import gregtech.api.util.GTUtility;
@@ -57,6 +58,22 @@ protected void addDisplayText(List<ITextComponent> textList) {
5758
.addWorkingStatusLine();
5859
}
5960

61+
@Override
62+
protected void configureDisplayText(MultiblockUIFactory.Builder builder) {
63+
MultiblockFuelRecipeLogic recipeLogic = (MultiblockFuelRecipeLogic) recipeMapWorkable;
64+
65+
builder.setWorkingStatus(recipeLogic.isWorkingEnabled(), recipeLogic.isActive())
66+
.addEnergyProductionLine(getMaxVoltage(), recipeLogic.getRecipeEUt())
67+
.addFuelNeededLine(recipeLogic.getRecipeFluidInputInfo(), recipeLogic.getPreviousRecipeDuration())
68+
.addWorkingStatusLine();
69+
}
70+
71+
@Override
72+
protected void configureWarningText(MultiblockUIFactory.Builder builder) {
73+
builder.addLowDynamoTierLine(isDynamoTierTooLow())
74+
.addMaintenanceProblemLines(getMaintenanceProblems());
75+
}
76+
6077
protected long getMaxVoltage() {
6178
IEnergyContainer energyContainer = recipeMapWorkable.getEnergyContainer();
6279
if (energyContainer != null && energyContainer.getEnergyCapacity() > 0) {
@@ -185,7 +202,6 @@ protected void addFuelText(List<ITextComponent> textList) {
185202
*/
186203
protected void createFuelTooltip(@NotNull RichTooltip tooltip, @NotNull FixedIntArraySyncValue amounts,
187204
@NotNull StringSyncValue fuelNameValue) {
188-
tooltip.setAutoUpdate(true);
189205
if (isStructureFormed()) {
190206
Fluid fluid = fuelNameValue.getStringValue() == null ? null :
191207
FluidRegistry.getFluid(fuelNameValue.getStringValue());

src/main/java/gregtech/api/metatileentity/multiblock/MultiMapMultiblockController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public TraceabilityPredicate autoAbilities(boolean checkEnergyIn, boolean checkM
135135
@Override
136136
protected MultiblockUIFactory createUIFactory() {
137137
IntSyncValue recipeMapValue = new IntSyncValue(this::getRecipeMapIndex, this::setRecipeMapIndex);
138-
return new MultiblockUIFactory(this)
138+
return super.createUIFactory()
139139
.createFlexButton((panel, syncManager) -> {
140140
if (getAvailableRecipeMaps() == null || getAvailableRecipeMaps().length <= 1)
141141
return null;

src/main/java/gregtech/api/metatileentity/multiblock/MultiblockWithDisplayBase.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public abstract class MultiblockWithDisplayBase extends MultiblockControllerBase
5050
private static final String NBT_VOIDING_MODE = "VoidingMode";
5151
private static final String NBT_VOIDING_ITEMS = "VoidingItems";
5252
private static final String NBT_VOIDING_FLUIDS = "VoidingFluids";
53-
private static final int UI_SYNC = GregtechDataCodes.assignId();
5453
private MultiblockUIFactory uiFactory;
5554

5655
private boolean voidingItems = false;
@@ -207,8 +206,6 @@ protected void formStructure(PatternMatchContext context) {
207206
}
208207
this.variantActiveBlocks = context.getOrDefault("VABlock", new LinkedList<>());
209208
replaceVariantBlocksActive(false);
210-
if (uiFactory != null)
211-
writeCustomData(UI_SYNC, uiFactory::writeInitialSync);;
212209
}
213210

214211
@Override
@@ -374,6 +371,7 @@ protected TraceabilityPredicate maintenancePredicate() {
374371
* each element of list is displayed on new line
375372
* to use translation, use TextComponentTranslation
376373
*/
374+
@Deprecated
377375
protected void addDisplayText(List<ITextComponent> textList) {
378376
MultiblockDisplayText.builder(textList, isStructureFormed());
379377
}
@@ -522,6 +520,7 @@ protected ModularUI.Builder createUITemplate(EntityPlayer entityPlayer) {
522520
* Returns a list of text indicating any current warnings in this Multiblock.
523521
* Recommended to only display warnings if the structure is already formed.
524522
*/
523+
@Deprecated
525524
protected void addWarningText(List<ITextComponent> textList) {
526525
MultiblockDisplayText.builder(textList, isStructureFormed(), false)
527526
.addMaintenanceProblemLines(getMaintenanceProblems());
@@ -531,6 +530,7 @@ protected void addWarningText(List<ITextComponent> textList) {
531530
* Returns a list of translation keys indicating any current errors in this Multiblock.
532531
* Prioritized over any warnings provided by {@link MultiblockWithDisplayBase#addWarningText}.
533532
*/
533+
@Deprecated
534534
protected void addErrorText(List<ITextComponent> textList) {
535535
MultiblockDisplayText.builder(textList, isStructureFormed())
536536
.addMufflerObstructedLine(hasMufflerMechanics() && !isMufflerFaceFree());
@@ -570,14 +570,22 @@ public boolean usesMui2() {
570570
return true;
571571
}
572572

573+
protected void configureDisplayText(MultiblockUIFactory.Builder builder) {}
574+
575+
protected void configureErrorText(MultiblockUIFactory.Builder builder) {}
576+
577+
protected void configureWarningText(MultiblockUIFactory.Builder builder) {}
578+
573579
protected MultiblockUIFactory createUIFactory() {
574-
return new MultiblockUIFactory(this);
580+
return new MultiblockUIFactory(this)
581+
.configureDisplayText(this::configureDisplayText)
582+
.configureWarningText(this::configureWarningText)
583+
.configureErrorText(this::configureErrorText);
575584
}
576585

577586
@Override
578587
public final ModularPanel buildUI(PosGuiData guiData, PanelSyncManager panelSyncManager) {
579-
if (uiFactory == null) return null;
580-
writeCustomData(UI_SYNC, uiFactory::writeInitialSync); // is this too early to sync?
588+
if (uiFactory == null) uiFactory = createUIFactory();
581589
return this.uiFactory.buildUI(guiData, panelSyncManager);
582590
}
583591

@@ -625,8 +633,6 @@ public void writeInitialSyncData(PacketBuffer buf) {
625633
buf.writeBoolean(voidingFluids);
626634
buf.writeBoolean(voidingItems);
627635
buf.writeInt(voidingMode.ordinal());
628-
if (uiFactory == null) uiFactory = createUIFactory();
629-
this.uiFactory.writeInitialSync(buf);
630636
}
631637

632638
@Override
@@ -637,8 +643,6 @@ public void receiveInitialSyncData(PacketBuffer buf) {
637643
voidingFluids = buf.readBoolean();
638644
voidingItems = buf.readBoolean();
639645
voidingMode = VoidingMode.values()[buf.readInt()];
640-
if (uiFactory == null) uiFactory = createUIFactory();
641-
this.uiFactory.readInitialSync(buf);
642646
}
643647

644648
@Override
@@ -679,10 +683,6 @@ public void receiveCustomData(int dataId, PacketBuffer buf) {
679683
if (dataId == IS_WORKING) {
680684
lastActive = buf.readBoolean();
681685
}
682-
if (dataId == UI_SYNC) {
683-
uiFactory.readInitialSync(buf);
684-
uiFactory.markDirty();
685-
}
686686
}
687687

688688
@Override

src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
import codechicken.lib.render.CCRenderState;
3434
import codechicken.lib.render.pipeline.IVertexOperation;
3535
import codechicken.lib.vec.Matrix4;
36-
import com.cleanroommc.modularui.value.sync.DoubleSyncValue;
37-
import com.cleanroommc.modularui.value.sync.IntSyncValue;
3836
import com.google.common.collect.Lists;
3937
import org.jetbrains.annotations.NotNull;
4038
import org.jetbrains.annotations.Nullable;
@@ -165,22 +163,18 @@ protected void addWarningText(List<ITextComponent> textList) {
165163
.addMaintenanceProblemLines(getMaintenanceProblems());
166164
}
167165

168-
@Override
169-
protected MultiblockUIFactory createUIFactory() {
170-
DoubleSyncValue progress = new DoubleSyncValue(recipeMapWorkable::getProgressPercent, null);
171-
IntSyncValue tier = new IntSyncValue(() -> GTUtility.getTierByVoltage(recipeMapWorkable.getMaxVoltage()), null);
172-
return new MultiblockUIFactory(this)
173-
.syncValue("progress", progress)
174-
.syncValue("tier", tier)
175-
.configureDisplayText(builder -> builder
176-
.setWorkingStatus(recipeMapWorkable::isWorkingEnabled, recipeMapWorkable::isActive)
177-
.addEnergyUsageLine(this::getEnergyContainer)
178-
.addEnergyTierLine(tier.getIntValue())
179-
.addParallelsLine(recipeMapWorkable.getParallelLimit())
180-
.addWorkingStatusLine()
181-
.addProgressLine(progress::getDoubleValue))
182-
.configureWarningText(builder -> builder
183-
.addLowPowerLine(recipeMapWorkable.isHasNotEnoughEnergy()));
166+
protected void configureDisplayText(MultiblockUIFactory.Builder builder) {
167+
builder.setWorkingStatus(recipeMapWorkable.isWorkingEnabled(), recipeMapWorkable.isActive())
168+
.addEnergyUsageLine(this.getEnergyContainer())
169+
.addEnergyTierLine(GTUtility.getTierByVoltage(recipeMapWorkable.getMaxVoltage()))
170+
.addParallelsLine(recipeMapWorkable.getParallelLimit())
171+
.addWorkingStatusLine()
172+
.addProgressLine(recipeMapWorkable.getProgressPercent());
173+
}
174+
175+
protected void configureWarningText(MultiblockUIFactory.Builder builder) {
176+
builder.addLowPowerLine(recipeMapWorkable.isHasNotEnoughEnergy());
177+
super.configureWarningText(builder);
184178
}
185179

186180
@Override

0 commit comments

Comments
 (0)