Skip to content

Commit 5b212cb

Browse files
authored
Port singleblock miners to MUI2 and fix lang error (#2878)
1 parent b6960a5 commit 5b212cb

File tree

7 files changed

+286
-140
lines changed

7 files changed

+286
-140
lines changed

src/main/java/gregtech/api/capability/IMiner.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
package gregtech.api.capability;
22

3+
import gregtech.common.mui.widget.ScrollableTextWidget;
4+
5+
import net.minecraftforge.items.IItemHandlerModifiable;
6+
37
import codechicken.lib.vec.Cuboid6;
8+
import com.cleanroommc.modularui.drawable.UITexture;
9+
import com.cleanroommc.modularui.drawable.text.RichText;
10+
import com.cleanroommc.modularui.utils.Alignment;
11+
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
12+
import com.cleanroommc.modularui.value.sync.SyncHandlers;
13+
import com.cleanroommc.modularui.widget.Widget;
14+
import com.cleanroommc.modularui.widgets.layout.Flow;
15+
import com.cleanroommc.modularui.widgets.layout.Grid;
16+
import com.cleanroommc.modularui.widgets.slot.ItemSlot;
17+
import org.jetbrains.annotations.NotNull;
18+
19+
import java.util.function.Consumer;
420

521
public interface IMiner {
622

@@ -19,4 +35,31 @@ default boolean drainFluid(boolean simulate) {
1935
default int getWorkingArea(int maximumRadius) {
2036
return maximumRadius * 2 + 1;
2137
}
38+
39+
default Widget<?> createMinerWidgets(@NotNull PanelSyncManager panelSyncManager,
40+
@NotNull IItemHandlerModifiable inventory, int inventorySize,
41+
@NotNull UITexture textDisplayBackground,
42+
@NotNull Consumer<RichText> textBuilder) {
43+
int rowSize = (int) Math.sqrt(inventorySize);
44+
panelSyncManager.registerSlotGroup("export_items", rowSize);
45+
46+
return Flow.row()
47+
.coverChildren()
48+
.child(new ScrollableTextWidget()
49+
.size(105 - 3 * 2, 75 - 3 * 2)
50+
.autoUpdate(true)
51+
.alignment(Alignment.TopLeft)
52+
.textBuilder(textBuilder)
53+
.background(textDisplayBackground.asIcon()
54+
.margin(-3)))
55+
.child(new Grid()
56+
.marginLeft(6)
57+
.minElementMargin(0)
58+
.minColWidth(18)
59+
.minRowHeight(18)
60+
.mapTo(rowSize, inventorySize, index -> new ItemSlot()
61+
.slot(SyncHandlers.itemSlot(inventory, index)
62+
.slotGroup("export_items")
63+
.accessibility(false, true))));
64+
}
2265
}

src/main/java/gregtech/api/mui/GTGuiTheme.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ private static String gregtech(String s) {
7171
public static final GTGuiTheme BRONZE = templateBuilder(Names.BRONZE)
7272
.parent(Names.STANDARD)
7373
.panel(IDs.BRONZE_BACKGROUND)
74-
// .itemSlot(GTGuiTextures.IDs.BRONZE_SLOT)
75-
// .fluidSlot(GTGuiTextures.IDs.BRONZE_SLOT)
74+
.itemSlot(GTGuiTextures.IDs.BRONZE_SLOT)
7675
.displayBackground(IDs.DISPLAY_BRONZE)
7776
.button(IDs.BRONZE_BUTTON)
7877
.color(Colors.BRONZE)
@@ -84,8 +83,7 @@ private static String gregtech(String s) {
8483
.parent(Names.STANDARD)
8584
.panel(IDs.STEEL_BACKGROUND)
8685
.textColor(Color.WHITE.darker(1))
87-
// .itemSlot(GTGuiTextures.IDs.STEEL_SLOT)
88-
// .fluidSlot(GTGuiTextures.IDs.STEEL_SLOT)
86+
.itemSlot(GTGuiTextures.IDs.STEEL_SLOT)
8987
.displayBackground(IDs.DISPLAY_STEEL)
9088
.button(IDs.STEEL_BUTTON)
9189
.simpleToggleButton(IDs.STEEL_BUTTON, IDs.STEEL_BUTTON_SELECTED,
@@ -98,8 +96,7 @@ private static String gregtech(String s) {
9896
.panel(IDs.PRIMITIVE_BACKGROUND)
9997
.textColor(Color.WHITE.darker(1))
10098
.color(Colors.PRIMITIVE)
101-
// .itemSlot(GTGuiTextures.IDs.PRIMITIVE_SLOT)
102-
// .fluidSlot(GTGuiTextures.IDs.PRIMITIVE_SLOT)
99+
.itemSlot(GTGuiTextures.IDs.PRIMITIVE_SLOT)
103100
.build();
104101

105102
protected final String themeId;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package gregtech.api.mui;
2+
3+
import gregtech.api.util.KeyUtil;
4+
5+
import net.minecraft.util.text.TextFormatting;
6+
7+
import com.cleanroommc.modularui.api.drawable.IKey;
8+
9+
public final class TextStandards {
10+
11+
public static class Colors {
12+
13+
public static final TextFormatting MACHINE_WORKING = TextFormatting.GREEN;
14+
public static final TextFormatting MACHINE_DONE = TextFormatting.GREEN;
15+
public static final TextFormatting MACHINE_PAUSED = TextFormatting.GOLD;
16+
public static final TextFormatting NO_OUTPUT_SPACE = TextFormatting.RED;
17+
public static final TextFormatting STEAM_VENT_BLOCKED = TextFormatting.RED;
18+
public static final TextFormatting NO_POWER = TextFormatting.RED;
19+
}
20+
21+
public static class Keys {
22+
23+
public static final IKey MACHINE_PAUSED = KeyUtil.lang(Colors.MACHINE_PAUSED,
24+
"gregtech.multiblock.work_paused");
25+
}
26+
}

src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityMiner.java

Lines changed: 90 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
import gregtech.api.capability.impl.EnergyContainerHandler;
88
import gregtech.api.capability.impl.NotifiableItemStackHandler;
99
import gregtech.api.capability.impl.miner.MinerLogic;
10-
import gregtech.api.gui.GuiTextures;
11-
import gregtech.api.gui.ModularUI;
12-
import gregtech.api.gui.widgets.AdvancedTextWidget;
13-
import gregtech.api.gui.widgets.SlotWidget;
1410
import gregtech.api.items.itemhandlers.GTItemStackHandler;
1511
import gregtech.api.metatileentity.IDataInfoProvider;
1612
import gregtech.api.metatileentity.MetaTileEntity;
1713
import gregtech.api.metatileentity.TieredMetaTileEntity;
1814
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
15+
import gregtech.api.mui.GTGuiTextures;
16+
import gregtech.api.mui.GTGuis;
17+
import gregtech.api.mui.TextStandards;
18+
import gregtech.api.util.KeyUtil;
1919
import gregtech.client.renderer.texture.Textures;
2020
import gregtech.core.sound.GTSoundEvents;
2121

@@ -26,7 +26,6 @@
2626
import net.minecraft.network.PacketBuffer;
2727
import net.minecraft.util.*;
2828
import net.minecraft.util.text.ITextComponent;
29-
import net.minecraft.util.text.Style;
3029
import net.minecraft.util.text.TextComponentTranslation;
3130
import net.minecraft.util.text.TextFormatting;
3231
import net.minecraft.world.World;
@@ -40,6 +39,15 @@
4039
import codechicken.lib.render.CCRenderState;
4140
import codechicken.lib.render.pipeline.IVertexOperation;
4241
import codechicken.lib.vec.Matrix4;
42+
import com.cleanroommc.modularui.api.drawable.IKey;
43+
import com.cleanroommc.modularui.factory.PosGuiData;
44+
import com.cleanroommc.modularui.screen.ModularPanel;
45+
import com.cleanroommc.modularui.screen.UISettings;
46+
import com.cleanroommc.modularui.value.sync.BooleanSyncValue;
47+
import com.cleanroommc.modularui.value.sync.IntSyncValue;
48+
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
49+
import com.cleanroommc.modularui.widgets.SlotGroupWidget;
50+
import com.cleanroommc.modularui.widgets.slot.ItemSlot;
4351
import org.jetbrains.annotations.NotNull;
4452
import org.jetbrains.annotations.Nullable;
4553

@@ -96,69 +104,85 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation,
96104
}
97105

98106
@Override
99-
protected ModularUI createUI(@NotNull EntityPlayer entityPlayer) {
100-
int rowSize = (int) Math.sqrt(inventorySize);
101-
ModularUI.Builder builder = new ModularUI.Builder(GuiTextures.BACKGROUND, 195, 176);
102-
builder.bindPlayerInventory(entityPlayer.inventory, 94);
103-
104-
if (getTier() == GTValues.HV) {
105-
for (int y = 0; y < rowSize; y++) {
106-
for (int x = 0; x < rowSize; x++) {
107-
int index = y * rowSize + x;
108-
builder.widget(
109-
new SlotWidget(exportItems, index, 151 - rowSize * 9 + x * 18, 18 + y * 18, true, false)
110-
.setBackgroundTexture(GuiTextures.SLOT));
111-
}
112-
}
113-
} else {
114-
for (int y = 0; y < rowSize; y++) {
115-
for (int x = 0; x < rowSize; x++) {
116-
int index = y * rowSize + x;
117-
builder.widget(
118-
new SlotWidget(exportItems, index, 142 - rowSize * 9 + x * 18, 18 + y * 18, true, false)
119-
.setBackgroundTexture(GuiTextures.SLOT));
120-
}
121-
}
122-
}
123-
124-
builder.image(7, 16, 105, 75, GuiTextures.DISPLAY)
125-
.label(6, 6, getMetaFullName());
126-
builder.widget(new AdvancedTextWidget(10, 19, this::addDisplayText, 0xFFFFFF)
127-
.setMaxWidthLimit(84));
128-
builder.widget(new AdvancedTextWidget(70, 19, this::addDisplayText2, 0xFFFFFF)
129-
.setMaxWidthLimit(84));
130-
builder.widget(new SlotWidget(chargerInventory, 0, 171, 152)
131-
.setBackgroundTexture(GuiTextures.SLOT, GuiTextures.CHARGER_OVERLAY));
132-
133-
return builder.build(getHolder(), entityPlayer);
134-
}
135-
136-
private void addDisplayText(@NotNull List<ITextComponent> textList) {
137-
int workingArea = getWorkingArea(minerLogic.getCurrentRadius());
138-
textList.add(new TextComponentTranslation("gregtech.machine.miner.startx", this.minerLogic.getX().get()));
139-
textList.add(new TextComponentTranslation("gregtech.machine.miner.starty", this.minerLogic.getY().get()));
140-
textList.add(new TextComponentTranslation("gregtech.machine.miner.startz", this.minerLogic.getZ().get()));
141-
textList.add(new TextComponentTranslation("gregtech.machine.miner.working_area", workingArea, workingArea));
142-
if (this.minerLogic.isDone())
143-
textList.add(new TextComponentTranslation("gregtech.machine.miner.done")
144-
.setStyle(new Style().setColor(TextFormatting.GREEN)));
145-
else if (this.minerLogic.isWorking())
146-
textList.add(new TextComponentTranslation("gregtech.machine.miner.working")
147-
.setStyle(new Style().setColor(TextFormatting.GOLD)));
148-
else if (!this.isWorkingEnabled())
149-
textList.add(new TextComponentTranslation("gregtech.multiblock.work_paused"));
150-
if (isInventoryFull)
151-
textList.add(new TextComponentTranslation("gregtech.machine.miner.invfull")
152-
.setStyle(new Style().setColor(TextFormatting.RED)));
153-
if (!drainEnergy(true))
154-
textList.add(new TextComponentTranslation("gregtech.machine.miner.needspower")
155-
.setStyle(new Style().setColor(TextFormatting.RED)));
107+
public boolean usesMui2() {
108+
return true;
156109
}
157110

158-
private void addDisplayText2(@NotNull List<ITextComponent> textList) {
159-
textList.add(new TextComponentTranslation("gregtech.machine.miner.minex", this.minerLogic.getMineX().get()));
160-
textList.add(new TextComponentTranslation("gregtech.machine.miner.miney", this.minerLogic.getMineY().get()));
161-
textList.add(new TextComponentTranslation("gregtech.machine.miner.minez", this.minerLogic.getMineZ().get()));
111+
@SuppressWarnings("DuplicatedCode")
112+
@Override
113+
public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager panelSyncManager, UISettings settings) {
114+
IntSyncValue radiusSync = new IntSyncValue(() -> getWorkingArea(minerLogic.getCurrentRadius()));
115+
BooleanSyncValue isDoneSync = new BooleanSyncValue(minerLogic::isDone);
116+
BooleanSyncValue isWorkingSync = new BooleanSyncValue(minerLogic::isWorking);
117+
BooleanSyncValue isWorkingEnabledSync = new BooleanSyncValue(minerLogic::isWorkingEnabled);
118+
BooleanSyncValue isInventoryFullSync = new BooleanSyncValue(() -> isInventoryFull);
119+
BooleanSyncValue hasEnoughEnergySync = new BooleanSyncValue(() -> drainEnergy(true));
120+
panelSyncManager.syncValue("radius", 0, radiusSync);
121+
panelSyncManager.syncValue("done", 0, isDoneSync);
122+
panelSyncManager.syncValue("working", 0, isWorkingSync);
123+
panelSyncManager.syncValue("workingEnabled", 0, isWorkingEnabledSync);
124+
panelSyncManager.syncValue("inventoryFull", 0, isInventoryFullSync);
125+
panelSyncManager.syncValue("enoughEnergy", 0, hasEnoughEnergySync);
126+
127+
IntSyncValue xPosSync = new IntSyncValue(() -> minerLogic.getMineX().get());
128+
IntSyncValue yPosSync = new IntSyncValue(() -> minerLogic.getMineY().get());
129+
IntSyncValue zPosSync = new IntSyncValue(() -> minerLogic.getMineZ().get());
130+
panelSyncManager.syncValue("xPos", 0, xPosSync);
131+
panelSyncManager.syncValue("yPos", 0, yPosSync);
132+
panelSyncManager.syncValue("zPos", 0, zPosSync);
133+
134+
return GTGuis.createPanel(this, 197, 176)
135+
.child(IKey.lang(getMetaFullName())
136+
.asWidget()
137+
.pos(5, 5))
138+
.child(createMinerWidgets(panelSyncManager, exportItems, inventorySize, GTGuiTextures.DISPLAY, text -> {
139+
boolean isDone = isDoneSync.getBoolValue();
140+
boolean isWorking = isWorkingSync.getBoolValue();
141+
boolean isWorkingEnabled = isWorkingEnabledSync.getBoolValue();
142+
boolean isInventoryFull = isInventoryFullSync.getBoolValue();
143+
boolean hasEnoughEnergy = hasEnoughEnergySync.getBoolValue();
144+
145+
if (isWorking) {
146+
text.addLine(KeyUtil.lang(TextFormatting.WHITE, "gregtech.machine.miner.mining_at"));
147+
text.addLine(KeyUtil.lang(TextFormatting.WHITE, "gregtech.machine.miner.mining_pos_x",
148+
xPosSync.getIntValue()));
149+
text.addLine(KeyUtil.lang(TextFormatting.WHITE, "gregtech.machine.miner.mining_pos_y",
150+
yPosSync.getIntValue()));
151+
text.addLine(KeyUtil.lang(TextFormatting.WHITE, "gregtech.machine.miner.mining_pos_z",
152+
zPosSync.getIntValue()));
153+
}
154+
155+
text.addLine(KeyUtil.lang(TextFormatting.WHITE, "gregtech.machine.miner.working_area",
156+
radiusSync.getIntValue(), radiusSync.getIntValue()));
157+
158+
if (isDone) {
159+
text.addLine(KeyUtil.lang(TextStandards.Colors.MACHINE_DONE, "gregtech.machine.miner.done"));
160+
} else if (isWorking) {
161+
text.addLine(KeyUtil.lang(TextStandards.Colors.MACHINE_WORKING,
162+
"gregtech.machine.miner.working"));
163+
} else if (!isWorkingEnabled) {
164+
text.addLine(TextStandards.Keys.MACHINE_PAUSED);
165+
}
166+
167+
if (isInventoryFull) {
168+
text.addLine(KeyUtil.lang(TextStandards.Colors.NO_OUTPUT_SPACE,
169+
"gregtech.machine.miner.invfull"));
170+
}
171+
172+
if (!hasEnoughEnergy) {
173+
text.addLine(KeyUtil.lang(TextStandards.Colors.NO_POWER, "gregtech.machine.miner.needspower"));
174+
}
175+
})
176+
.left(10)
177+
.top(18))
178+
.child(SlotGroupWidget.playerInventory(false)
179+
.left(7)
180+
.bottom(7))
181+
.child(new ItemSlot()
182+
.right(7)
183+
.bottom(7)
184+
.slot(chargerInventory, 0)
185+
.background(GTGuiTextures.SLOT, GTGuiTextures.CHARGER_OVERLAY));
162186
}
163187

164188
@Override

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,11 @@ protected void configureDisplayText(MultiblockUIBuilder builder) {
270270
int workingArea = syncer.syncInt(getWorkingArea(minerLogic.getCurrentRadius()));
271271

272272
list.add(KeyUtil.lang(TextFormatting.GRAY, "gregtech.machine.miner.mining_at"));
273-
list.add(KeyUtil.lang(TextFormatting.GRAY, "gregtech.machine.miner.mining_pos",
274-
syncer.syncInt(minerLogic.getMineX().get()),
275-
syncer.syncInt(minerLogic.getMineY().get()),
273+
list.add(KeyUtil.lang(TextFormatting.GRAY, "gregtech.machine.miner.mining_pos_x",
274+
syncer.syncInt(minerLogic.getMineX().get())));
275+
list.add(KeyUtil.lang(TextFormatting.GRAY, "gregtech.machine.miner.mining_pos_y",
276+
syncer.syncInt(minerLogic.getMineY().get())));
277+
list.add(KeyUtil.lang(TextFormatting.GRAY, "gregtech.machine.miner.mining_pos_z",
276278
syncer.syncInt(minerLogic.getMineZ().get())));
277279

278280
if (syncer.syncBoolean(minerLogic.isChunkMode())) {

0 commit comments

Comments
 (0)