同步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"))
|
@Inject(method = "init", at = @At("TAIL"))
|
||||||
private void eap$addScaleButtons(CallbackInfo ci) {
|
private void eap$addScaleButtons(CallbackInfo ci) {
|
||||||
// 仅在 InterfaceScreen 实例中添加
|
// 仅在 AE2 接口界面或 ExtendedAE 扩展接口界面中添加
|
||||||
if (!(((Object) this) instanceof InterfaceScreen)) {
|
if (!eap$isSupportedInterfaceScreen()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try { LogUtils.getLogger().info("[EAP][InterfaceMixin] init tail reached, preparing scale buttons."); } catch (Throwable ignored) {}
|
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"))
|
@Inject(method = "containerTick", at = @At("TAIL"))
|
||||||
private void eap$ensureButtons(CallbackInfo ci) {
|
private void eap$ensureButtons(CallbackInfo ci) {
|
||||||
if (!(((Object) this) instanceof InterfaceScreen)) {
|
if (!eap$isSupportedInterfaceScreen()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var accessor = (ScreenAccessor) (Object) this;
|
var accessor = (ScreenAccessor) (Object) this;
|
||||||
|
|
@ -171,7 +171,7 @@ public abstract class InterfaceScreenMixin<T extends AEBaseMenu> {
|
||||||
private void eap$sendAdjustForHoveredConfig(boolean divide, int factor) {
|
private void eap$sendAdjustForHoveredConfig(boolean divide, int factor) {
|
||||||
try {
|
try {
|
||||||
// 仅在 InterfaceScreen 中生效
|
// 仅在 InterfaceScreen 中生效
|
||||||
if (!(((Object) this) instanceof InterfaceScreen)) {
|
if (!eap$isSupportedInterfaceScreen()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 获取悬停槽位
|
// 获取悬停槽位
|
||||||
|
|
@ -229,7 +229,7 @@ public abstract class InterfaceScreenMixin<T extends AEBaseMenu> {
|
||||||
@Unique
|
@Unique
|
||||||
private void eap$sendAdjustForAllConfigs(boolean divide, int factor) {
|
private void eap$sendAdjustForAllConfigs(boolean divide, int factor) {
|
||||||
try {
|
try {
|
||||||
if (!(((Object) this) instanceof InterfaceScreen)) {
|
if (!eap$isSupportedInterfaceScreen()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 直接发送 -1 表示对所有 CONFIG 槽生效
|
// 直接发送 -1 表示对所有 CONFIG 槽生效
|
||||||
|
|
@ -237,6 +237,22 @@ public abstract class InterfaceScreenMixin<T extends AEBaseMenu> {
|
||||||
} catch (Throwable ignored) {}
|
} 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
|
@Unique
|
||||||
private void eap$relayoutButtons() {
|
private void eap$relayoutButtons() {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -43,27 +43,24 @@ public class InterfaceAdjustConfigAmountC2SPacket {
|
||||||
ctx.enqueueWork(() -> {
|
ctx.enqueueWork(() -> {
|
||||||
ServerPlayer player = ctx.getSender();
|
ServerPlayer player = ctx.getSender();
|
||||||
if (player == null) return;
|
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 {
|
try {
|
||||||
var logic = menu.getHost().getInterfaceLogic();
|
var logic = (menu != null ? menu.getHost() : exMenu.getHost()).getInterfaceLogic();
|
||||||
var config = logic.getConfig();
|
var config = logic.getConfig();
|
||||||
if (msg.slotIndex == -1) {
|
if (msg.slotIndex == -1) {
|
||||||
// 对所有 CONFIG 槽位生效
|
// 对所有配置槽统一生效(不依赖槽位语义,直接按 config.size() 遍历)
|
||||||
var configSlots = menu.getSlots(SlotSemantics.CONFIG);
|
int size = config.size();
|
||||||
if (configSlots == null || configSlots.isEmpty()) return;
|
for (int idx = 0; idx < size; idx++) {
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
var st = config.getStack(idx);
|
var st = config.getStack(idx);
|
||||||
if (st == null) continue;
|
if (st == null) continue;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user