From 4b6a2356532d373372f614c8dd75345064a708be Mon Sep 17 00:00:00 2001 From: zeng-git <95841646+zeng-github01@users.noreply.github.com> Date: Sat, 22 Mar 2025 01:01:26 +0800 Subject: [PATCH 1/2] Make some GuiType support GuiWrapper --- .../github/handler/AEGuiBridgeHandler.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/main/java/com/glodblock/github/handler/AEGuiBridgeHandler.java diff --git a/src/main/java/com/glodblock/github/handler/AEGuiBridgeHandler.java b/src/main/java/com/glodblock/github/handler/AEGuiBridgeHandler.java new file mode 100644 index 000000000..d2323faec --- /dev/null +++ b/src/main/java/com/glodblock/github/handler/AEGuiBridgeHandler.java @@ -0,0 +1,51 @@ +package com.glodblock.github.handler; + +import appeng.container.interfaces.IInventorySlotAware; +import appeng.core.sync.GuiWrapper; +import com.glodblock.github.FluidCraft; +import com.glodblock.github.inventory.GuiType; +import com.glodblock.github.inventory.InventoryHandler; +import com.glodblock.github.util.Util; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.BlockPos; + +public class AEGuiBridgeHandler implements GuiWrapper.IExternalGui { + public static final AEGuiBridgeHandler WIRELESS_FLUID_PATTERN = new AEGuiBridgeHandler(GuiType.WIRELESS_FLUID_PATTERN_TERMINAL, "wireless_fluid_pattern_terminal"); + public static final AEGuiBridgeHandler FLUID_PATTERN_TERMINAL = new AEGuiBridgeHandler(GuiType.FLUID_PATTERN_TERMINAL, "fluid_pattern_terminal"); + public static final AEGuiBridgeHandler FLUID_EXTENDED_PATTERN_TERMINAL = new AEGuiBridgeHandler(GuiType.FLUID_EXTENDED_PATTERN_TERMINAL, "fluid_extended_pattern_terminal"); + + private final ResourceLocation id; + private final GuiType guiType; + + public AEGuiBridgeHandler(GuiType type, String key) { + id = FluidCraft.resource(key); + guiType = type; + GuiWrapper.INSTANCE.registerExternalGuiHandler(this.id, this::openGui); + } + + @Override + public ResourceLocation getID() { + return id; + } + + private void openGui(GuiWrapper.IExternalGui gui, GuiWrapper.GuiContext ctx) { + if (gui instanceof AEGuiBridgeHandler) { + GuiType type = ((AEGuiBridgeHandler) gui).guiType; + if (ctx.pos != null && ctx.facing != null) { + InventoryHandler.openGui(ctx.player, ctx.world, ctx.pos, ctx.facing, type); + } else if (ctx.extra != null) { + int slot = ctx.extra.getInteger("slot"); + boolean isBauble = ctx.extra.getBoolean("isBauble"); + InventoryHandler.openGui(ctx.player, ctx.world, new BlockPos(slot, isBauble ? 1 : 0, Integer.MIN_VALUE), EnumFacing.DOWN, type); + } else { + if (ctx.player.openContainer instanceof IInventorySlotAware) { + IInventorySlotAware c = (IInventorySlotAware) ctx.player.openContainer; + InventoryHandler.openGui(ctx.player, ctx.world, new BlockPos(c.getInventorySlot(), c.isBaubleSlot() ? 1 : 0, Integer.MIN_VALUE), EnumFacing.DOWN, type); + } else { + InventoryHandler.openGui(ctx.player, ctx.world, new BlockPos(ctx.player.inventory.currentItem, 0, Integer.MIN_VALUE), EnumFacing.DOWN, type); + } + } + } + } +} From e3eac59f3f5023722e5f3ed6ef508b4e30863dd6 Mon Sep 17 00:00:00 2001 From: zeng-git <95841646+zeng-github01@users.noreply.github.com> Date: Sun, 23 Mar 2025 00:43:28 +0800 Subject: [PATCH 2/2] rename --- .../java/com/glodblock/github/handler/AEGuiBridgeHandler.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/glodblock/github/handler/AEGuiBridgeHandler.java b/src/main/java/com/glodblock/github/handler/AEGuiBridgeHandler.java index d2323faec..4acf2bad2 100644 --- a/src/main/java/com/glodblock/github/handler/AEGuiBridgeHandler.java +++ b/src/main/java/com/glodblock/github/handler/AEGuiBridgeHandler.java @@ -5,13 +5,12 @@ import com.glodblock.github.FluidCraft; import com.glodblock.github.inventory.GuiType; import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.util.Util; import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; public class AEGuiBridgeHandler implements GuiWrapper.IExternalGui { - public static final AEGuiBridgeHandler WIRELESS_FLUID_PATTERN = new AEGuiBridgeHandler(GuiType.WIRELESS_FLUID_PATTERN_TERMINAL, "wireless_fluid_pattern_terminal"); + public static final AEGuiBridgeHandler WIRELESS_FLUID_PATTERN_TERMINAL = new AEGuiBridgeHandler(GuiType.WIRELESS_FLUID_PATTERN_TERMINAL, "wireless_fluid_pattern_terminal"); public static final AEGuiBridgeHandler FLUID_PATTERN_TERMINAL = new AEGuiBridgeHandler(GuiType.FLUID_PATTERN_TERMINAL, "fluid_pattern_terminal"); public static final AEGuiBridgeHandler FLUID_EXTENDED_PATTERN_TERMINAL = new AEGuiBridgeHandler(GuiType.FLUID_EXTENDED_PATTERN_TERMINAL, "fluid_extended_pattern_terminal");