Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to MUI2 RC3 #2702

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
dependencies {
// Published dependencies
api("codechicken:codechickenlib:3.2.3.358")
api("com.cleanroommc:modularui:2.5.0-rc2") { transitive = false }
api("com.cleanroommc:modularui:2.5.0-rc3") { transitive = false }
api("com.cleanroommc:groovyscript:1.2.0-hotfix1") { transitive = false }
api("CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.1.20.700")
api("appeng:ae2-uel:v0.56.4") { transitive = false }
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/gregtech/GregTechMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
acceptedMinecraftVersions = "[1.12.2,1.13)",
version = GTInternalTags.VERSION,
dependencies = "required:forge@[14.23.5.2847,);" + "required-after:codechickenlib@[3.2.3,);" +
"required-after:modularui@[2.3,);" + "required-after:mixinbooter@[8.0,);" + "after:appliedenergistics2;" +
"required-after:modularui@[2.5.0-rc,);" + "required-after:mixinbooter@[8.0,);" +
"after:appliedenergistics2;" +
"after:forestry;" + "after:extrabees;" + "after:extratrees;" + "after:genetics;" + "after:magicbees;" +
"after:jei@[4.15.0,);" + "after:crafttweaker@[4.1.20,);" + "after:groovyscript@[1.2.0,);" +
"after:theoneprobe;" + "after:hwyla;")
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/gregtech/api/mui/GTGuis.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import net.minecraft.item.ItemStack;

