修复F键搜索失效问题
This commit is contained in:
parent
0a820c734b
commit
af71f3ba8b
|
|
@ -2,6 +2,7 @@ package com.extendedae_plus.client;
|
||||||
|
|
||||||
import appeng.api.stacks.GenericStack;
|
import appeng.api.stacks.GenericStack;
|
||||||
import appeng.client.gui.me.common.MEStorageScreen;
|
import appeng.client.gui.me.common.MEStorageScreen;
|
||||||
|
import com.extendedae_plus.ExtendedAEPlus;
|
||||||
import com.extendedae_plus.mixin.ae2.accessor.MEStorageScreenAccessor;
|
import com.extendedae_plus.mixin.ae2.accessor.MEStorageScreenAccessor;
|
||||||
import com.extendedae_plus.mixin.extendedae.accessor.GuiExPatternTerminalAccessor;
|
import com.extendedae_plus.mixin.extendedae.accessor.GuiExPatternTerminalAccessor;
|
||||||
import com.extendedae_plus.network.OpenCraftFromJeiC2SPacket;
|
import com.extendedae_plus.network.OpenCraftFromJeiC2SPacket;
|
||||||
|
|
@ -14,11 +15,15 @@ import net.neoforged.bus.api.SubscribeEvent;
|
||||||
import net.neoforged.neoforge.client.event.ScreenEvent;
|
import net.neoforged.neoforge.client.event.ScreenEvent;
|
||||||
import net.neoforged.neoforge.network.PacketDistributor;
|
import net.neoforged.neoforge.network.PacketDistributor;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public final class InputEvents {
|
public final class InputEvents {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(InputEvents.class);
|
||||||
|
|
||||||
private InputEvents() {}
|
private InputEvents() {}
|
||||||
|
|
||||||
private static Optional<?> getIngredientUnderMouse() {
|
private static Optional<?> getIngredientUnderMouse() {
|
||||||
|
|
@ -136,14 +141,18 @@ public final class InputEvents {
|
||||||
public static void onKeyPressedPre(ScreenEvent.KeyPressed.Pre event) {
|
public static void onKeyPressedPre(ScreenEvent.KeyPressed.Pre event) {
|
||||||
if (event.getKeyCode() != GLFW.GLFW_KEY_F) return;
|
if (event.getKeyCode() != GLFW.GLFW_KEY_F) return;
|
||||||
|
|
||||||
|
var screen = Minecraft.getInstance().screen;
|
||||||
|
if (!(screen instanceof MEStorageScreen<?> || screen instanceof GuiExPatternTerminal<?>)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Optional<?> hovered = getIngredientUnderMouse();
|
Optional<?> hovered = getIngredientUnderMouse();
|
||||||
if (hovered.isEmpty()) return;
|
if (hovered.isEmpty()) {
|
||||||
|
return;}
|
||||||
|
|
||||||
Object typed = hovered.get();
|
Object typed = hovered.get();
|
||||||
String name = getTypedIngredientDisplayName(typed);
|
String name = getTypedIngredientDisplayName(typed);
|
||||||
if (name == null || name.isEmpty()) return;
|
if (name == null || name.isEmpty()) {
|
||||||
|
return;}
|
||||||
var screen = Minecraft.getInstance().screen;
|
|
||||||
if (screen instanceof MEStorageScreen<?> me) {
|
if (screen instanceof MEStorageScreen<?> me) {
|
||||||
try {
|
try {
|
||||||
MEStorageScreenAccessor acc = (MEStorageScreenAccessor) (Object) me;
|
MEStorageScreenAccessor acc = (MEStorageScreenAccessor) (Object) me;
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,10 @@ public final class JeiRuntimeProxy {
|
||||||
RUNTIME = runtime;
|
RUNTIME = runtime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Class<?> eap$getIngredientTypeClass() throws ClassNotFoundException {
|
||||||
|
return Class.forName("mezz.jei.api.ingredients.IIngredientType");
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Object get() {
|
public static Object get() {
|
||||||
return RUNTIME;
|
return RUNTIME;
|
||||||
|
|
@ -55,16 +59,17 @@ public final class JeiRuntimeProxy {
|
||||||
Object rt = RUNTIME;
|
Object rt = RUNTIME;
|
||||||
if (rt == null) return Optional.empty();
|
if (rt == null) return Optional.empty();
|
||||||
try {
|
try {
|
||||||
|
Class<?> ingredientTypeClass = eap$getIngredientTypeClass();
|
||||||
Method getRecipesGui = rt.getClass().getMethod("getRecipesGui");
|
Method getRecipesGui = rt.getClass().getMethod("getRecipesGui");
|
||||||
Object gui = getRecipesGui.invoke(rt);
|
Object gui = getRecipesGui.invoke(rt);
|
||||||
if (gui == null) return Optional.empty();
|
if (gui == null) return Optional.empty();
|
||||||
Object ingredientManager = rt.getClass().getMethod("getIngredientManager").invoke(rt);
|
Object ingredientManager = rt.getClass().getMethod("getIngredientManager").invoke(rt);
|
||||||
Class<?> vanillaTypes = Class.forName("mezz.jei.api.constants.VanillaTypes");
|
Class<?> vanillaTypes = Class.forName("mezz.jei.api.constants.VanillaTypes");
|
||||||
Object itemType = vanillaTypes.getField("ITEM_STACK").get(null);
|
Object itemType = vanillaTypes.getField("ITEM_STACK").get(null);
|
||||||
Method getUnder = gui.getClass().getMethod("getIngredientUnderMouse", itemType.getClass());
|
Method getUnder = gui.getClass().getMethod("getIngredientUnderMouse", ingredientTypeClass);
|
||||||
Object valueOpt = getUnder.invoke(gui, itemType);
|
Object valueOpt = getUnder.invoke(gui, itemType);
|
||||||
if (!(valueOpt instanceof Optional<?> value) || value.isEmpty()) return Optional.empty();
|
if (!(valueOpt instanceof Optional<?> value) || value.isEmpty()) return Optional.empty();
|
||||||
Method createTyped = ingredientManager.getClass().getMethod("createTypedIngredient", itemType.getClass(), Object.class);
|
Method createTyped = ingredientManager.getClass().getMethod("createTypedIngredient", ingredientTypeClass, Object.class);
|
||||||
Object typedOpt = createTyped.invoke(ingredientManager, itemType, value.get());
|
Object typedOpt = createTyped.invoke(ingredientManager, itemType, value.get());
|
||||||
return typedOpt instanceof Optional<?> o ? o : Optional.empty();
|
return typedOpt instanceof Optional<?> o ? o : Optional.empty();
|
||||||
} catch (Throwable ignored) {}
|
} catch (Throwable ignored) {}
|
||||||
|
|
@ -87,10 +92,11 @@ public final class JeiRuntimeProxy {
|
||||||
Object rt = RUNTIME;
|
Object rt = RUNTIME;
|
||||||
if (rt == null || typed == null) return "";
|
if (rt == null || typed == null) return "";
|
||||||
try {
|
try {
|
||||||
|
Class<?> ingredientTypeClass = eap$getIngredientTypeClass();
|
||||||
Object manager = rt.getClass().getMethod("getIngredientManager").invoke(rt);
|
Object manager = rt.getClass().getMethod("getIngredientManager").invoke(rt);
|
||||||
Method getType = typed.getClass().getMethod("getType");
|
Method getType = typed.getClass().getMethod("getType");
|
||||||
Object type = getType.invoke(typed);
|
Object type = getType.invoke(typed);
|
||||||
Method getHelper = manager.getClass().getMethod("getIngredientHelper", type.getClass());
|
Method getHelper = manager.getClass().getMethod("getIngredientHelper", ingredientTypeClass);
|
||||||
Object helper = getHelper.invoke(manager, type);
|
Object helper = getHelper.invoke(manager, type);
|
||||||
Method getIngredient = typed.getClass().getMethod("getIngredient");
|
Method getIngredient = typed.getClass().getMethod("getIngredient");
|
||||||
Object ingredient = getIngredient.invoke(typed);
|
Object ingredient = getIngredient.invoke(typed);
|
||||||
|
|
@ -144,9 +150,10 @@ public final class JeiRuntimeProxy {
|
||||||
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);
|
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, itemType, stack);
|
||||||
if (typedOpt instanceof Optional<?> opt && opt.isPresent()) {
|
if (typedOpt instanceof Optional<?> opt && opt.isPresent()) {
|
||||||
Object typed = opt.get();
|
Object typed = opt.get();
|
||||||
|
|
@ -174,9 +181,10 @@ public final class JeiRuntimeProxy {
|
||||||
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 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", fluidType.getClass(), Object.class);
|
Method createTyped = manager.getClass().getMethod("createTypedIngredient", ingredientTypeClass, Object.class);
|
||||||
Object typedOpt = createTyped.invoke(manager, fluidType, fluidStack);
|
Object typedOpt = createTyped.invoke(manager, fluidType, fluidStack);
|
||||||
if (typedOpt instanceof Optional<?> opt && opt.isPresent()) {
|
if (typedOpt instanceof Optional<?> opt && opt.isPresent()) {
|
||||||
Object typed = opt.get();
|
Object typed = opt.get();
|
||||||
|
|
@ -203,6 +211,7 @@ public final class JeiRuntimeProxy {
|
||||||
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);
|
||||||
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);
|
||||||
|
|
@ -212,7 +221,7 @@ public final class JeiRuntimeProxy {
|
||||||
}
|
}
|
||||||
if (typeField == null) return;
|
if (typeField == null) return;
|
||||||
Object typeConst = typeField.get(null);
|
Object typeConst = typeField.get(null);
|
||||||
Method createTyped = manager.getClass().getMethod("createTypedIngredient", typeConst.getClass(), Object.class);
|
Method createTyped = manager.getClass().getMethod("createTypedIngredient", ingredientTypeClass, Object.class);
|
||||||
Object typedOpt = createTyped.invoke(manager, typeConst, chemicalStack);
|
Object typedOpt = createTyped.invoke(manager, typeConst, chemicalStack);
|
||||||
if (typedOpt instanceof Optional<?> opt && opt.isPresent()) {
|
if (typedOpt instanceof Optional<?> opt && opt.isPresent()) {
|
||||||
Object typed = opt.get();
|
Object typed = opt.get();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user