feat: 合成计划界面,按住shift点击取消按钮,自动将缺失材料添加至jei书签
This commit is contained in:
parent
981d7c923e
commit
71351ec9c1
|
|
@ -7,7 +7,9 @@ import mezz.jei.api.runtime.IBookmarkOverlay;
|
||||||
import mezz.jei.api.runtime.IIngredientListOverlay;
|
import mezz.jei.api.runtime.IIngredientListOverlay;
|
||||||
import mezz.jei.api.runtime.IJeiRuntime;
|
import mezz.jei.api.runtime.IJeiRuntime;
|
||||||
import mezz.jei.gui.bookmarks.BookmarkList;
|
import mezz.jei.gui.bookmarks.BookmarkList;
|
||||||
|
import mezz.jei.gui.bookmarks.IngredientBookmark;
|
||||||
import mezz.jei.gui.overlay.elements.IElement;
|
import mezz.jei.gui.overlay.elements.IElement;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
@ -132,4 +134,42 @@ public final class JeiRuntimeProxy {
|
||||||
}
|
}
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将物品添加到 JEI 书签
|
||||||
|
*/
|
||||||
|
public static void addBookmark(ItemStack stack) {
|
||||||
|
IJeiRuntime rt = RUNTIME;
|
||||||
|
if (rt == null) return;
|
||||||
|
|
||||||
|
IBookmarkOverlay overlay = rt.getBookmarkOverlay();
|
||||||
|
if (overlay instanceof BookmarkOverlayAccessor accessor) {
|
||||||
|
BookmarkList list = accessor.eap$getBookmarkList();
|
||||||
|
Optional<ITypedIngredient<ItemStack>> typedOpt = rt.getIngredientManager()
|
||||||
|
.createTypedIngredient(VanillaTypes.ITEM_STACK, stack);
|
||||||
|
typedOpt.ifPresent(typed -> {
|
||||||
|
IngredientBookmark<ItemStack> bookmark = IngredientBookmark.create(typed, rt.getIngredientManager());
|
||||||
|
list.add(bookmark); // add 内部会自动保存到配置
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从 JEI 书签移除物品
|
||||||
|
*/
|
||||||
|
public static void removeBookmark(ItemStack stack) {
|
||||||
|
IJeiRuntime rt = RUNTIME;
|
||||||
|
if (rt == null) return;
|
||||||
|
|
||||||
|
IBookmarkOverlay overlay = rt.getBookmarkOverlay();
|
||||||
|
if (overlay instanceof BookmarkOverlayAccessor accessor) {
|
||||||
|
BookmarkList list = accessor.eap$getBookmarkList();
|
||||||
|
Optional<ITypedIngredient<ItemStack>> typedOpt = rt.getIngredientManager()
|
||||||
|
.createTypedIngredient(VanillaTypes.ITEM_STACK, stack);
|
||||||
|
typedOpt.ifPresent(typed -> {
|
||||||
|
IngredientBookmark<ItemStack> bookmark = IngredientBookmark.create(typed, rt.getIngredientManager());
|
||||||
|
list.remove(bookmark);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inject into CraftConfirmMenu.goBack() after it finishes and read the plan entries.
|
||||||
|
*/
|
||||||
|
@Mixin(CraftConfirmMenu.class)
|
||||||
|
public class CraftConfirmMenuGoBackMixin {
|
||||||
|
|
||||||
|
@Inject(method = "goBack", at = @At("RETURN"), remap = false)
|
||||||
|
private void 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;
|
||||||
|
|
||||||
|
// 仅在按住 shift 时为缺失的条目添加 JEI 书签
|
||||||
|
for (CraftingPlanSummaryEntry entry : entries) {
|
||||||
|
if (entry.getMissingAmount() > 0) {
|
||||||
|
JeiRuntimeProxy.addBookmark(entry.getWhat().wrapForDisplayOrFilter());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Throwable ignored) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -46,6 +46,7 @@
|
||||||
"ae2.helpers.PatternProviderLogicAdvancedMixin",
|
"ae2.helpers.PatternProviderLogicAdvancedMixin",
|
||||||
"ae2.helpers.PatternProviderLogicDoublingMixin",
|
"ae2.helpers.PatternProviderLogicDoublingMixin",
|
||||||
"ae2.menu.ContainerPatternEncodingTermMenuMixin",
|
"ae2.menu.ContainerPatternEncodingTermMenuMixin",
|
||||||
|
"ae2.menu.CraftConfirmMenuGoBackMixin",
|
||||||
"ae2.menu.MEStorageMenuMixin",
|
"ae2.menu.MEStorageMenuMixin",
|
||||||
"ae2.menu.PatternEncodingTermMenuMixin",
|
"ae2.menu.PatternEncodingTermMenuMixin",
|
||||||
"ae2.menu.PatternProviderMenuAdvancedMixin",
|
"ae2.menu.PatternProviderMenuAdvancedMixin",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user