修复jei不存在时classnotfonud的问题
This commit is contained in:
parent
b812dac9de
commit
39f89183e7
|
|
@ -18,6 +18,7 @@ import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.client.event.ScreenEvent;
|
import net.minecraftforge.client.event.ScreenEvent;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.fml.ModList;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
@ -28,8 +29,17 @@ public final class InputEvents {
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onMouseButtonPre(ScreenEvent.MouseButtonPressed.Pre event) {
|
public static void onMouseButtonPre(ScreenEvent.MouseButtonPressed.Pre event) {
|
||||||
|
// 若未安装 JEI,直接跳过,避免触发 JEI 类加载导致的 NoClassDefFoundError
|
||||||
|
if (!ModList.get().isLoaded("jei")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 若 JEI 运行时尚未就绪,跳过
|
||||||
|
if (JeiRuntimeProxy.get() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 优先处理:Shift + 左键(拉取或下单)
|
// 优先处理:Shift + 左键(拉取或下单)
|
||||||
if (event.getButton() == GLFW.GLFW_MOUSE_BUTTON_LEFT && Screen.hasShiftDown()) {
|
if (event.getButton() == GLFW.GLFW_MOUSE_BUTTON_LEFT && Screen.hasShiftDown()) {
|
||||||
|
try {
|
||||||
double mouseX = event.getMouseX();
|
double mouseX = event.getMouseX();
|
||||||
double mouseY = event.getMouseY();
|
double mouseY = event.getMouseY();
|
||||||
Optional<ITypedIngredient<?>> hovered = JeiRuntimeProxy.getIngredientUnderMouse(mouseX, mouseY);
|
Optional<ITypedIngredient<?>> hovered = JeiRuntimeProxy.getIngredientUnderMouse(mouseX, mouseY);
|
||||||
|
|
@ -51,10 +61,14 @@ public final class InputEvents {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
// 兼容 JEI 版本差异或运行时异常
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 中键:打开 AE 下单界面(保持原有功能)
|
// 中键:打开 AE 下单界面(保持原有功能)
|
||||||
if (event.getButton() == GLFW.GLFW_MOUSE_BUTTON_MIDDLE) {
|
if (event.getButton() == GLFW.GLFW_MOUSE_BUTTON_MIDDLE) {
|
||||||
|
try {
|
||||||
// 优先在 JEI 配方界面基于坐标获取;若无,再从覆盖层/书签获取
|
// 优先在 JEI 配方界面基于坐标获取;若无,再从覆盖层/书签获取
|
||||||
double mouseX = event.getMouseX();
|
double mouseX = event.getMouseX();
|
||||||
double mouseY = event.getMouseY();
|
double mouseY = event.getMouseY();
|
||||||
|
|
@ -77,14 +91,25 @@ public final class InputEvents {
|
||||||
|
|
||||||
// 消费此次点击,避免 JEI/原版对中键的其它处理
|
// 消费此次点击,避免 JEI/原版对中键的其它处理
|
||||||
event.setCanceled(true);
|
event.setCanceled(true);
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
// 兼容 JEI 版本差异或运行时异常
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onKeyPressedPre(ScreenEvent.KeyPressed.Pre event) {
|
public static void onKeyPressedPre(ScreenEvent.KeyPressed.Pre event) {
|
||||||
|
// 若未安装 JEI,直接跳过
|
||||||
|
if (!ModList.get().isLoaded("jei")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (JeiRuntimeProxy.get() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (event.getKeyCode() != GLFW.GLFW_KEY_F) return;
|
if (event.getKeyCode() != GLFW.GLFW_KEY_F) return;
|
||||||
|
|
||||||
// 仅当鼠标确实悬停在 JEI 配料上时触发
|
// 仅当鼠标确实悬停在 JEI 配料上时触发
|
||||||
|
try {
|
||||||
Optional<ITypedIngredient<?>> hovered = JeiRuntimeProxy.getIngredientUnderMouse();
|
Optional<ITypedIngredient<?>> hovered = JeiRuntimeProxy.getIngredientUnderMouse();
|
||||||
if (hovered.isEmpty()) return;
|
if (hovered.isEmpty()) return;
|
||||||
|
|
||||||
|
|
@ -111,5 +136,8 @@ public final class InputEvents {
|
||||||
event.setCanceled(true);
|
event.setCanceled(true);
|
||||||
}catch (Throwable ignored) {}
|
}catch (Throwable ignored) {}
|
||||||
}
|
}
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
// 兼容 JEI 版本差异或运行时异常
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user