mixin到装配矩阵的ui绘制,动态为不同样板核心槽位数变量赋值

This commit is contained in:
GaLicn 2025-12-01 23:13:21 +08:00
parent 55993ef0f0
commit 1496ecd367
2 changed files with 80 additions and 1 deletions

View File

@ -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<Object> 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 = "<init>", 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);
}
}

View File

@ -33,7 +33,8 @@
"minecraft.ModelBakeryMixin",
"minecraft.PickFromWirelessMixin",
"minecraft.accessor.AbstractContainerScreenAccessor",
"minecraft.accessor.ScreenAccessor"
"minecraft.accessor.ScreenAccessor",
"extendedae.client.gui.GuiAssemblerMatrixPatternInfoMixin"
],
"mixins": [
"advancedae.AdvPatternProviderLogicContainsRedirectMixin",