Skip to content

Commit c214f00

Browse files
authored
Port Covers to Mui2 Part 2 (GregTechCEu#2700)
1 parent 8182590 commit c214f00

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1029
-813
lines changed

src/main/java/gregtech/api/cover/CoverUIFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
import net.minecraft.util.EnumFacing;
1414
import net.minecraft.util.math.BlockPos;
1515

16+
import org.jetbrains.annotations.ApiStatus;
17+
1618
@Deprecated
19+
@ApiStatus.ScheduledForRemoval(inVersion = "2.10")
1720
public final class CoverUIFactory extends UIFactory<CoverWithUI> {
1821

1922
public static final CoverUIFactory INSTANCE = new CoverUIFactory();

src/main/java/gregtech/api/cover/CoverWithUI.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package gregtech.api.cover;
22

3-
import gregtech.api.gui.IUIHolder;
4-
import gregtech.api.gui.ModularUI;
53
import gregtech.api.mui.GTGuiTextures;
64
import gregtech.api.mui.GTGuiTheme;
75
import gregtech.api.mui.GregTechGuiScreen;
@@ -17,6 +15,7 @@
1715
import com.cleanroommc.modularui.api.IGuiHolder;
1816
import com.cleanroommc.modularui.api.drawable.IDrawable;
1917
import com.cleanroommc.modularui.api.drawable.IKey;
18+
import com.cleanroommc.modularui.drawable.DynamicDrawable;
2019
import com.cleanroommc.modularui.drawable.ItemDrawable;
2120
import com.cleanroommc.modularui.factory.SidedPosGuiData;
2221
import com.cleanroommc.modularui.screen.ModularPanel;
@@ -30,30 +29,36 @@
3029
import com.cleanroommc.modularui.value.sync.IntSyncValue;
3130
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
3231
import com.cleanroommc.modularui.widget.ParentWidget;
32+
import com.cleanroommc.modularui.widget.Widget;
3333
import com.cleanroommc.modularui.widgets.ToggleButton;
3434
import com.cleanroommc.modularui.widgets.layout.Flow;
3535
import org.jetbrains.annotations.ApiStatus;
3636
import org.jetbrains.annotations.NotNull;
3737

3838
import java.util.function.BooleanSupplier;
39+
import java.util.function.Supplier;
3940

40-
public interface CoverWithUI extends Cover, IUIHolder, IGuiHolder<SidedPosGuiData> {
41+
public interface CoverWithUI extends Cover, IGuiHolder<SidedPosGuiData>, gregtech.api.gui.IUIHolder {
4142

4243
@ApiStatus.Experimental
4344
default boolean usesMui2() {
44-
return false;
45+
// this is gonna cause problems if implementing classes expect this to be false
46+
// all of our covers use mui2 though
47+
return true;
4548
}
4649

4750
default void openUI(EntityPlayerMP player) {
4851
if (usesMui2()) {
4952
CoverGuiFactory.open(player, this);
5053
} else {
54+
// todo remove in 2.10
5155
CoverUIFactory.INSTANCE.openUI(this, player);
5256
}
5357
}
5458

5559
@Deprecated
56-
default ModularUI createUI(EntityPlayer player) {
60+
@ApiStatus.ScheduledForRemoval(inVersion = "2.10")
61+
default gregtech.api.gui.ModularUI createUI(EntityPlayer player) {
5762
return null;
5863
}
5964

@@ -104,11 +109,22 @@ default void markAsDirty() {
104109
* Create the Title bar widget for a Cover.
105110
*/
106111
static Flow createTitleRow(ItemStack stack) {
112+
return createTitleRow(() -> stack);
113+
}
114+
115+
/**
116+
* Create the Title bar widget for a Cover.
117+
*/
118+
static Flow createTitleRow(Supplier<ItemStack> stack) {
119+
ItemDrawable itemDrawable = new ItemDrawable();
107120
return Flow.row()
108121
.pos(4, 4)
109122
.height(16).coverChildrenWidth()
110-
.child(new ItemDrawable(stack).asWidget().size(16).marginRight(4))
111-
.child(IKey.str(stack.getDisplayName())
123+
.child(new Widget<>()
124+
.overlay(new DynamicDrawable(() -> itemDrawable.setItem(stack.get())))
125+
.size(16)
126+
.marginRight(4))
127+
.child(IKey.dynamic(() -> stack.get().getDisplayName())
112128
.color(UI_TITLE_COLOR)
113129
.asWidget().heightRel(1.0f));
114130
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,22 @@ private static String id(String path) {
458458
public static final UITexture RESEARCH_STATION_OVERLAY = fullImage(
459459
"textures/gui/overlay/research_station_overlay.png", ColorType.DEFAULT);
460460

461+
// Texture Areas
462+
public static final UITexture[] BUTTON_FLUID = slice("textures/blocks/cover/cover_interface_fluid_button.png", 18,
463+
36, null);
464+
public static final UITexture[] BUTTON_ITEM = slice("textures/blocks/cover/cover_interface_item_button.png", 18, 36,
465+
null);
466+
public static final UITexture[] BUTTON_ENERGY = slice("textures/blocks/cover/cover_interface_energy_button.png", 18,
467+
36, null);
468+
public static final UITexture[] BUTTON_MACHINE = slice("textures/blocks/cover/cover_interface_machine_button.png",
469+
18, 36, null);
470+
public static final UITexture[] BUTTON_INTERFACE = slice(
471+
"textures/blocks/cover/cover_interface_computer_button.png", 18, 36, null);
472+
public static final UITexture COVER_INTERFACE_MACHINE_ON_PROXY = fullImage(
473+
"textures/blocks/cover/cover_interface_machine_on_proxy.png");
474+
public static final UITexture COVER_INTERFACE_MACHINE_OFF_PROXY = fullImage(
475+
"textures/blocks/cover/cover_interface_machine_off_proxy.png");
476+
461477
// BUTTONS
462478

463479
public static final UITexture BUTTON = new UITexture.Builder()

src/main/java/gregtech/api/mui/sync/GTFluidSyncHandler.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ public void handleClick(MouseData data) {
304304
public void readOnServer(int id, PacketBuffer buf) {
305305
if (id == TRY_CLICK_CONTAINER) {
306306
var data = MouseData.readPacket(buf);
307+
if (canLockFluid())
308+
toggleLockFluid();
307309
if (isPhantom()) {
308310
tryClickPhantom(data);
309311
} else {
@@ -316,14 +318,6 @@ public void readOnServer(int id, PacketBuffer buf) {
316318
setFluid(fluid);
317319
} else if (id == PHANTOM_SCROLL) {
318320
tryScrollPhantom(MouseData.readPacket(buf));
319-
} else if (id == LOCK_FLUID) {
320-
boolean locked = buf.readBoolean();
321-
var fluidStack = NetworkUtils.readFluidStack(buf);
322-
if (fluidStack == null) {
323-
this.lockHandler.accept(locked);
324-
} else {
325-
this.jeiHandler.accept(fluidStack);
326-
}
327321
}
328322
}
329323

@@ -341,19 +335,26 @@ public void tryClickPhantom(MouseData data) {
341335
}
342336
} else {
343337
FluidStack cellFluid = fluidHandlerItem.drain(Integer.MAX_VALUE, false);
344-
if ((this.showAmountOnSlot.getAsBoolean() || currentFluid == null) && cellFluid != null) {
338+
if (!GTUtility.areFluidStacksEqual(cellFluid, currentFluid)) {
339+
340+
// drain existing
341+
if (this.canDrainSlot()) {
342+
int amt = data.shift ? Integer.MAX_VALUE : 1000;
343+
this.tank.drain(amt, true);
344+
}
345+
346+
// then fill
345347
if (this.canFillSlot()) {
346-
if (!this.showAmountOnSlot.getAsBoolean()) {
347-
cellFluid.amount = 1;
348+
FluidStack fill;
349+
if (this.showAmountOnSlot.getAsBoolean() && !GTUtility.isEmpty(cellFluid)) {
350+
fill = GTUtility.copy(cellFluid);
351+
} else {
352+
fill = GTUtility.copy(1, cellFluid);
348353
}
349-
if (this.tank.fill(cellFluid, true) > 0) {
350-
this.phantomFluid = cellFluid.copy();
354+
if (fill == null || this.tank.fill(fill, true) > 0) {
355+
this.phantomFluid = fill;
351356
}
352357
}
353-
} else {
354-
if (this.canDrainSlot()) {
355-
this.tank.drain(data.shift ? Integer.MAX_VALUE : 1000, true);
356-
}
357358
}
358359
}
359360
}

src/main/java/gregtech/api/util/virtualregistry/VirtualEnderRegistry.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import net.minecraft.world.World;
88
import net.minecraft.world.storage.MapStorage;
99
import net.minecraft.world.storage.WorldSavedData;
10-
import net.minecraftforge.fluids.IFluidTank;
1110

1211
import org.jetbrains.annotations.NotNull;
1312
import org.jetbrains.annotations.Nullable;
@@ -91,18 +90,6 @@ private static VirtualRegistryMap getRegistry(UUID owner) {
9190
return VIRTUAL_REGISTRIES.computeIfAbsent(owner, key -> new VirtualRegistryMap());
9291
}
9392

94-
// remove if tank app is removed
95-
public static Map<UUID, Map<String, IFluidTank>> createTankMap() {
96-
Map<UUID, Map<String, IFluidTank>> map = new HashMap<>();
97-
for (var uuid : VIRTUAL_REGISTRIES.keySet()) {
98-
map.put(uuid, new HashMap<>());
99-
for (var name : getEntryNames(uuid, EntryTypes.ENDER_FLUID)) {
100-
map.get(uuid).put(name, getEntry(uuid, EntryTypes.ENDER_FLUID, name));
101-
}
102-
}
103-
return map;
104-
}
105-
10693
@Override
10794
public final void readFromNBT(NBTTagCompound nbt) {
10895
if (nbt.hasKey(PUBLIC_KEY)) {

src/main/java/gregtech/api/util/virtualregistry/VirtualRegistryMap.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.jetbrains.annotations.NotNull;
77
import org.jetbrains.annotations.Nullable;
88

9+
import java.util.Collections;
910
import java.util.HashMap;
1011
import java.util.Map;
1112
import java.util.Set;
@@ -49,7 +50,7 @@ public void clear() {
4950
}
5051

5152
public Set<String> getEntryNames(EntryTypes<?> type) {
52-
return registryMap.get(type).keySet();
53+
return registryMap.getOrDefault(type, Collections.emptyMap()).keySet();
5354
}
5455

5556
@Override

src/main/java/gregtech/common/covers/CoverConveyor.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import gregtech.client.renderer.texture.Textures;
1616
import gregtech.client.renderer.texture.cube.SimpleSidedCubeRenderer;
1717
import gregtech.common.covers.filter.ItemFilterContainer;
18+
import gregtech.common.mui.widget.GTTextFieldWidget;
1819
import gregtech.common.pipelike.itempipe.tile.TileEntityItemPipe;
1920

2021
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
@@ -53,11 +54,8 @@
5354
import com.cleanroommc.modularui.value.sync.EnumSyncValue;
5455
import com.cleanroommc.modularui.value.sync.IntSyncValue;
5556
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
56-
import com.cleanroommc.modularui.value.sync.StringSyncValue;
57-
import com.cleanroommc.modularui.widget.ParentWidget;
5857
import com.cleanroommc.modularui.widgets.ButtonWidget;
5958
import com.cleanroommc.modularui.widgets.layout.Flow;
60-
import com.cleanroommc.modularui.widgets.textfield.TextFieldWidget;
6159
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
6260
import it.unimi.dsi.fastutil.ints.IntArrayList;
6361
import it.unimi.dsi.fastutil.ints.IntList;
@@ -498,11 +496,6 @@ public <T> T getCapability(Capability<T> capability, T defaultValue) {
498496
return defaultValue;
499497
}
500498

501-
@Override
502-
public boolean usesMui2() {
503-
return true;
504-
}
505-
506499
@Override
507500
public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncManager, UISettings settings) {
508501
var panel = GTGuis.createPanel(this, 176, 192 + 18);
@@ -514,7 +507,7 @@ public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncMan
514507
.bindPlayerInventory();
515508
}
516509

517-
protected ParentWidget<Flow> createUI(GuiData data, PanelSyncManager guiSyncManager) {
510+
protected Flow createUI(GuiData data, PanelSyncManager guiSyncManager) {
518511
var column = Flow.column().top(24).margin(7, 0)
519512
.widthRel(1f).coverChildrenHeight();
520513

@@ -526,16 +519,12 @@ protected ParentWidget<Flow> createUI(GuiData data, PanelSyncManager guiSyncMana
526519

527520
IntSyncValue throughput = new IntSyncValue(this::getTransferRate, this::setTransferRate);
528521

529-
StringSyncValue formattedThroughput = new StringSyncValue(throughput::getStringValue,
530-
throughput::setStringValue);
531-
532522
EnumSyncValue<DistributionMode> distributionMode = new EnumSyncValue<>(DistributionMode.class,
533523
this::getDistributionMode, this::setDistributionMode);
534524

535525
guiSyncManager.syncValue("manual_io", manualIOmode);
536526
guiSyncManager.syncValue("conveyor_mode", conveyorMode);
537527
guiSyncManager.syncValue("distribution_mode", distributionMode);
538-
guiSyncManager.syncValue("throughput", throughput);
539528

540529
if (createThroughputRow())
541530
column.child(Flow.row().coverChildrenHeight()
@@ -548,11 +537,12 @@ protected ParentWidget<Flow> createUI(GuiData data, PanelSyncManager guiSyncMana
548537
return true;
549538
})
550539
.onUpdateListener(w -> w.overlay(createAdjustOverlay(false))))
551-
.child(new TextFieldWidget()
540+
.child(new GTTextFieldWidget()
552541
.left(18).right(18)
542+
.setPostFix(" items/s")
553543
.setTextColor(Color.WHITE.darker(1))
554544
.setNumbers(1, maxItemTransferRate)
555-
.value(formattedThroughput)
545+
.value(throughput)
556546
.background(GTGuiTextures.DISPLAY))
557547
.child(new ButtonWidget<>()
558548
.right(0).width(18)

0 commit comments

Comments
 (0)