ME接口增加升级槽
This commit is contained in:
parent
a5db537b22
commit
687432f86f
|
|
@ -0,0 +1,85 @@
|
|||
package com.extendedae_plus.mixin.ae2.helpers;
|
||||
|
||||
import appeng.api.networking.IManagedGridNode;
|
||||
import appeng.api.upgrades.IUpgradeInventory;
|
||||
import appeng.api.upgrades.UpgradeInventories;
|
||||
import appeng.helpers.InterfaceLogic;
|
||||
import appeng.helpers.InterfaceLogicHost;
|
||||
import com.extendedae_plus.bridge.CompatUpgradeProvider;
|
||||
import com.extendedae_plus.compat.UpgradeSlotCompat;
|
||||
import net.neoforged.fml.ModList;
|
||||
import com.extendedae_plus.util.ExtendedAELogger;
|
||||
import net.minecraft.world.item.Item;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
/**
|
||||
* 为ME接口增加升级槽数量
|
||||
* - 没有AppliedFlux时:从1个增加到2个
|
||||
* - 有AppliedFlux时:从2个增加到3个
|
||||
*/
|
||||
@Mixin(value = InterfaceLogic.class, priority = 1100, remap = false)
|
||||
public abstract class InterfaceLogicUpgradesMixin implements CompatUpgradeProvider {
|
||||
|
||||
@Shadow(remap = false)
|
||||
private IUpgradeInventory upgrades;
|
||||
|
||||
@Unique
|
||||
private IUpgradeInventory eap$compatUpgrades;
|
||||
|
||||
|
||||
/**
|
||||
* 在AppliedFlux之后进一步增加升级槽数量
|
||||
* mixin优先级设置为1100,确保在AppliedFlux的mixin之后执行
|
||||
*/
|
||||
@Inject(method = "<init>(Lappeng/api/networking/IManagedGridNode;Lappeng/helpers/InterfaceLogicHost;Lnet/minecraft/world/item/Item;I)V",
|
||||
at = @At("TAIL"), remap = false)
|
||||
private void eap$expandUpgradesAfterAppliedFlux(IManagedGridNode gridNode, InterfaceLogicHost host, Item is, int slots, CallbackInfo ci) {
|
||||
boolean hasAppliedFlux = ModList.get().isLoaded("appflux");
|
||||
int currentSlots = this.upgrades.size();
|
||||
int targetSlots;
|
||||
|
||||
if (hasAppliedFlux) {
|
||||
// AppliedFlux已经将升级槽从1增加到2,我们再增加1个变成3
|
||||
targetSlots = 3;
|
||||
ExtendedAELogger.LOGGER.debug("[ME接口] 检测到AppliedFlux,当前升级槽: {}, 目标升级槽: {}", currentSlots, targetSlots);
|
||||
} else {
|
||||
// 没有AppliedFlux,从原始的1增加到2
|
||||
targetSlots = 2;
|
||||
ExtendedAELogger.LOGGER.debug("[ME接口] 未检测到AppliedFlux,当前升级槽: {}, 目标升级槽: {}", currentSlots, targetSlots);
|
||||
}
|
||||
|
||||
// 只有当当前槽数小于目标槽数时才需要扩展
|
||||
if (currentSlots < targetSlots) {
|
||||
this.upgrades = UpgradeInventories.forMachine(is, targetSlots, this::eap$onUpgradesChanged);
|
||||
ExtendedAELogger.LOGGER.debug("[ME接口] 升级槽已扩展到: {}", targetSlots);
|
||||
|
||||
// 设置兼容升级槽
|
||||
if (UpgradeSlotCompat.shouldEnableUpgradeSlots()) {
|
||||
this.eap$compatUpgrades = this.upgrades;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Unique
|
||||
private void eap$onUpgradesChanged() {
|
||||
// 调用原始的onUpgradesChanged方法
|
||||
try {
|
||||
// 通过反射调用原始方法,因为它是protected的
|
||||
var method = InterfaceLogic.class.getDeclaredMethod("onUpgradesChanged");
|
||||
method.setAccessible(true);
|
||||
method.invoke(this);
|
||||
} catch (Exception e) {
|
||||
ExtendedAELogger.LOGGER.error("[ME接口] 调用onUpgradesChanged失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IUpgradeInventory eap$getCompatUpgrades() {
|
||||
return this.eap$compatUpgrades != null ? this.eap$compatUpgrades : this.upgrades;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package com.extendedae_plus.mixin.ae2.menu;
|
||||
|
||||
import appeng.helpers.InterfaceLogicHost;
|
||||
import appeng.menu.AEBaseMenu;
|
||||
import appeng.menu.ToolboxMenu;
|
||||
import appeng.menu.implementations.InterfaceMenu;
|
||||
import com.extendedae_plus.bridge.IUpgradableMenu;
|
||||
import com.extendedae_plus.compat.UpgradeSlotCompat;
|
||||
import com.extendedae_plus.bridge.CompatUpgradeProvider;
|
||||
import com.extendedae_plus.util.ExtendedAELogger;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
/**
|
||||
* 为ME接口菜单添加升级槽支持,确保与AppliedFlux的兼容性
|
||||
*/
|
||||
@Mixin(value = InterfaceMenu.class, priority = 900, remap = false)
|
||||
public abstract class InterfaceMenuUpgradesMixin extends AEBaseMenu implements IUpgradableMenu {
|
||||
|
||||
@Unique
|
||||
private ToolboxMenu eap$toolbox;
|
||||
|
||||
@Inject(method = "<init>(Lnet/minecraft/world/inventory/MenuType;ILnet/minecraft/world/entity/player/Inventory;Lappeng/helpers/InterfaceLogicHost;)V",
|
||||
at = @At("TAIL"))
|
||||
private void eap$initUpgrades(MenuType<?> menuType, int id, Inventory playerInventory, InterfaceLogicHost host, CallbackInfo ci) {
|
||||
this.eap$toolbox = new ToolboxMenu(this);
|
||||
|
||||
// InterfaceMenu已经继承自UpgradeableMenu,会自动处理升级槽
|
||||
// 这里只需要记录日志,不需要重复设置升级槽
|
||||
ExtendedAELogger.LOGGER.debug("[ME接口][菜单] 升级槽已由UpgradeableMenu自动处理,当前升级槽数量: {}",
|
||||
host.getInterfaceLogic().getUpgrades().size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ToolboxMenu getToolbox() {
|
||||
return this.eap$toolbox;
|
||||
}
|
||||
|
||||
public InterfaceMenuUpgradesMixin(MenuType<?> menuType, int id, Inventory playerInventory, Object host) {
|
||||
super(menuType, id, playerInventory, host);
|
||||
}
|
||||
}
|
||||
|
|
@ -28,9 +28,11 @@
|
|||
"ae2.compat.PatternProviderLogicCompatMixin",
|
||||
"ae2.helpers.InterfaceLogicChannelCardMixin",
|
||||
"ae2.helpers.InterfaceLogicTickerMixin",
|
||||
"ae2.helpers.InterfaceLogicUpgradesMixin",
|
||||
"ae2.helpers.PatternProviderLogicAdvancedMixin",
|
||||
"ae2.helpers.PatternProviderLogicDoublingMixin",
|
||||
"ae2.helpers.patternprovider.PatternProviderLogicTickerMixin",
|
||||
"ae2.menu.InterfaceMenuUpgradesMixin",
|
||||
"ae2.menu.PatternProviderMenuUpgradesMixin",
|
||||
"ae2.parts.automation.IOBusPartChannelCardMixin",
|
||||
"ae2.parts.storagebus.StorageBusPartChannelCardMixin",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user