同步ME扩展接口
This commit is contained in:
parent
b3e129e03c
commit
23dcd69a39
|
|
@ -44,8 +44,8 @@ public abstract class InterfaceScreenMixin<T extends AEBaseMenu> {
|
|||
|
||||
@Inject(method = "init", at = @At("TAIL"))
|
||||
private void eap$addScaleButtons(CallbackInfo ci) {
|
||||
// 仅在 InterfaceScreen 实例中添加
|
||||
if (!(((Object) this) instanceof InterfaceScreen)) {
|
||||
// 仅在 AE2 接口界面或 ExtendedAE 扩展接口界面中添加
|
||||
if (!eap$isSupportedInterfaceScreen()) {
|
||||
return;
|
||||
}
|
||||
try { LogUtils.getLogger().info("[EAP][InterfaceMixin] init tail reached, preparing scale buttons."); } catch (Throwable ignored) {}
|
||||
|
|
@ -115,7 +115,7 @@ public abstract class InterfaceScreenMixin<T extends AEBaseMenu> {
|
|||
|
||||
@Inject(method = "containerTick", at = @At("TAIL"))
|
||||
private void eap$ensureButtons(CallbackInfo ci) {
|
||||
if (!(((Object) this) instanceof InterfaceScreen)) {
|
||||
if (!eap$isSupportedInterfaceScreen()) {
|
||||
return;
|
||||
}
|
||||
var accessor = (ScreenAccessor) (Object) this;
|
||||
|
|
@ -171,7 +171,7 @@ public abstract class InterfaceScreenMixin<T extends AEBaseMenu> {
|
|||
private void eap$sendAdjustForHoveredConfig(boolean divide, int factor) {
|
||||
try {
|
||||
// 仅在 InterfaceScreen 中生效
|
||||
if (!(((Object) this) instanceof InterfaceScreen)) {
|
||||
if (!eap$isSupportedInterfaceScreen()) {
|
||||
return;
|
||||
}
|
||||
// 获取悬停槽位
|
||||
|
|
@ -229,7 +229,7 @@ public abstract class InterfaceScreenMixin<T extends AEBaseMenu> {
|
|||
@Unique
|
||||
private void eap$sendAdjustForAllConfigs(boolean divide, int factor) {
|
||||
try {
|
||||
if (!(((Object) this) instanceof InterfaceScreen)) {
|
||||
if (!eap$isSupportedInterfaceScreen()) {
|
||||
return;
|
||||
}
|
||||
// 直接发送 -1 表示对所有 CONFIG 槽生效
|
||||
|
|
@ -237,6 +237,22 @@ public abstract class InterfaceScreenMixin<T extends AEBaseMenu> {
|
|||
} catch (Throwable ignored) {}
|
||||
}
|
||||
|
||||
@Unique
|
||||
private boolean eap$isSupportedInterfaceScreen() {
|
||||
// AE2 原版接口界面
|
||||
if (((Object) this) instanceof InterfaceScreen) {
|
||||
return true;
|
||||
}
|
||||
// ExtendedAE 扩展接口界面(使用类名判断避免编译期硬依赖)
|
||||
try {
|
||||
String cn = ((Object) this).getClass().getName();
|
||||
if ("com.glodblock.github.extendedae.client.gui.GuiExInterface".equals(cn)) {
|
||||
return true;
|
||||
}
|
||||
} catch (Throwable ignored) {}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Unique
|
||||
private void eap$relayoutButtons() {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -43,27 +43,24 @@ public class InterfaceAdjustConfigAmountC2SPacket {
|
|||
ctx.enqueueWork(() -> {
|
||||
ServerPlayer player = ctx.getSender();
|
||||
if (player == null) return;
|
||||
if (!(player.containerMenu instanceof InterfaceMenu menu)) return;
|
||||
// 支持 AE2 原版接口和 ExtendedAE 扩展接口
|
||||
InterfaceMenu menu = null;
|
||||
com.glodblock.github.extendedae.container.ContainerExInterface exMenu = null;
|
||||
if (player.containerMenu instanceof InterfaceMenu im) {
|
||||
menu = im;
|
||||
} else if (player.containerMenu instanceof com.glodblock.github.extendedae.container.ContainerExInterface cem) {
|
||||
exMenu = cem;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
var logic = menu.getHost().getInterfaceLogic();
|
||||
var logic = (menu != null ? menu.getHost() : exMenu.getHost()).getInterfaceLogic();
|
||||
var config = logic.getConfig();
|
||||
if (msg.slotIndex == -1) {
|
||||
// 对所有 CONFIG 槽位生效
|
||||
var configSlots = menu.getSlots(SlotSemantics.CONFIG);
|
||||
if (configSlots == null || configSlots.isEmpty()) return;
|
||||
for (var s : configSlots) {
|
||||
int idx = -1;
|
||||
try {
|
||||
var f = s.getClass().getDeclaredField("slot");
|
||||
f.setAccessible(true);
|
||||
Object v = f.get(s);
|
||||
if (v instanceof Integer i) idx = i;
|
||||
} catch (Throwable ignored) {}
|
||||
if (idx < 0) {
|
||||
idx = configSlots.indexOf(s);
|
||||
}
|
||||
|
||||
// 对所有配置槽统一生效(不依赖槽位语义,直接按 config.size() 遍历)
|
||||
int size = config.size();
|
||||
for (int idx = 0; idx < size; idx++) {
|
||||
var st = config.getStack(idx);
|
||||
if (st == null) continue;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user