import com.cleanroommc.modularui.api.IPanelHandler;
import com.cleanroommc.modularui.factory.GuiManager;
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.utils.Alignment;
Expand Down Expand Up @@ -103,6 +104,9 @@ public PopupPanel(@NotNull String name, int width, int height, boolean disableBe
.onMousePressed(mouseButton -> {
if (mouseButton == 0 || mouseButton == 1) {
this.closeIfOpen(true);
if (isSynced() && getSyncHandler() instanceof IPanelHandler handler) {
handler.deleteCachedPanel();
}
return true;
}
return false;
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/gregtech/api/mui/LocaleAccessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package gregtech.api.mui;

import net.minecraft.client.resources.Locale;

// todo remove in next mui2 version
public interface LocaleAccessor {

String gregtech$getRawKey(String s);

ThreadLocal<LocaleAccessor> accessor = new ThreadLocal<>();

static String getRawKey(String s) {
if (accessor.get() == null) return s;
return accessor.get().gregtech$getRawKey(s);
}

static void setLocale(Locale locale) {
accessor.set((LocaleAccessor) locale);
}
}
22 changes: 0 additions & 22 deletions src/main/java/gregtech/api/mui/StateOverlay.java

This file was deleted.

8 changes: 0 additions & 8 deletions src/main/java/gregtech/api/mui/UnboxFix.java

This file was deleted.

5 changes: 2 additions & 3 deletions src/main/java/gregtech/api/mui/sync/GTFluidSyncHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ public GTFluidSyncHandler(IFluidTank tank) {
@Override
public void detectAndSendChanges(boolean init) {
var current = getFluid();
if (current == null && lastFluid == null) return;
if (current == null || lastFluid == null || lastFluid.getFluid() != current.getFluid()) {
if (init || current == null || lastFluid == null || current.isFluidEqual(lastFluid)) {
lastFluid = current == null ? null : current.copy();
syncToClient(UPDATE_TANK, buffer -> NetworkUtils.writeFluidStack(buffer, current));
} else if (current.amount != lastFluid.amount) {
} else if (lastFluid != null && current.amount != lastFluid.amount) {
lastFluid.amount = current.amount;
syncToClient(UPDATE_AMOUNT, buffer -> buffer.writeInt(current.amount));
}
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/gregtech/common/covers/CoverConveyor.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Matrix4;
import com.cleanroommc.modularui.api.drawable.IDrawable;
import com.cleanroommc.modularui.api.widget.Interactable;
import com.cleanroommc.modularui.drawable.DynamicDrawable;
import com.cleanroommc.modularui.factory.GuiData;
import com.cleanroommc.modularui.factory.SidedPosGuiData;
Expand Down Expand Up @@ -545,7 +544,6 @@ protected ParentWidget<Flow> createUI(GuiData data, PanelSyncManager guiSyncMana
.onMousePressed(mouseButton -> {
int val = throughput.getValue() - getIncrementValue(MouseData.create(mouseButton));
throughput.setValue(val, true, true);
Interactable.playButtonClickSound();
return true;
})
.onUpdateListener(w -> w.overlay(createAdjustOverlay(false))))
Expand All @@ -560,7 +558,6 @@ protected ParentWidget<Flow> createUI(GuiData data, PanelSyncManager guiSyncMana
.onMousePressed(mouseButton -> {
int val = throughput.getValue() + getIncrementValue(MouseData.create(mouseButton));
throughput.setValue(val, true, true);
Interactable.playButtonClickSound();
return true;
})
.onUpdateListener(w -> w.overlay(createAdjustOverlay(true)))));
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/gregtech/common/covers/CoverPump.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Matrix4;
import com.cleanroommc.modularui.api.drawable.IDrawable;
import com.cleanroommc.modularui.api.widget.Interactable;
import com.cleanroommc.modularui.drawable.DynamicDrawable;
import com.cleanroommc.modularui.factory.GuiData;
import com.cleanroommc.modularui.factory.SidedPosGuiData;
Expand Down Expand Up @@ -226,7 +225,6 @@ protected ParentWidget<?> createUI(GuiData data, PanelSyncManager syncManager) {
.onMousePressed(mouseButton -> {
int val = throughput.getValue() - getIncrementValue(MouseData.create(mouseButton));
throughput.setValue(val);
Interactable.playButtonClickSound();
return true;
})
.onUpdateListener(w -> w.overlay(createAdjustOverlay(false))))
Expand All @@ -241,7 +239,6 @@ protected ParentWidget<?> createUI(GuiData data, PanelSyncManager syncManager) {
.onMousePressed(mouseButton -> {
int val = throughput.getValue() + getIncrementValue(MouseData.create(mouseButton));
throughput.setValue(val);
Interactable.playButtonClickSound();
return true;
})
.onUpdateListener(w -> w.overlay(createAdjustOverlay(true)))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import codechicken.lib.raytracer.CuboidRayTraceResult;
import com.cleanroommc.modularui.api.drawable.IKey;
import com.cleanroommc.modularui.api.widget.IWidget;
import com.cleanroommc.modularui.api.widget.Interactable;
import com.cleanroommc.modularui.drawable.DynamicDrawable;
import com.cleanroommc.modularui.drawable.GuiTextures;
import com.cleanroommc.modularui.drawable.Rectangle;
Expand All @@ -50,8 +49,9 @@
import org.jetbrains.annotations.Nullable;
import org.lwjgl.input.Keyboard;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -149,8 +149,7 @@ public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncMan
protected Flow createWidgets(GuiData data, PanelSyncManager syncManager) {
var name = new StringSyncValue(this::getColorStr, this::updateColor);

// todo unneeded cast in mui2 rc3
var entrySelectorSH = (PanelSyncHandler) syncManager.panel("entry_selector", entrySelector(getType()), true);
var entrySelectorSH = syncManager.panel("entry_selector", entrySelector(getType()), true);

return Flow.column().coverChildrenHeight().top(24)
.margin(7, 0).widthRel(1f)
Expand All @@ -173,6 +172,7 @@ protected Flow createWidgets(GuiData data, PanelSyncManager syncManager) {
.onMousePressed(i -> {
if (entrySelectorSH.isPanelOpen()) {
entrySelectorSH.closePanel();
entrySelectorSH.deleteCachedPanel();
} else {
entrySelectorSH.openPanel();
}
Expand Down Expand Up @@ -284,14 +284,19 @@ public void writeToNBT(@NotNull NBTTagCompound nbt) {

protected PanelSyncHandler.IPanelBuilder entrySelector(EntryTypes<T> type) {
return (syncManager, syncHandler) -> {
Set<String> names = VirtualEnderRegistry.getEntryNames(getOwner(), type);
List<IWidget> rows = new ArrayList<>();
for (String name : VirtualEnderRegistry.getEntryNames(getOwner(), type)) {
rows.add(createRow(name, syncManager, type));
}
return GTGuis.createPopupPanel("entry_selector", 168, 112)
.child(IKey.lang("cover.generic.ender.known_channels")
.color(UI_TITLE_COLOR)
.asWidget()
.top(6)
.left(4))
.child(ListWidget.builder(names, name -> createRow(name, syncManager, type))
.child(new ListWidget<>()
.children(rows)
// .builder(names, name -> createRow(name, syncManager, type))
.background(GTGuiTextures.DISPLAY.asIcon()
.width(168 - 8)
.height(112 - 20))
Expand Down Expand Up @@ -391,7 +396,6 @@ protected IWidget createRow(final String name, final PanelSyncManager syncManage
getOwner() == null ? "null" : getOwner().toString());
NetworkUtils.writeStringSafe(buffer, name);
});
Interactable.playButtonClickSound();
return true;
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.items.ItemStackHandler;

import com.cleanroommc.modularui.api.IPanelHandler;
import com.cleanroommc.modularui.api.drawable.IKey;
import com.cleanroommc.modularui.api.widget.IWidget;
import com.cleanroommc.modularui.drawable.GuiTextures;
import com.cleanroommc.modularui.factory.GuiData;
import com.cleanroommc.modularui.network.NetworkUtils;
import com.cleanroommc.modularui.utils.Alignment;
import com.cleanroommc.modularui.value.sync.PanelSyncHandler;
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
import com.cleanroommc.modularui.value.sync.SyncHandlers;
import com.cleanroommc.modularui.widgets.ButtonWidget;
Expand All @@ -24,8 +25,6 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;

public abstract class BaseFilterContainer extends ItemStackHandler {

private int maxTransferSize = 1;
Expand Down Expand Up @@ -213,7 +212,7 @@ public void handleLegacyNBT(NBTTagCompound nbt) {

/** Uses Cleanroom MUI */
public IWidget initUI(GuiData data, PanelSyncManager manager) {
PanelSyncHandler panel = (PanelSyncHandler) manager.panel("filter_panel", (syncManager, syncHandler) -> {
IPanelHandler panel = manager.panel("filter_panel", (syncManager, syncHandler) -> {
var filter = hasFilter() ? getFilter() : BaseFilter.ERROR_FILTER;
filter.setMaxTransferSize(getMaxTransferSize());
return filter.createPopupPanel(syncManager);
Expand Down Expand Up @@ -253,17 +252,13 @@ public IWidget initUI(GuiData data, PanelSyncManager manager) {
}

public void writeInitialSyncData(PacketBuffer packetBuffer) {
packetBuffer.writeItemStack(this.getFilterStack());
NetworkUtils.writeItemStack(packetBuffer, this.getFilterStack());
packetBuffer.writeInt(this.maxTransferSize);
packetBuffer.writeInt(this.transferSize);
}

public void readInitialSyncData(@NotNull PacketBuffer packetBuffer) {
var stack = ItemStack.EMPTY;
try {
stack = packetBuffer.readItemStack();
} catch (IOException ignore) {}
this.setFilterStack(stack);
this.setFilterStack(NetworkUtils.readItemStack(packetBuffer));
this.setMaxTransferSize(packetBuffer.readInt());
this.setTransferSize(packetBuffer.readInt());
}
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/gregtech/mixins/minecraft/L18nMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package gregtech.mixins.minecraft;

import gregtech.api.mui.LocaleAccessor;

import net.minecraft.client.resources.I18n;
import net.minecraft.client.resources.Locale;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

// todo remove in next mui2 version
@Mixin(I18n.class)
public abstract class L18nMixin {

@Inject(method = "setLocale", at = @At("HEAD"))
private static void getLocale(Locale i18nLocaleIn, CallbackInfo ci) {
LocaleAccessor.setLocale(i18nLocaleIn);
}
}
23 changes: 23 additions & 0 deletions src/main/java/gregtech/mixins/minecraft/LocaleMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package gregtech.mixins.minecraft;

import gregtech.api.mui.LocaleAccessor;

import net.minecraft.client.resources.Locale;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

import java.util.Map;

// todo remove in next mui2 version
@Mixin(Locale.class)
public abstract class LocaleMixin implements LocaleAccessor {

@Shadow
Map<String, String> properties;

@Override
public String gregtech$getRawKey(String s) {
return this.properties.get(s);
}
}
79 changes: 0 additions & 79 deletions src/main/java/gregtech/mixins/mui2/ClientEventHandlerMixin.java

This file was deleted.

Loading