增加jei中鼠标中建可以直接下单功能,并且适配curios适配槽
This commit is contained in:
parent
04ea2681da
commit
c70479e3cf
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.extendedae_plus.menu.host;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
|
import appeng.api.implementations.menuobjects.ItemMenuHost;
|
||||||
|
import appeng.helpers.WirelessTerminalMenuHost;
|
||||||
|
import appeng.menu.ISubMenu;
|
||||||
|
import appeng.api.storage.ISubMenuHost;
|
||||||
|
|
||||||
|
// Curios API
|
||||||
|
import top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 针对 Curios 槽位的无线终端菜单宿主。
|
||||||
|
* 关键点:在 onBroadcastChanges 周期性把 getItemStack() 回写到 Curios 槽位,
|
||||||
|
* 以持久化能量消耗等 NBT 变化。
|
||||||
|
*/
|
||||||
|
public class CuriosWirelessTerminalMenuHost extends WirelessTerminalMenuHost implements ISubMenuHost {
|
||||||
|
private final ICurioStacksHandler curiosHandler;
|
||||||
|
private final int curiosIndex;
|
||||||
|
|
||||||
|
public CuriosWirelessTerminalMenuHost(Player player,
|
||||||
|
ItemStack itemStack,
|
||||||
|
ICurioStacksHandler curiosHandler,
|
||||||
|
int curiosIndex,
|
||||||
|
java.util.function.BiConsumer<Player, ISubMenu> returnToMainMenu) {
|
||||||
|
super(player, null, itemStack, returnToMainMenu);
|
||||||
|
this.curiosHandler = curiosHandler;
|
||||||
|
this.curiosIndex = curiosIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onBroadcastChanges(AbstractContainerMenu menu) {
|
||||||
|
// 将当前 ItemStack 写回 Curios 槽位,保证 NBT 改动(如耗电)持久化
|
||||||
|
try {
|
||||||
|
ItemStack current = getItemStack();
|
||||||
|
curiosHandler.getStacks().setStackInSlot(curiosIndex, current);
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
return super.onBroadcastChanges(menu);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,7 +8,12 @@ import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
import appeng.api.implementations.menuobjects.IMenuItem;
|
import appeng.api.implementations.menuobjects.IMenuItem;
|
||||||
import appeng.api.implementations.menuobjects.ItemMenuHost;
|
import appeng.api.implementations.menuobjects.ItemMenuHost;
|
||||||
|
import appeng.helpers.WirelessTerminalMenuHost;
|
||||||
|
import appeng.items.tools.powered.WirelessTerminalItem;
|
||||||
|
import appeng.menu.MenuOpener;
|
||||||
|
import appeng.menu.me.common.MEStorageMenu;
|
||||||
import appeng.menu.locator.MenuLocator;
|
import appeng.menu.locator.MenuLocator;
|
||||||
|
import com.extendedae_plus.menu.host.CuriosWirelessTerminalMenuHost;
|
||||||
|
|
||||||
// Curios API (软依赖)
|
// Curios API (软依赖)
|
||||||
import top.theillusivec4.curios.api.CuriosApi;
|
import top.theillusivec4.curios.api.CuriosApi;
|
||||||
|
|
@ -29,10 +34,25 @@ public record CuriosItemLocator(String slotId, int index) implements MenuLocator
|
||||||
ICurioStacksHandler stacksHandler = handler.getCurios().get(slotId);
|
ICurioStacksHandler stacksHandler = handler.getCurios().get(slotId);
|
||||||
if (stacksHandler != null) {
|
if (stacksHandler != null) {
|
||||||
ItemStack it = stacksHandler.getStacks().getStackInSlot(index);
|
ItemStack it = stacksHandler.getStacks().getStackInSlot(index);
|
||||||
if (!it.isEmpty() && it.getItem() instanceof IMenuItem guiItem) {
|
if (!it.isEmpty()) {
|
||||||
ItemMenuHost menuHost = guiItem.getMenuHost(player, -1, it, null);
|
if (it.getItem() instanceof WirelessTerminalItem) {
|
||||||
if (hostInterface.isInstance(menuHost)) {
|
// 为 Curios 构建一个带回写能力的宿主
|
||||||
return hostInterface.cast(menuHost);
|
WirelessTerminalMenuHost host = new CuriosWirelessTerminalMenuHost(
|
||||||
|
player,
|
||||||
|
it,
|
||||||
|
stacksHandler,
|
||||||
|
index,
|
||||||
|
(p, sub) -> MenuOpener.open(MEStorageMenu.WIRELESS_TYPE, p, this)
|
||||||
|
);
|
||||||
|
if (hostInterface.isInstance(host)) {
|
||||||
|
return hostInterface.cast(host);
|
||||||
|
}
|
||||||
|
} else if (it.getItem() instanceof IMenuItem guiItem) {
|
||||||
|
// 回退:非无线终端,按常规 IMenuItem 处理
|
||||||
|
ItemMenuHost menuHost = guiItem.getMenuHost(player, -1, it, null);
|
||||||
|
if (hostInterface.isInstance(menuHost)) {
|
||||||
|
return hostInterface.cast(menuHost);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user