diff --git a/dependencies.gradle b/dependencies.gradle index 7a1dea7d03f..74ea3cf0e06 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -40,7 +40,7 @@ dependencies { // Published dependencies api("codechicken:codechickenlib:3.2.3.358") - api("com.cleanroommc:modularui:2.5.0-rc3") { transitive = false } + api("com.cleanroommc:modularui:2.5.0-rc4") { transitive = false } api("com.cleanroommc:groovyscript:1.2.0-hotfix1") { transitive = false } api("curse.maven:inventory-bogosorter-632327:4951607-deobf-4951608-sources-4951609") api("CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.1.20.700") diff --git a/src/main/java/gregtech/api/mui/LocaleAccessor.java b/src/main/java/gregtech/api/mui/LocaleAccessor.java deleted file mode 100644 index 2fee169f215..00000000000 --- a/src/main/java/gregtech/api/mui/LocaleAccessor.java +++ /dev/null @@ -1,20 +0,0 @@ -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 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); - } -} diff --git a/src/main/java/gregtech/api/mui/widget/GhostCircuitSlotWidget.java b/src/main/java/gregtech/api/mui/widget/GhostCircuitSlotWidget.java index 991f65e7d05..5a498360404 100644 --- a/src/main/java/gregtech/api/mui/widget/GhostCircuitSlotWidget.java +++ b/src/main/java/gregtech/api/mui/widget/GhostCircuitSlotWidget.java @@ -6,31 +6,35 @@ import gregtech.api.recipes.ingredients.IntCircuitIngredient; import gregtech.client.utils.TooltipHelper; +import net.minecraft.item.ItemStack; import net.minecraft.network.PacketBuffer; import net.minecraftforge.items.IItemHandler; import com.cleanroommc.modularui.api.IPanelHandler; 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.ItemDrawable; import com.cleanroommc.modularui.screen.ModularScreen; import com.cleanroommc.modularui.screen.RichTooltip; import com.cleanroommc.modularui.utils.MouseData; import com.cleanroommc.modularui.value.sync.ItemSlotSH; +import com.cleanroommc.modularui.value.sync.SyncHandler; +import com.cleanroommc.modularui.widget.Widget; import com.cleanroommc.modularui.widgets.ButtonWidget; import com.cleanroommc.modularui.widgets.ItemSlot; import com.cleanroommc.modularui.widgets.layout.Grid; import com.cleanroommc.modularui.widgets.slot.ModularSlot; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; public class GhostCircuitSlotWidget extends ItemSlot { private static final int SYNC_CIRCUIT_INDEX = 10; + @Nullable + private IPanelHandler selectorPanel; + private GhostCircuitSyncHandler syncHandler; public GhostCircuitSlotWidget() { super(); @@ -41,7 +45,7 @@ public GhostCircuitSlotWidget() { public @NotNull Result onMousePressed(int mouseButton) { if (!isSelectorPanelOpen()) { if (mouseButton == 0 && TooltipHelper.isShiftDown()) { - createSelectorPanel(); + this.getSelectorPanel().openPanel(); } else { MouseData mouseData = MouseData.create(mouseButton); getSyncHandler().syncToServer(2, mouseData::writeToPacket); @@ -58,17 +62,24 @@ public boolean onMouseScroll(ModularScreen.UpOrDown scrollDirection, int amount) return true; } + @Override + public boolean isValidSyncHandler(SyncHandler syncHandler) { + this.syncHandler = castIfTypeElseNull(syncHandler, GhostCircuitSyncHandler.class); + if (this.syncHandler == null) return false; + return super.isValidSyncHandler(syncHandler); + } + @Override public ItemSlot slot(ModularSlot slot) { - ItemSlotSH sh = new GhostCircuitSyncHandler(slot); - isValidSyncHandler(sh); - setSyncHandler(sh); + this.syncHandler = new GhostCircuitSyncHandler(slot); + isValidSyncHandler(this.syncHandler); + setSyncHandler(this.syncHandler); return this; } protected void getCircuitSlotTooltip(@NotNull RichTooltip tooltip) { String configString; - int value = getSyncHandler().getGhostCircuitHandler().getCircuitValue(); + int value = this.syncHandler.getCircuitValue(); if (value == GhostCircuitItemStackHandler.NO_CONFIG) { configString = IKey.lang("gregtech.gui.configurator_slot.no_value").get(); } else { @@ -78,11 +89,6 @@ protected void getCircuitSlotTooltip(@NotNull RichTooltip tooltip) { tooltip.addLine(IKey.lang("gregtech.gui.configurator_slot.tooltip", configString)); } - @Override - public @NotNull GhostCircuitSyncHandler getSyncHandler() { - return (GhostCircuitSyncHandler) super.getSyncHandler(); - } - @Override public void onMouseDrag(int mouseButton, long timeSinceClick) {} @@ -92,44 +98,41 @@ public boolean onMouseRelease(int mouseButton) { } private boolean isSelectorPanelOpen() { - return getPanel().getScreen().isPanelOpen("circuit_selector"); + return this.getSelectorPanel().isPanelOpen(); } - private void createSelectorPanel() { - ItemDrawable circuitPreview = new ItemDrawable(getSyncHandler().getSlot().getStack()); - - IPanelHandler.simple(getPanel(), (mainPanel, player) -> { - var panel = GTGuis.createPopupPanel("circuit_selector", 176, 120); - List> options = new ArrayList<>(); - for (int i = 0; i < 4; i++) { - options.add(new ArrayList<>()); - for (int j = 0; j < 9; j++) { - int index = i * 9 + j; - if (index > 32) break; - options.get(i).add(new ButtonWidget<>() - .size(18) - .background(GTGuiTextures.SLOT, new ItemDrawable( - IntCircuitIngredient.getIntegratedCircuit(index)).asIcon()) - .disableHoverBackground() - .onMousePressed(mouseButton -> { - getSyncHandler().syncToServer(SYNC_CIRCUIT_INDEX, buf -> buf.writeShort(index)); - circuitPreview.setItem(IntCircuitIngredient.getIntegratedCircuit(index)); - if (Interactable.hasShiftDown()) panel.animateClose(); - return true; - })); - } - } - return panel.child(IKey.lang("metaitem.circuit.integrated.gui").asWidget().pos(5, 5)) - .child(circuitPreview.asIcon().size(16).asWidget() - .size(18) - .top(19).alignX(0.5f) - .background(GTGuiTextures.SLOT, GTGuiTextures.INT_CIRCUIT_OVERLAY)) - .child(new Grid() - .left(7).right(7).top(41).height(4 * 18) - .matrix(options) - .minColWidth(18).minRowHeight(18) - .minElementMargin(0, 0)); - }, true).openPanel(); + @NotNull + private IPanelHandler getSelectorPanel() { + if (this.selectorPanel == null) { + this.selectorPanel = IPanelHandler.simple(getPanel(), (mainPanel, player) -> { + ItemDrawable circuitPreview = new ItemDrawable(this.syncHandler.getCircuitStack()); + + return GTGuis.createPopupPanel("circuit_selector", 176, 120) + .child(IKey.lang("metaitem.circuit.integrated.gui").asWidget().pos(5, 5)) + .child(new Widget<>() + .size(18) + .top(19).alignX(0.5f) + .overlay(circuitPreview.asIcon().margin(1)) + .background(GTGuiTextures.SLOT, GTGuiTextures.INT_CIRCUIT_OVERLAY)) + .child(new Grid() + .left(7).right(7).top(41).height(4 * 18) + .mapTo(9, 33, value -> new ButtonWidget<>() + .size(18) + .background(GTGuiTextures.SLOT, new ItemDrawable( + IntCircuitIngredient.getIntegratedCircuit(value)).asIcon()) + .disableHoverBackground() + .onMousePressed(mouseButton -> { + getSyncHandler().syncToServer(SYNC_CIRCUIT_INDEX, + buf -> buf.writeShort(value)); + circuitPreview.setItem(IntCircuitIngredient.getIntegratedCircuit(value)); + if (Interactable.hasShiftDown()) this.selectorPanel.closePanel(); + return true; + })) + .minColWidth(18).minRowHeight(18) + .minElementMargin(0, 0)); + }, true); + } + return this.selectorPanel; } private static class GhostCircuitSyncHandler extends ItemSlotSH { @@ -169,6 +172,14 @@ private void setCircuitValue(int value) { } } + public int getCircuitValue() { + return getGhostCircuitHandler().getCircuitValue(); + } + + public ItemStack getCircuitStack() { + return getSlot().getStack(); + } + @Override public void readOnServer(int id, PacketBuffer buf) throws IOException { if (id == SYNC_CIRCUIT_INDEX) { diff --git a/src/main/java/gregtech/mixins/minecraft/L18nMixin.java b/src/main/java/gregtech/mixins/minecraft/L18nMixin.java deleted file mode 100644 index 26d67c82e0b..00000000000 --- a/src/main/java/gregtech/mixins/minecraft/L18nMixin.java +++ /dev/null @@ -1,21 +0,0 @@ -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); - } -} diff --git a/src/main/java/gregtech/mixins/minecraft/LocaleMixin.java b/src/main/java/gregtech/mixins/minecraft/LocaleMixin.java deleted file mode 100644 index b93f29b02e6..00000000000 --- a/src/main/java/gregtech/mixins/minecraft/LocaleMixin.java +++ /dev/null @@ -1,23 +0,0 @@ -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 properties; - - @Override - public String gregtech$getRawKey(String s) { - return this.properties.get(s); - } -} diff --git a/src/main/java/gregtech/mixins/mui2/InputMixin.java b/src/main/java/gregtech/mixins/mui2/InputMixin.java deleted file mode 100644 index 0e1d3febacf..00000000000 --- a/src/main/java/gregtech/mixins/mui2/InputMixin.java +++ /dev/null @@ -1,64 +0,0 @@ -package gregtech.mixins.mui2; - -import gregtech.api.mui.InputAccessor; - -import com.cleanroommc.modularui.api.widget.Interactable; -import com.cleanroommc.modularui.screen.viewport.LocatedWidget; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -// todo remove on next mui2 update -@Mixin(targets = "com.cleanroommc.modularui.screen.ModularPanel$Input", remap = false) -public abstract class InputMixin implements InputAccessor { - - @Shadow - private boolean held; - - @Shadow - private long timeHeld; - - @Shadow - private @Nullable LocatedWidget lastPressed; - - @Shadow - private int lastButton; - - @Shadow - protected abstract void addAcceptedInteractable(Interactable interactable); - - @Override - public boolean held() { - return this.held; - } - - @Override - public void held(boolean held) { - this.held = held; - } - - @Override - public void timeHeld(long a) { - timeHeld = a; - } - - @Override - public LocatedWidget lastPressed() { - return this.lastPressed; - } - - @Override - public void lastPressed(LocatedWidget last) { - this.lastPressed = last; - } - - @Override - public void lastButton(int b) { - this.lastButton = b; - } - - @Override - public void addInteractable(Interactable i) { - addAcceptedInteractable(i); - } -} diff --git a/src/main/java/gregtech/mixins/mui2/LangKeyMixin.java b/src/main/java/gregtech/mixins/mui2/LangKeyMixin.java index 7c219710609..2e5e1a3f8ce 100644 --- a/src/main/java/gregtech/mixins/mui2/LangKeyMixin.java +++ b/src/main/java/gregtech/mixins/mui2/LangKeyMixin.java @@ -1,23 +1,20 @@ package gregtech.mixins.mui2; -import gregtech.api.mui.LocaleAccessor; - import com.cleanroommc.modularui.drawable.text.BaseKey; import com.cleanroommc.modularui.drawable.text.LangKey; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; -// todo remove in next mui2 version +// all this mixin does is switch newlines to the expected format @Mixin(value = LangKey.class, remap = false) public abstract class LangKeyMixin extends BaseKey { - @Redirect(method = "getFormatted", - at = @At(value = "INVOKE", - target = "Lnet/minecraft/client/resources/I18n;format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;")) - public String getTranslateKey(String translateKey, Object[] parameters) { - return LocaleAccessor.getRawKey(translateKey) + @ModifyExpressionValue(method = "getFormatted", + at = @At(value = "INVOKE", + target = "Lcom/cleanroommc/modularui/drawable/text/FontRenderHelper;formatArgs([Ljava/lang/Object;Lcom/cleanroommc/modularui/drawable/text/FormattingState;Ljava/lang/String;Z)Ljava/lang/String;")) + public String getTranslateKey(String original) { + return original .replace("\\n", "\n") .replace("/n", "\n"); } diff --git a/src/main/java/gregtech/mixins/mui2/ModularPanelMixin.java b/src/main/java/gregtech/mixins/mui2/ModularPanelMixin.java index 16e4a2b6b8c..78cec0e56bb 100644 --- a/src/main/java/gregtech/mixins/mui2/ModularPanelMixin.java +++ b/src/main/java/gregtech/mixins/mui2/ModularPanelMixin.java @@ -1,167 +1,27 @@ package gregtech.mixins.mui2; -import gregtech.api.mui.InputAccessor; -import gregtech.api.util.Mods; -import gregtech.integration.jei.JustEnoughItemsModule; -import gregtech.mixins.jei.DragManagerAccessor; -import gregtech.mixins.jei.GhostDragAccessor; - -import net.minecraft.client.Minecraft; - import com.cleanroommc.modularui.api.layout.IViewport; -import com.cleanroommc.modularui.api.widget.IFocusedWidget; -import com.cleanroommc.modularui.api.widget.Interactable; -import com.cleanroommc.modularui.integration.jei.JeiGhostIngredientSlot; +import com.cleanroommc.modularui.integration.jei.ModularUIJeiPlugin; import com.cleanroommc.modularui.screen.ModularPanel; import com.cleanroommc.modularui.screen.viewport.LocatedWidget; -import com.cleanroommc.modularui.utils.ObjectList; import com.cleanroommc.modularui.widget.ParentWidget; -import mezz.jei.gui.ghost.GhostIngredientDrag; -import mezz.jei.gui.ghost.GhostIngredientDragManager; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(value = ModularPanel.class, remap = false) public abstract class ModularPanelMixin extends ParentWidget implements IViewport { - @Shadow - @Final - private ObjectList hovering; - - @Shadow - public abstract boolean closeOnOutOfBoundsClick(); - - @Shadow - public abstract void animateClose(); - - @Unique - InputAccessor gregTech$mouse = null; - - /** - * @author Ghzdude - GTCEu - * @reason Implement fixes to phantom slot handling from Mui2 master - */ - // this looks really cursed in mixin.out, but it works - @Overwrite - private boolean lambda$onMousePressed$3(int mouseButton) { - LocatedWidget pressed = LocatedWidget.EMPTY; - boolean result = false; - - if (gregTech$mouse == null) { - // reflection because the type is a private inner class - try { - gregTech$mouse = (InputAccessor) ModularPanel.class.getDeclaredField("mouse").get(this); - } catch (IllegalAccessException | NoSuchFieldException e) { - throw new RuntimeException(e); - } - } - - if (this.hovering.isEmpty()) { - if (closeOnOutOfBoundsClick()) { - animateClose(); - result = true; - } - } else { - loop: - for (LocatedWidget widget : this.hovering) { - widget.applyMatrix(getContext()); - GhostIngredientDrag drag = gregTech$getGhostDrag(); - if (widget.getElement() instanceof JeiGhostIngredientSlotghostSlot && - Mods.JustEnoughItems.isModLoaded()) { - if (drag != null && gregTech$insertGhostIngredient(drag, ghostSlot)) { - gregTech$stopDrag(); - pressed = LocatedWidget.EMPTY; - result = true; - widget.unapplyMatrix(getContext()); - break; - } - } - if (drag == null && widget.getElement() instanceof Interactable interactable) { - switch (interactable.onMousePressed(mouseButton)) { - case IGNORE: - break; - case ACCEPT: { - if (!gregTech$mouse.held()) { - gregTech$mouse.addInteractable(interactable); - } - pressed = widget; - // result = false; - break; - } - case STOP: { - pressed = LocatedWidget.EMPTY; - result = true; - widget.unapplyMatrix(getContext()); - break loop; - } - case SUCCESS: { - if (!gregTech$mouse.held()) { - gregTech$mouse.addInteractable(interactable); - } - pressed = widget; - result = true; - widget.unapplyMatrix(getContext()); - break loop; - } - } - } - if (getContext().onHoveredClick(mouseButton, widget)) { - pressed = LocatedWidget.EMPTY; - result = true; - widget.unapplyMatrix(getContext()); - break; - } - widget.unapplyMatrix(getContext()); - if (widget.getElement().canHover()) { - result = true; - break; - } - } + @Redirect(method = "lambda$onMousePressed$3", + at = @At(value = "INVOKE", + target = "Lcom/cleanroommc/modularui/screen/viewport/LocatedWidget;getElement()Ljava/lang/Object;", + ordinal = 1)) + private Object checkDrag(LocatedWidget instance) { + // if we're dragging something, prevent interaction + if (ModularUIJeiPlugin.hasDraggingGhostIngredient()) { + return null; } - if (result && pressed.getElement() instanceof IFocusedWidget) { - getContext().focus(pressed); - } else { - getContext().removeFocus(); - } - if (!gregTech$mouse.held()) { - gregTech$mouse.lastPressed(pressed); - if (gregTech$mouse.lastPressed().getElement() != null) { - gregTech$mouse.timeHeld(Minecraft.getSystemTime()); - } - gregTech$mouse.lastButton(mouseButton); - gregTech$mouse.held(true); - } - return result; - } - - @Unique - private static GhostIngredientDrag gregTech$getGhostDrag() { - GhostIngredientDragManager manager = ((DragManagerAccessor) JustEnoughItemsModule.jeiRuntime - .getIngredientListOverlay()).getManager(); - return ((GhostDragAccessor) manager).getDrag(); - } - - @Unique - @SuppressWarnings("rawtypes") - private static boolean gregTech$insertGhostIngredient(GhostIngredientDrag drag, - JeiGhostIngredientSlot slot) { - Object object = slot.castGhostIngredientIfValid(drag.getIngredient()); - if (object != null) { - // noinspection unchecked - slot.setGhostIngredient(object); - return true; - } - return false; - } - - @Unique - private static void gregTech$stopDrag() { - GhostIngredientDragManager manager = ((DragManagerAccessor) JustEnoughItemsModule.jeiRuntime - .getIngredientListOverlay()).getManager(); - manager.stopDrag(); + return instance.getElement(); } } diff --git a/src/main/resources/mixins.gregtech.minecraft.json b/src/main/resources/mixins.gregtech.minecraft.json index 41a4c44b26e..85676f99055 100644 --- a/src/main/resources/mixins.gregtech.minecraft.json +++ b/src/main/resources/mixins.gregtech.minecraft.json @@ -18,10 +18,8 @@ "client": [ "BlockMixin", "EntityRendererMixin", - "L18nMixin", "LayerArmorBaseMixin", "LayerCustomHeadMixin", - "LocaleMixin", "RecipeRepairItemMixin", "RegionRenderCacheBuilderMixin", "RenderChunkMixin", diff --git a/src/main/resources/mixins.gregtech.mui2.json b/src/main/resources/mixins.gregtech.mui2.json index 41f64f92ed4..f313fa2b32d 100644 --- a/src/main/resources/mixins.gregtech.mui2.json +++ b/src/main/resources/mixins.gregtech.mui2.json @@ -8,7 +8,6 @@ "maxShiftBy": 10 }, "mixins": [ - "InputMixin", "ModularPanelMixin" ], "client": [