一键添加缺失物品书签
This commit is contained in:
parent
9545180f09
commit
02c936ea0f
|
|
@ -7,7 +7,9 @@ import mezz.jei.api.runtime.IBookmarkOverlay;
|
|||
import mezz.jei.api.runtime.IIngredientListOverlay;
|
||||
import mezz.jei.api.runtime.IJeiRuntime;
|
||||
import mezz.jei.gui.bookmarks.BookmarkList;
|
||||
import mezz.jei.gui.bookmarks.IngredientBookmark;
|
||||
import mezz.jei.gui.overlay.elements.IElement;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
|
|
@ -132,4 +134,44 @@ public final class JeiRuntimeProxy {
|
|||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将物品添加到 JEI 书签
|
||||
*/
|
||||
public static void addBookmark(ItemStack stack) {
|
||||
IJeiRuntime rt = RUNTIME;
|
||||
if (rt == null || stack == null || stack.isEmpty()) return;
|
||||
|
||||
IBookmarkOverlay overlay = rt.getBookmarkOverlay();
|
||||
if (overlay instanceof BookmarkOverlayAccessor accessor) {
|
||||
BookmarkList list = accessor.eap$getBookmarkList();
|
||||
try {
|
||||
var typedOpt = rt.getIngredientManager().createTypedIngredient(VanillaTypes.ITEM_STACK, stack);
|
||||
typedOpt.ifPresent(typed -> {
|
||||
IngredientBookmark<ItemStack> bookmark = IngredientBookmark.create(typed, rt.getIngredientManager());
|
||||
list.add(bookmark); // add 内部会自动保存到配置
|
||||
});
|
||||
} catch (Throwable ignored) {}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 JEI 书签移除物品
|
||||
*/
|
||||
public static void removeBookmark(ItemStack stack) {
|
||||
IJeiRuntime rt = RUNTIME;
|
||||
if (rt == null || stack == null || stack.isEmpty()) return;
|
||||
|
||||
IBookmarkOverlay overlay = rt.getBookmarkOverlay();
|
||||
if (overlay instanceof BookmarkOverlayAccessor accessor) {
|
||||
BookmarkList list = accessor.eap$getBookmarkList();
|
||||
try {
|
||||
var typedOpt = rt.getIngredientManager().createTypedIngredient(VanillaTypes.ITEM_STACK, stack);
|
||||
typedOpt.ifPresent(typed -> {
|
||||
IngredientBookmark<ItemStack> bookmark = IngredientBookmark.create(typed, rt.getIngredientManager());
|
||||
list.remove(bookmark);
|
||||
});
|
||||
} catch (Throwable ignored) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,56 @@
|
|||
package com.extendedae_plus.mixin.ae2.menu;
|
||||
|
||||
import appeng.menu.me.crafting.CraftConfirmMenu;
|
||||
import appeng.menu.me.crafting.CraftingPlanSummary;
|
||||
import appeng.menu.me.crafting.CraftingPlanSummaryEntry;
|
||||
import com.extendedae_plus.integration.jei.JeiRuntimeProxy;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 在 CraftConfirmMenu.goBack() 结束后(RETURN)处理:
|
||||
* 若客户端按住 Shift,则将缺失条目添加到 JEI 书签,便于后续合成或标记。
|
||||
*/
|
||||
@Mixin(value = CraftConfirmMenu.class, remap = false)
|
||||
public class CraftConfirmMenuGoBackMixin {
|
||||
|
||||
@Inject(method = "goBack", at = @At("RETURN"))
|
||||
private void eap$afterGoBack(CallbackInfo ci) {
|
||||
CraftConfirmMenu self = (CraftConfirmMenu) (Object) this;
|
||||
try {
|
||||
// 仅客户端执行
|
||||
if (!self.isClientSide()) return;
|
||||
|
||||
// 检测是否按住 Shift
|
||||
boolean shiftDown = false;
|
||||
try {
|
||||
shiftDown = Screen.hasShiftDown();
|
||||
} catch (Throwable ignored) {}
|
||||
if (!shiftDown) return;
|
||||
|
||||
// 获取合成计划摘要与条目
|
||||
CraftingPlanSummary plan = self.getPlan();
|
||||
if (plan == null) return;
|
||||
List<CraftingPlanSummaryEntry> entries = plan.getEntries();
|
||||
if (entries == null || entries.isEmpty()) return;
|
||||
|
||||
// 为缺失的条目添加 JEI 书签
|
||||
for (CraftingPlanSummaryEntry entry : entries) {
|
||||
if (entry.getMissingAmount() > 0) {
|
||||
try {
|
||||
var display = entry.getWhat().wrapForDisplayOrFilter();
|
||||
if (display != null && !display.isEmpty()) {
|
||||
// wrapForDisplayOrFilter 返回 ItemStack
|
||||
JeiRuntimeProxy.addBookmark(display);
|
||||
}
|
||||
} catch (Throwable ignored) {}
|
||||
}
|
||||
}
|
||||
} catch (Throwable ignored) {}
|
||||
}
|
||||
}
|
||||
|
|
@ -36,6 +36,7 @@
|
|||
"PickFromWirelessMixin",
|
||||
"accessor.AbstractContainerScreenAccessor",
|
||||
"accessor.ScreenAccessor",
|
||||
"ae2.menu.CraftConfirmMenuGoBackMixin",
|
||||
"ae2.accessor.AEBaseScreenAccessor",
|
||||
"ae2.accessor.AEBaseScreenInvoker",
|
||||
"ae2.accessor.MEStorageScreenAccessor",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user