mirror of
https://github.com/architectury/architectury-api.git
synced 2026-03-28 03:56:59 -05:00
Fix InputEvent.MouseScrollingEvent crash
This commit is contained in:
@@ -24,10 +24,10 @@ import dev.architectury.event.EventResult;
|
||||
import dev.architectury.event.events.client.ClientChatEvent;
|
||||
import dev.architectury.event.events.client.*;
|
||||
import dev.architectury.event.events.common.InteractionEvent;
|
||||
import dev.architectury.hooks.forgelike.ForgeLikeClientHooks;
|
||||
import dev.architectury.impl.ScreenAccessImpl;
|
||||
import dev.architectury.impl.TooltipEventColorContextImpl;
|
||||
import dev.architectury.impl.TooltipEventPositionContextImpl;
|
||||
import dev.architectury.platform.Platform;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
@@ -43,8 +43,6 @@ import net.minecraftforge.eventbus.api.EventPriority;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class EventHandlerImplClient {
|
||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
||||
@@ -220,40 +218,12 @@ public class EventHandlerImplClient {
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
||||
public static void eventMouseScrollEvent(ScreenEvent.MouseScrolled.Pre event) {
|
||||
double deltaX, deltaY;
|
||||
if (Platform.isNeoForge()) {
|
||||
try {
|
||||
deltaX = (double) event.getClass().getMethod("getScrollDeltaX").invoke(event);
|
||||
deltaY = (double) event.getClass().getMethod("getScrollDeltaY").invoke(event);
|
||||
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
deltaX = event.getDeltaX();
|
||||
deltaY = event.getDeltaY();
|
||||
}
|
||||
|
||||
if (ClientScreenInputEvent.MOUSE_SCROLLED_PRE.invoker().mouseScrolled(Minecraft.getInstance(), event.getScreen(), event.getMouseX(), event.getMouseY(), deltaX, deltaY).isFalse()) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
ForgeLikeClientHooks.preMouseScroll(event);
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
||||
public static void eventMouseScrollEvent(ScreenEvent.MouseScrolled.Post event) {
|
||||
double deltaX, deltaY;
|
||||
if (Platform.isNeoForge()) {
|
||||
try {
|
||||
deltaX = (double) event.getClass().getMethod("getScrollDeltaX").invoke(event);
|
||||
deltaY = (double) event.getClass().getMethod("getScrollDeltaY").invoke(event);
|
||||
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
deltaX = event.getDeltaX();
|
||||
deltaY = event.getDeltaY();
|
||||
}
|
||||
|
||||
ClientScreenInputEvent.MOUSE_SCROLLED_POST.invoker().mouseScrolled(Minecraft.getInstance(), event.getScreen(), event.getMouseX(), event.getMouseY(), deltaX, deltaY);
|
||||
ForgeLikeClientHooks.postMouseScroll(event);
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
||||
@@ -330,9 +300,7 @@ public class EventHandlerImplClient {
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
||||
public static void eventInputEvent(InputEvent.MouseScrollingEvent event) {
|
||||
if (ClientRawInputEvent.MOUSE_SCROLLED.invoker().mouseScrolled(Minecraft.getInstance(), event.getDeltaX(), event.getDeltaY()).isFalse()) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
ForgeLikeClientHooks.inputMouseScroll(event);
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
||||
@@ -356,7 +324,7 @@ public class EventHandlerImplClient {
|
||||
public static class ModBasedEventHandler {
|
||||
// @SubscribeEvent(priority = EventPriority.HIGH)
|
||||
// public static void eventTextureStitchEvent(TextureStitchEvent.Post event) {
|
||||
// ClientTextureStitchEvent.POST.invoker().stitch(event.getAtlas());
|
||||
// ClientTextureStitchEvent.POST.invoker().stitch(event.getAtlas());
|
||||
// }
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* This file is part of architectury.
|
||||
* Copyright (C) 2020, 2021, 2022 architectury
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package dev.architectury.hooks.forgelike;
|
||||
|
||||
import dev.architectury.injectables.annotations.ExpectPlatform;
|
||||
import net.minecraftforge.client.event.InputEvent;
|
||||
import net.minecraftforge.client.event.ScreenEvent;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public class ForgeLikeClientHooks {
|
||||
@ExpectPlatform
|
||||
public static void preMouseScroll(ScreenEvent.MouseScrolled.Pre event) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static void postMouseScroll(ScreenEvent.MouseScrolled.Post event) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static void inputMouseScroll(InputEvent.MouseScrollingEvent event) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* This file is part of architectury.
|
||||
* Copyright (C) 2020, 2021, 2022 architectury
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package dev.architectury.hooks.forgelike.forge;
|
||||
|
||||
import dev.architectury.event.events.client.ClientRawInputEvent;
|
||||
import dev.architectury.event.events.client.ClientScreenInputEvent;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraftforge.client.event.InputEvent;
|
||||
import net.minecraftforge.client.event.ScreenEvent;
|
||||
|
||||
public class ForgeLikeClientHooksImpl {
|
||||
public static void preMouseScroll(ScreenEvent.MouseScrolled.Pre event) {
|
||||
if (ClientScreenInputEvent.MOUSE_SCROLLED_PRE.invoker().mouseScrolled(Minecraft.getInstance(), event.getScreen(), event.getMouseX(), event.getMouseY(), event.getDeltaX(), event.getDeltaY()).isFalse()) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public static void postMouseScroll(ScreenEvent.MouseScrolled.Post event) {
|
||||
ClientScreenInputEvent.MOUSE_SCROLLED_POST.invoker().mouseScrolled(Minecraft.getInstance(), event.getScreen(), event.getMouseX(), event.getMouseY(), event.getDeltaX(), event.getDeltaY());
|
||||
}
|
||||
|
||||
public static void inputMouseScroll(InputEvent.MouseScrollingEvent event) {
|
||||
if (ClientRawInputEvent.MOUSE_SCROLLED.invoker().mouseScrolled(Minecraft.getInstance(), event.getDeltaX(), event.getDeltaY()).isFalse()) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* This file is part of architectury.
|
||||
* Copyright (C) 2020, 2021, 2022 architectury
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package dev.architectury.hooks.forgelike.forge;
|
||||
|
||||
import dev.architectury.event.events.client.ClientRawInputEvent;
|
||||
import dev.architectury.event.events.client.ClientScreenInputEvent;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.neoforged.neoforge.client.event.InputEvent;
|
||||
import net.neoforged.neoforge.client.event.ScreenEvent;
|
||||
|
||||
public class ForgeLikeClientHooksImpl {
|
||||
public static void preMouseScroll(ScreenEvent.MouseScrolled.Pre event) {
|
||||
if (ClientScreenInputEvent.MOUSE_SCROLLED_PRE.invoker().mouseScrolled(Minecraft.getInstance(), event.getScreen(), event.getMouseX(), event.getMouseY(), event.getScrollDeltaX(), event.getScrollDeltaY()).isFalse()) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public static void postMouseScroll(ScreenEvent.MouseScrolled.Post event) {
|
||||
ClientScreenInputEvent.MOUSE_SCROLLED_POST.invoker().mouseScrolled(Minecraft.getInstance(), event.getScreen(), event.getMouseX(), event.getMouseY(), event.getScrollDeltaX(), event.getScrollDeltaY());
|
||||
}
|
||||
|
||||
public static void inputMouseScroll(InputEvent.MouseScrollingEvent event) {
|
||||
if (ClientRawInputEvent.MOUSE_SCROLLED.invoker().mouseScrolled(Minecraft.getInstance(), event.getScrollDeltaX(), event.getScrollDeltaY()).isFalse()) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user