fix:合成界面shift取消添加书签功能
This commit is contained in:
parent
c599dfb198
commit
f77e9dc6a4
|
|
@ -238,97 +238,32 @@ public final class JeiRuntimeProxy {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addBookmark(ItemStack stack) {
|
public static void addBookmark(ItemStack stack) {
|
||||||
Object rt = RUNTIME;
|
if (stack == null || stack.isEmpty()) {
|
||||||
if (rt == null || stack == null || stack.isEmpty()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Object overlay = rt.getClass().getMethod("getBookmarkOverlay").invoke(rt);
|
|
||||||
if (overlay == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Field f = overlay.getClass().getDeclaredField("bookmarkList");
|
|
||||||
f.setAccessible(true);
|
|
||||||
Object list = f.get(overlay);
|
|
||||||
Class<?> ingredientTypeClass = eap$getIngredientTypeClass();
|
|
||||||
Object manager = rt.getClass().getMethod("getIngredientManager").invoke(rt);
|
|
||||||
Object itemType = Class.forName("mezz.jei.api.constants.VanillaTypes").getField("ITEM_STACK").get(null);
|
Object itemType = Class.forName("mezz.jei.api.constants.VanillaTypes").getField("ITEM_STACK").get(null);
|
||||||
Method createTyped = manager.getClass().getMethod("createTypedIngredient", ingredientTypeClass, Object.class);
|
eap$addBookmarkInternal(itemType, stack);
|
||||||
Object typedOpt = createTyped.invoke(manager, itemType, stack);
|
|
||||||
if (typedOpt instanceof Optional<?> opt && opt.isPresent()) {
|
|
||||||
Object typed = opt.get();
|
|
||||||
Class<?> ibCls = Class.forName("mezz.jei.gui.bookmarks.IngredientBookmark");
|
|
||||||
Method create = null;
|
|
||||||
for (Method m : ibCls.getMethods()) {
|
|
||||||
if (m.getName().equals("create") && m.getParameterCount() == 2) {
|
|
||||||
create = m;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (create != null) {
|
|
||||||
Object bookmark = create.invoke(null, typed, manager);
|
|
||||||
list.getClass().getMethod("add", ibCls).invoke(list, bookmark);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Throwable ignored) {
|
} catch (Throwable ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addBookmark(FluidStack fluidStack) {
|
public static void addBookmark(FluidStack fluidStack) {
|
||||||
Object rt = RUNTIME;
|
if (fluidStack == null) {
|
||||||
if (rt == null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Object overlay = rt.getClass().getMethod("getBookmarkOverlay").invoke(rt);
|
|
||||||
if (overlay == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Field f = overlay.getClass().getDeclaredField("bookmarkList");
|
|
||||||
f.setAccessible(true);
|
|
||||||
Object list = f.get(overlay);
|
|
||||||
Class<?> ingredientTypeClass = eap$getIngredientTypeClass();
|
|
||||||
Object manager = rt.getClass().getMethod("getIngredientManager").invoke(rt);
|
|
||||||
Object fluidType = Class.forName("mezz.jei.api.neoforge.NeoForgeTypes").getField("FLUID_STACK").get(null);
|
Object fluidType = Class.forName("mezz.jei.api.neoforge.NeoForgeTypes").getField("FLUID_STACK").get(null);
|
||||||
Method createTyped = manager.getClass().getMethod("createTypedIngredient", ingredientTypeClass, Object.class);
|
eap$addBookmarkInternal(fluidType, fluidStack);
|
||||||
Object typedOpt = createTyped.invoke(manager, fluidType, fluidStack);
|
|
||||||
if (typedOpt instanceof Optional<?> opt && opt.isPresent()) {
|
|
||||||
Object typed = opt.get();
|
|
||||||
Class<?> ibCls = Class.forName("mezz.jei.gui.bookmarks.IngredientBookmark");
|
|
||||||
Method create = null;
|
|
||||||
for (Method m : ibCls.getMethods()) {
|
|
||||||
if (m.getName().equals("create") && m.getParameterCount() == 2) {
|
|
||||||
create = m;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (create != null) {
|
|
||||||
Object bookmark = create.invoke(null, typed, manager);
|
|
||||||
list.getClass().getMethod("add", ibCls).invoke(list, bookmark);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Throwable ignored) {
|
} catch (Throwable ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addBookmark(Object chemicalStack) {
|
public static void addBookmark(Object chemicalStack) {
|
||||||
if (!ModList.get().isLoaded("mekanism") && !ModList.get().isLoaded("appmek")) {
|
if ((!ModList.get().isLoaded("mekanism") && !ModList.get().isLoaded("appmek")) || chemicalStack == null) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
Object rt = RUNTIME;
|
|
||||||
if (rt == null || chemicalStack == null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Object overlay = rt.getClass().getMethod("getBookmarkOverlay").invoke(rt);
|
|
||||||
if (overlay == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Field f = overlay.getClass().getDeclaredField("bookmarkList");
|
|
||||||
f.setAccessible(true);
|
|
||||||
Object list = f.get(overlay);
|
|
||||||
Class<?> ingredientTypeClass = eap$getIngredientTypeClass();
|
|
||||||
Object manager = rt.getClass().getMethod("getIngredientManager").invoke(rt);
|
|
||||||
String mekanismJeiClass = "mekanism.client.recipe_viewer.jei.MekanismJEI";
|
String mekanismJeiClass = "mekanism.client.recipe_viewer.jei.MekanismJEI";
|
||||||
Class<?> jeiCls = Class.forName(mekanismJeiClass);
|
Class<?> jeiCls = Class.forName(mekanismJeiClass);
|
||||||
Field typeField = null;
|
Field typeField = null;
|
||||||
|
|
@ -339,58 +274,49 @@ public final class JeiRuntimeProxy {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Object typeConst = typeField.get(null);
|
Object typeConst = typeField.get(null);
|
||||||
Method createTyped = manager.getClass().getMethod("createTypedIngredient", ingredientTypeClass, Object.class);
|
eap$addBookmarkInternal(typeConst, chemicalStack);
|
||||||
Object typedOpt = createTyped.invoke(manager, typeConst, chemicalStack);
|
|
||||||
if (typedOpt instanceof Optional<?> opt && opt.isPresent()) {
|
|
||||||
Object typed = opt.get();
|
|
||||||
Class<?> ibCls = Class.forName("mezz.jei.gui.bookmarks.IngredientBookmark");
|
|
||||||
Method create = null;
|
|
||||||
for (Method m : ibCls.getMethods()) {
|
|
||||||
if (m.getName().equals("create") && m.getParameterCount() == 2) {
|
|
||||||
create = m;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (create != null) {
|
|
||||||
Object bookmark = create.invoke(null, typed, manager);
|
|
||||||
list.getClass().getMethod("add", ibCls).invoke(list, bookmark);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Throwable ignored) {
|
} catch (Throwable ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeBookmark(ItemStack stack) {
|
/**
|
||||||
|
* 内部方法:将指定类型的原料添加到 JEI 书签列表
|
||||||
|
* @param ingredientType 原料类型(如 ITEM_STACK、FLUID_STACK 等)
|
||||||
|
* @param ingredient 原料对象(如 ItemStack、FluidStack 等)
|
||||||
|
*/
|
||||||
|
private static void eap$addBookmarkInternal(Object ingredientType, Object ingredient) {
|
||||||
Object rt = RUNTIME;
|
Object rt = RUNTIME;
|
||||||
if (rt == null || stack == null || stack.isEmpty()) {
|
if (rt == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
// 获取书签覆盖层对象
|
||||||
Object overlay = rt.getClass().getMethod("getBookmarkOverlay").invoke(rt);
|
Object overlay = rt.getClass().getMethod("getBookmarkOverlay").invoke(rt);
|
||||||
if (overlay == null) {
|
if (overlay == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// 获取书签列表对象
|
||||||
Field f = overlay.getClass().getDeclaredField("bookmarkList");
|
Field f = overlay.getClass().getDeclaredField("bookmarkList");
|
||||||
f.setAccessible(true);
|
f.setAccessible(true);
|
||||||
Object list = f.get(overlay);
|
Object list = f.get(overlay);
|
||||||
|
// 获取原料管理器
|
||||||
|
Class<?> ingredientTypeClass = eap$getIngredientTypeClass();
|
||||||
Object manager = rt.getClass().getMethod("getIngredientManager").invoke(rt);
|
Object manager = rt.getClass().getMethod("getIngredientManager").invoke(rt);
|
||||||
Object itemType = Class.forName("mezz.jei.api.constants.VanillaTypes").getField("ITEM_STACK").get(null);
|
// 创建类型化的原料对象
|
||||||
Method createTyped = manager.getClass().getMethod("createTypedIngredient", itemType.getClass(), Object.class);
|
Method createTyped = manager.getClass().getMethod("createTypedIngredient", ingredientTypeClass, Object.class);
|
||||||
Object typedOpt = createTyped.invoke(manager, itemType, stack);
|
Object typedOpt = createTyped.invoke(manager, ingredientType, ingredient);
|
||||||
if (typedOpt instanceof Optional<?> opt && opt.isPresent()) {
|
if (typedOpt instanceof Optional<?> opt && opt.isPresent()) {
|
||||||
Object typed = opt.get();
|
Object typed = opt.get();
|
||||||
Class<?> ibCls = Class.forName("mezz.jei.gui.bookmarks.IngredientBookmark");
|
// 从 BookmarkList 获取 bookmarkFactory 字段
|
||||||
Method create = null;
|
Field factoryField = list.getClass().getDeclaredField("bookmarkFactory");
|
||||||
for (Method m : ibCls.getMethods()) {
|
factoryField.setAccessible(true);
|
||||||
if (m.getName().equals("create") && m.getParameterCount() == 2) {
|
Object factory = factoryField.get(list);
|
||||||
create = m;
|
// 调用 bookmarkFactory.create() 创建书签对象
|
||||||
break;
|
Method create = factory.getClass().getMethod("create", Class.forName("mezz.jei.api.ingredients.ITypedIngredient"));
|
||||||
}
|
Object bookmark = create.invoke(factory, typed);
|
||||||
}
|
// 将书签添加到列表
|
||||||
if (create != null) {
|
Class<?> ibCls = Class.forName("mezz.jei.gui.bookmarks.IBookmark");
|
||||||
Object bookmark = create.invoke(null, typed, manager);
|
list.getClass().getMethod("add", ibCls).invoke(list, bookmark);
|
||||||
list.getClass().getMethod("remove", ibCls).invoke(list, bookmark);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (Throwable ignored) {
|
} catch (Throwable ignored) {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,14 @@ versionRange = "*"
|
||||||
ordering = "AFTER"
|
ordering = "AFTER"
|
||||||
side = "BOTH"
|
side = "BOTH"
|
||||||
|
|
||||||
|
# Require JEI (version >= 19.27.0.336) for bookmark integration
|
||||||
|
[[dependencies.${ mod_id }]]
|
||||||
|
modId = "jei"
|
||||||
|
type = "optional"
|
||||||
|
versionRange = "[19.27.0.336,)"
|
||||||
|
ordering = "NONE"
|
||||||
|
side = "CLIENT"
|
||||||
|
|
||||||
# Features are specific properties of the game environment, that you may want to declare you require. This example declares
|
# Features are specific properties of the game environment, that you may want to declare you require. This example declares
|
||||||
# that your mod requires GL version 3.2 or higher. Other features will be added. They are side aware so declaring this won't
|
# that your mod requires GL version 3.2 or higher. Other features will be added. They are side aware so declaring this won't
|
||||||
# stop your mod loading on the server for example.
|
# stop your mod loading on the server for example.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user