Skip to content

Commit 51e68c1

Browse files
committed
Mostly working multi miner port
1 parent 9ee8b2c commit 51e68c1

File tree

4 files changed

+71
-84
lines changed

4 files changed

+71
-84
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ protected void addDisplayText(List<ITextComponent> textList) {
383383
*/
384384
protected void handleDisplayClick(String componentData, ClickData clickData) {}
385385

386+
@Deprecated
386387
protected ModularUI.Builder createUITemplate(EntityPlayer entityPlayer) {
387388
ModularUI.Builder builder = ModularUI.builder(GuiTextures.BACKGROUND, 198, 208);
388389

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,8 @@ public static class IDs {
427427
"textures/gui/widget/button_no_distinct_buses.png", true);
428428
public static final UITexture BUTTON_NO_FLEX = fullImage("textures/gui/widget/button_no_flex.png", true);
429429
public static final UITexture BUTTON_MULTI_MAP = fullImage("textures/gui/widget/button_multi_map.png", true);
430-
public static final UITexture BUTTON_MINER_MODES = fullImage("textures/gui/widget/button_miner_modes.png", true);
430+
public static final UITexture[] BUTTON_MINER_MODES = slice("textures/gui/widget/button_miner_modes.png", 18, 72, 18,
431+
18, true);
431432
public static final UITexture BUTTON_THROTTLE_MINUS = fullImage("textures/gui/widget/button_throttle_minus.png",
432433
true); // TODO new texture
433434
public static final UITexture BUTTON_THROTTLE_PLUS = fullImage("textures/gui/widget/button_throttle_plus.png",

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

Lines changed: 66 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@
77
import gregtech.api.capability.impl.ItemHandlerList;
88
import gregtech.api.capability.impl.miner.MultiblockMinerLogic;
99
import gregtech.api.gui.GuiTextures;
10-
import gregtech.api.gui.ModularUI;
1110
import gregtech.api.gui.Widget;
12-
import gregtech.api.gui.widgets.AdvancedTextWidget;
1311
import gregtech.api.gui.widgets.ImageCycleButtonWidget;
1412
import gregtech.api.items.itemhandlers.GTItemStackHandler;
1513
import gregtech.api.metatileentity.IDataInfoProvider;
1614
import gregtech.api.metatileentity.MetaTileEntity;
1715
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
1816
import gregtech.api.metatileentity.multiblock.IMultiblockPart;
1917
import gregtech.api.metatileentity.multiblock.MultiblockAbility;
20-
import gregtech.api.metatileentity.multiblock.MultiblockDisplayText;
2118
import gregtech.api.metatileentity.multiblock.MultiblockWithDisplayBase;
19+
import gregtech.api.metatileentity.multiblock.ui.MultiblockUIFactory;
20+
import gregtech.api.mui.GTGuiTextures;
2221
import gregtech.api.pattern.BlockPattern;
2322
import gregtech.api.pattern.FactoryBlockPattern;
2423
import gregtech.api.pattern.PatternMatchContext;
@@ -27,7 +26,7 @@
2726
import gregtech.api.unification.material.Material;
2827
import gregtech.api.unification.material.Materials;
2928
import gregtech.api.util.GTUtility;
30-
import gregtech.api.util.TextComponentUtil;
29+
import gregtech.api.util.KeyUtil;
3130
import gregtech.client.renderer.ICubeRenderer;
3231
import gregtech.client.renderer.texture.Textures;
3332
import gregtech.common.blocks.BlockMetalCasing;
@@ -57,6 +56,9 @@
5756
import codechicken.lib.render.CCRenderState;
5857
import codechicken.lib.render.pipeline.IVertexOperation;
5958
import codechicken.lib.vec.Matrix4;
59+
import com.cleanroommc.modularui.api.drawable.IKey;
60+
import com.cleanroommc.modularui.value.sync.IntSyncValue;
61+
import com.cleanroommc.modularui.widgets.CycleButtonWidget;
6062
import com.google.common.collect.Lists;
6163
import org.jetbrains.annotations.NotNull;
6264
import org.jetbrains.annotations.Nullable;
@@ -232,79 +234,75 @@ public void addToolUsages(ItemStack stack, @Nullable World world, List<String> t
232234
}
233235

234236
@Override
235-
protected void addDisplayText(List<ITextComponent> textList) {
236-
super.addDisplayText(textList);
237+
protected MultiblockUIFactory createUIFactory() {
238+
return super.createUIFactory()
239+
.createFlexButton((posGuiData, panelSyncManager) -> {
240+
IntSyncValue buttonSync = new IntSyncValue(this::getCurrentMode, this::setCurrentMode);
237241

238-
if (this.isStructureFormed()) {
239-
if (energyContainer != null && energyContainer.getEnergyCapacity() > 0) {
240-
int energyContainer = getEnergyTier();
241-
long maxVoltage = GTValues.V[energyContainer];
242-
String voltageName = GTValues.VNF[energyContainer];
243-
textList.add(new TextComponentTranslation("gregtech.multiblock.max_energy_per_tick", maxVoltage,
244-
voltageName));
245-
}
246-
247-
int workingAreaChunks = this.minerLogic.getCurrentRadius() * 2 / CHUNK_LENGTH;
248-
int workingArea = getWorkingArea(minerLogic.getCurrentRadius());
249-
textList.add(new TextComponentTranslation("gregtech.machine.miner.startx",
250-
this.minerLogic.getX().get() == Integer.MAX_VALUE ? 0 : this.minerLogic.getX().get()));
251-
textList.add(new TextComponentTranslation("gregtech.machine.miner.starty",
252-
this.minerLogic.getY().get() == Integer.MAX_VALUE ? 0 : this.minerLogic.getY().get()));
253-
textList.add(new TextComponentTranslation("gregtech.machine.miner.startz",
254-
this.minerLogic.getZ().get() == Integer.MAX_VALUE ? 0 : this.minerLogic.getZ().get()));
255-
if (this.minerLogic.isChunkMode()) {
256-
textList.add(new TextComponentTranslation("gregtech.machine.miner.working_area_chunks",
257-
workingAreaChunks, workingAreaChunks));
258-
} else {
259-
textList.add(
260-
new TextComponentTranslation("gregtech.machine.miner.working_area", workingArea, workingArea));
261-
}
262-
if (this.minerLogic.isDone())
263-
textList.add(new TextComponentTranslation("gregtech.machine.miner.done")
264-
.setStyle(new Style().setColor(TextFormatting.GREEN)));
265-
else if (this.minerLogic.isWorking())
266-
textList.add(new TextComponentTranslation("gregtech.machine.miner.working")
267-
.setStyle(new Style().setColor(TextFormatting.GOLD)));
268-
else if (!this.isWorkingEnabled())
269-
textList.add(new TextComponentTranslation("gregtech.multiblock.work_paused"));
270-
}
271-
}
272-
273-
private void addDisplayText2(List<ITextComponent> textList) {
274-
if (this.isStructureFormed()) {
275-
ITextComponent mCoords = new TextComponentString(" ")
276-
.appendSibling(new TextComponentTranslation("gregtech.machine.miner.minex",
277-
this.minerLogic.getMineX().get()))
278-
.appendText("\n ")
279-
.appendSibling(new TextComponentTranslation("gregtech.machine.miner.miney",
280-
this.minerLogic.getMineY().get()))
281-
.appendText("\n ")
282-
.appendSibling(new TextComponentTranslation("gregtech.machine.miner.minez",
283-
this.minerLogic.getMineZ().get()));
284-
textList.add(mCoords);
285-
}
242+
return new CycleButtonWidget()
243+
.stateCount(4)
244+
.value(buttonSync)
245+
.addTooltip(0, IKey.lang("gregtech.multiblock.miner.neither_mode"))
246+
.addTooltip(1, IKey.lang("gregtech.multiblock.miner.chunk_mode"))
247+
.addTooltip(2, IKey.lang("gregtech.multiblock.miner.silk_touch_mode"))
248+
.addTooltip(3, IKey.lang("gregtech.multiblock.miner.both_modes"))
249+
.stateBackground(0, GTGuiTextures.BUTTON_MINER_MODES[0])
250+
.stateBackground(1, GTGuiTextures.BUTTON_MINER_MODES[1])
251+
.stateBackground(2, GTGuiTextures.BUTTON_MINER_MODES[2])
252+
.stateBackground(3, GTGuiTextures.BUTTON_MINER_MODES[3]);
253+
});
286254
}
287255

288256
@Override
289-
protected void addWarningText(List<ITextComponent> textList) {
290-
MultiblockDisplayText.builder(textList, isStructureFormed(), false)
291-
.addLowPowerLine(isStructureFormed() && !drainEnergy(true))
292-
.addCustom(tl -> {
293-
if (isStructureFormed() && isInventoryFull) {
294-
tl.add(TextComponentUtil.translationWithColor(
295-
TextFormatting.YELLOW,
296-
"gregtech.machine.miner.invfull"));
257+
protected void configureDisplayText(MultiblockUIFactory.Builder builder) {
258+
builder.setWorkingStatus(minerLogic.isWorkingEnabled(), minerLogic.isActive())
259+
.addEnergyUsageLine(energyContainer)
260+
.addCustom(list -> {
261+
if (isStructureFormed()) {
262+
int workingAreaChunks = this.minerLogic.getCurrentRadius() * 2 / CHUNK_LENGTH;
263+
int workingArea = getWorkingArea(minerLogic.getCurrentRadius());
264+
265+
list.add(KeyUtil.lang(TextFormatting.GRAY, "gregtech.machine.miner.mining_at"));
266+
list.add(KeyUtil.lang(TextFormatting.GRAY, "gregtech.machine.miner.mining_pos",
267+
minerLogic.getX().get(), minerLogic.getY().get(), minerLogic.getZ().get()));
268+
269+
if (minerLogic.isChunkMode()) {
270+
list.add(KeyUtil.lang(TextFormatting.GRAY, "gregtech.machine.miner.working_area_chunks",
271+
workingAreaChunks,
272+
workingAreaChunks));
273+
} else {
274+
list.add(KeyUtil.lang(TextFormatting.GRAY, "gregtech.machine.miner.working_area",
275+
workingArea, workingArea));
276+
}
277+
278+
if (minerLogic.isDone()) {
279+
list.add(KeyUtil.lang(TextFormatting.GREEN, "gregtech.machine.miner.done"));
280+
} else if (minerLogic.isWorking()) {
281+
list.add(KeyUtil.lang(TextFormatting.GOLD, "gregtech.machine.miner.working"));
282+
} else if (!isWorkingEnabled()) {
283+
list.add(KeyUtil.lang(TextFormatting.GRAY, "gregtech.multiblock.work_paused"));
284+
}
297285
}
298286
});
299287
}
300288

301289
@Override
302-
protected void addErrorText(List<ITextComponent> textList) {
303-
super.addErrorText(textList);
304-
if (isStructureFormed() && !drainFluid(true)) {
305-
textList.add(TextComponentUtil.translationWithColor(TextFormatting.RED,
306-
"gregtech.machine.miner.multi.needsfluid"));
307-
}
290+
protected void configureErrorText(MultiblockUIFactory.Builder builder) {
291+
builder.addCustom(list -> {
292+
if (isStructureFormed() && !drainFluid(false)) {
293+
list.add(KeyUtil.lang(TextFormatting.RED, "gregtech.machine.miner.multi.needsfluid"));
294+
}
295+
});
296+
}
297+
298+
@Override
299+
protected void configureWarningText(MultiblockUIFactory.Builder builder) {
300+
builder.addLowPowerLine(!drainEnergy(true));
301+
builder.addCustom(list -> {
302+
if (isStructureFormed() && isInventoryFull) {
303+
list.add(KeyUtil.lang(TextFormatting.YELLOW, "gregtech.machine.miner.invfull"));
304+
}
305+
});
308306
}
309307

310308
public IBlockState getCasingState() {
@@ -383,14 +381,6 @@ public long getMaxVoltage() {
383381
return GTValues.V[GTUtility.getTierByVoltage(energyContainer.getInputVoltage())];
384382
}
385383

386-
@Override
387-
protected ModularUI.Builder createUITemplate(EntityPlayer entityPlayer) {
388-
ModularUI.Builder builder = super.createUITemplate(entityPlayer);
389-
builder.widget(new AdvancedTextWidget(63, 31, this::addDisplayText2, 0xFFFFFF)
390-
.setMaxWidthLimit(68).setClickHandler(this::handleDisplayClick));
391-
return builder;
392-
}
393-
394384
// used for UI
395385
private int getCurrentMode() {
396386
// 0 -> not chunk mode, not silk touch mode

src/main/resources/assets/gregtech/lang/en_us.lang

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4866,13 +4866,8 @@ gregtech.machine.miner.multi.production=Produces §f3x§7 more crushed ore than
48664866
gregtech.machine.miner.fluid_usage=Uses §f%,d L/t §7of §f%s§7, doubled per overclock.
48674867
gregtech.machine.miner.multi.description=A multiblock mining machine that covers a large area and produces huge quantity of ore.
48684868
gregtech.machine.miner.multi.needsfluid=No Drilling Fluid!
4869-
4870-
gregtech.machine.miner.startx=sX: %d
4871-
gregtech.machine.miner.starty=sY: %d
4872-
gregtech.machine.miner.startz=sZ: %d
4873-
gregtech.machine.miner.minex=mX: %d
4874-
gregtech.machine.miner.miney=mY: %d
4875-
gregtech.machine.miner.minez=mZ: %d
4869+
gregtech.machine.miner.mining_at=Currently mining at:
4870+
gregtech.machine.miner.mining_pos=X: %s Y: %s Z: %s
48764871
gregtech.machine.miner.radius=Radius: %d
48774872
gregtech.machine.miner.working_area=Working Area: %dx%d blocks
48784873
gregtech.machine.miner.working_area_chunks=Working Area: %dx%d chunks

0 commit comments

Comments
 (0)