Skip to content

Commit b65f4f0

Browse files
committed
port processing array
add varargs to setHover()
1 parent 7bf7c3c commit b65f4f0

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

src/main/java/gregtech/api/util/KeyUtil.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ public static IKey number(Supplier<TextFormatting> formatting, LongSupplier supp
8787
return string(formatting, () -> TextFormattingUtil.formatNumbers(supplier.getAsLong()) + suffix);
8888
}
8989

90-
public static IDrawable setHover(IKey body, IDrawable hover) {
91-
return body.asTextIcon().asHoverable().addTooltipLine(hover);
90+
public static IDrawable setHover(IKey body, IDrawable... hover) {
91+
if (ArrayUtils.isEmpty(hover)) return body;
92+
return body.asTextIcon().asHoverable().addTooltipDrawableLines(Arrays.asList(hover));
9293
}
9394

9495
private static IKey wrap(TextFormatting formatting) {

src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityProcessingArray.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import gregtech.api.metatileentity.multiblock.MultiblockAbility;
1717
import gregtech.api.metatileentity.multiblock.MultiblockDisplayText;
1818
import gregtech.api.metatileentity.multiblock.RecipeMapMultiblockController;
19+
import gregtech.api.metatileentity.multiblock.ui.MultiblockUIFactory;
1920
import gregtech.api.pattern.BlockPattern;
2021
import gregtech.api.pattern.FactoryBlockPattern;
2122
import gregtech.api.pattern.PatternMatchContext;
@@ -26,6 +27,7 @@
2627
import gregtech.api.recipes.logic.OCResult;
2728
import gregtech.api.recipes.properties.RecipePropertyStorage;
2829
import gregtech.api.util.GTUtility;
30+
import gregtech.api.util.KeyUtil;
2931
import gregtech.api.util.TextComponentUtil;
3032
import gregtech.api.util.TextFormattingUtil;
3133
import gregtech.client.renderer.ICubeRenderer;
@@ -49,6 +51,9 @@
4951
import net.minecraftforge.fml.relauncher.SideOnly;
5052
import net.minecraftforge.items.IItemHandlerModifiable;
5153

54+
import com.cleanroommc.modularui.api.drawable.IKey;
55+
import com.cleanroommc.modularui.value.sync.DoubleSyncValue;
56+
import com.cleanroommc.modularui.value.sync.IntSyncValue;
5257
import org.apache.commons.lang3.ArrayUtils;
5358
import org.jetbrains.annotations.NotNull;
5459
import org.jetbrains.annotations.Nullable;
@@ -174,6 +179,73 @@ protected void addDisplayText(List<ITextComponent> textList) {
174179
.addProgressLine(recipeMapWorkable.getProgressPercent());
175180
}
176181

182+
@Override
183+
protected MultiblockUIFactory createUIFactory() {
184+
ProcessingArrayWorkable logic = (ProcessingArrayWorkable) recipeMapWorkable;
185+
186+
DoubleSyncValue progress = new DoubleSyncValue(recipeMapWorkable::getProgressPercent, null);
187+
IntSyncValue tier = new IntSyncValue(() -> logic.currentMachineStack.isEmpty() ? -1 : logic.machineTier, null);
188+
return new MultiblockUIFactory(this)
189+
.syncValue("progress", progress)
190+
.syncValue("tier", tier)
191+
.configureDisplayText(builder -> builder
192+
.setWorkingStatus(recipeMapWorkable::isWorkingEnabled, recipeMapWorkable::isActive)
193+
.addEnergyUsageLine(this::getEnergyContainer)
194+
.addEnergyTierLine(tier.getIntValue())
195+
.addCustom(richText -> {
196+
if (!isStructureFormed()) return;
197+
198+
// Machine mode text
199+
// Shared text components for both states
200+
IKey maxMachinesText = KeyUtil.string(TextFormatting.DARK_PURPLE,
201+
Integer.toString(getMachineLimit()));
202+
maxMachinesText = KeyUtil.lang(TextFormatting.GRAY,
203+
"gregtech.machine.machine_hatch.machines_max", maxMachinesText);
204+
205+
if (logic.activeRecipeMap == null) {
206+
// No machines in hatch
207+
IKey noneText = KeyUtil.lang(TextFormatting.YELLOW,
208+
"gregtech.machine.machine_hatch.machines_none");
209+
IKey bodyText = KeyUtil.lang(TextFormatting.GRAY,
210+
"gregtech.machine.machine_hatch.machines", noneText);
211+
IKey hoverText1 = KeyUtil.lang(TextFormatting.GRAY,
212+
"gregtech.machine.machine_hatch.machines_none_hover");
213+
richText.addLine(KeyUtil.setHover(bodyText, hoverText1, maxMachinesText));
214+
} else {
215+
// Some amount of machines in hatch
216+
String key = logic.getMachineStack().getTranslationKey();
217+
IKey mapText = KeyUtil.lang(TextFormatting.DARK_PURPLE,
218+
key + ".name");
219+
mapText = KeyUtil.lang(
220+
TextFormatting.DARK_PURPLE,
221+
"%sx %s",
222+
logic.getParallelLimit(), mapText);
223+
IKey bodyText = KeyUtil.lang(TextFormatting.GRAY,
224+
"gregtech.machine.machine_hatch.machines", mapText);
225+
String voltageName = GTValues.VNF[logic.machineTier];
226+
int amps = logic.getMachineStack().getCount();
227+
String energyFormatted = TextFormattingUtil
228+
.formatNumbers(GTValues.V[logic.machineTier] * amps);
229+
IKey hoverText = KeyUtil.lang(
230+
TextFormatting.GRAY,
231+
"gregtech.machine.machine_hatch.machines_max_eut",
232+
energyFormatted, amps, voltageName);
233+
richText.addLine(KeyUtil.setHover(bodyText, hoverText, maxMachinesText));
234+
}
235+
236+
// Hatch locked status
237+
if (isActive()) {
238+
richText.addLine(KeyUtil.lang(TextFormatting.DARK_RED,
239+
"gregtech.machine.machine_hatch.locked"));
240+
}
241+
})
242+
.addParallelsLine(recipeMapWorkable.getParallelLimit())
243+
.addWorkingStatusLine()
244+
.addProgressLine(progress::getDoubleValue))
245+
.configureWarningText(builder -> builder
246+
.addLowPowerLine(recipeMapWorkable.isHasNotEnoughEnergy()));
247+
}
248+
177249
@SideOnly(Side.CLIENT)
178250
@NotNull
179251
@Override

0 commit comments

Comments
 (0)