From 1496ecd36772cb185808630cc6e008acc710ba6e Mon Sep 17 00:00:00 2001 From: GaLicn <133291877+GaLicn@users.noreply.github.com> Date: Mon, 1 Dec 2025 23:13:21 +0800 Subject: [PATCH] =?UTF-8?q?mixin=E5=88=B0=E8=A3=85=E9=85=8D=E7=9F=A9?= =?UTF-8?q?=E9=98=B5=E7=9A=84ui=E7=BB=98=E5=88=B6=EF=BC=8C=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E4=B8=BA=E4=B8=8D=E5=90=8C=E6=A0=B7=E6=9D=BF=E6=A0=B8?= =?UTF-8?q?=E5=BF=83=E6=A7=BD=E4=BD=8D=E6=95=B0=E5=8F=98=E9=87=8F=E8=B5=8B?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GuiAssemblerMatrixPatternInfoMixin.java | 78 +++++++++++++++++++ .../resources/extendedae_plus.mixins.json | 3 +- 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/extendedae_plus/mixin/extendedae/client/gui/GuiAssemblerMatrixPatternInfoMixin.java diff --git a/src/main/java/com/extendedae_plus/mixin/extendedae/client/gui/GuiAssemblerMatrixPatternInfoMixin.java b/src/main/java/com/extendedae_plus/mixin/extendedae/client/gui/GuiAssemblerMatrixPatternInfoMixin.java new file mode 100644 index 0000000..cc1de4c --- /dev/null +++ b/src/main/java/com/extendedae_plus/mixin/extendedae/client/gui/GuiAssemblerMatrixPatternInfoMixin.java @@ -0,0 +1,78 @@ +package com.extendedae_plus.mixin.extendedae.client.gui; + +import com.extendedae_plus.content.matrix.PatternCorePlusBlockEntity; +import com.glodblock.github.extendedae.common.tileentities.matrix.TileAssemblerMatrixPattern; +import net.minecraft.client.Minecraft; +import net.minecraft.core.BlockPos; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.Unique; +import com.glodblock.github.extendedae.client.gui.GuiAssemblerMatrix; + +import java.util.List; +import java.lang.reflect.Constructor; + +@Mixin(targets = "com.glodblock.github.extendedae.client.gui.GuiAssemblerMatrix$PatternInfo") +public abstract class GuiAssemblerMatrixPatternInfoMixin { + + @Shadow + @Final + private List internalRows; + + @Unique + private static Constructor extendedae_plus$patternRowCtor; + + //通过反射获取目标类中的PatternRow内部类,new出来对象 + @Unique + private static Object extendedae_plus$createPatternRow(long patternID, int offset, int slots) { + try { + if (extendedae_plus$patternRowCtor == null) { + var clazz = Class.forName("com.glodblock.github.extendedae.client.gui.GuiAssemblerMatrix$PatternRow"); + extendedae_plus$patternRowCtor = clazz.getDeclaredConstructor(long.class, int.class, int.class); + extendedae_plus$patternRowCtor.setAccessible(true); + } + return extendedae_plus$patternRowCtor.newInstance(patternID, offset, slots); + } catch (ReflectiveOperationException e) { + throw new RuntimeException("Failed to create PatternRow", e); + } + } + + @Inject(method = "", at = @At("RETURN")) + private void extendedae_plus$rebuildRows(long id, CallbackInfo ci) { + int invSize = TileAssemblerMatrixPattern.INV_SIZE;//样板核心槽位数变量 + try { + //根据目标核心类型设置用于客户端渲染的槽位数值 + var mc = Minecraft.getInstance(); + if (mc.level != null) { + BlockPos pos = BlockPos.of(id); + var be = mc.level.getBlockEntity(pos); + if (be instanceof TileAssemblerMatrixPattern tile) { + invSize = tile.getTerminalPatternInventory().size(); + } else if (be instanceof PatternCorePlusBlockEntity plus) { + invSize = plus.getTerminalPatternInventory().size(); + } + } + } catch (Throwable ignored) { + } + + if (invSize <= TileAssemblerMatrixPattern.INV_SIZE) { + return; + } + + this.internalRows.clear(); + + int left = invSize; + int offset = 0; + do { + this.internalRows.add(extendedae_plus$createPatternRow(id, offset, Math.min(left, 9))); + left -= 9; + offset += 9; + } while (left > 0); + } +} + + diff --git a/src/main/resources/extendedae_plus.mixins.json b/src/main/resources/extendedae_plus.mixins.json index 4a9e4c0..640cafb 100644 --- a/src/main/resources/extendedae_plus.mixins.json +++ b/src/main/resources/extendedae_plus.mixins.json @@ -33,7 +33,8 @@ "minecraft.ModelBakeryMixin", "minecraft.PickFromWirelessMixin", "minecraft.accessor.AbstractContainerScreenAccessor", - "minecraft.accessor.ScreenAccessor" + "minecraft.accessor.ScreenAccessor", + "extendedae.client.gui.GuiAssemblerMatrixPatternInfoMixin" ], "mixins": [ "advancedae.AdvPatternProviderLogicContainsRedirectMixin",