Add ClientGuiInputEvent

This commit is contained in:
shedaniel
2020-12-31 20:05:26 +08:00
parent 59d42b7d4d
commit aac7d56ac9
5 changed files with 542 additions and 4 deletions

View File

@@ -0,0 +1,200 @@
/*
* This file is part of architectury.
* Copyright (C) 2020 shedaniel
*
* 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 me.shedaniel.architectury.event.events.client;
import me.shedaniel.architectury.event.Event;
import me.shedaniel.architectury.event.EventFactory;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.world.InteractionResult;
@Environment(EnvType.CLIENT)
public interface ClientGuiInputEvent {
Event<MouseScrolled> MOUSE_SCROLLED_PRE = EventFactory.of(listeners -> {
return (client, screen, mouseX, mouseY, amount) -> {
for (MouseScrolled listener : listeners) {
InteractionResult result = listener.mouseScrolled(client, screen, mouseX, mouseY, amount);
if (result != InteractionResult.PASS)
return result;
}
return InteractionResult.PASS;
};
});
Event<MouseScrolled> MOUSE_SCROLLED_POST = EventFactory.of(listeners -> {
return (client, screen, mouseX, mouseY, amount) -> {
for (MouseScrolled listener : listeners) {
InteractionResult result = listener.mouseScrolled(client, screen, mouseX, mouseY, amount);
if (result != InteractionResult.PASS)
return result;
}
return InteractionResult.PASS;
};
});
Event<MouseClicked> MOUSE_CLICKED_PRE = EventFactory.of(listeners -> {
return (client, screen, mouseX, mouseY, button) -> {
for (MouseClicked listener : listeners) {
InteractionResult result = listener.mouseClicked(client, screen, mouseX, mouseY, button);
if (result != InteractionResult.PASS)
return result;
}
return InteractionResult.PASS;
};
});
Event<MouseClicked> MOUSE_CLICKED_POST = EventFactory.of(listeners -> {
return (client, screen, mouseX, mouseY, button) -> {
for (MouseClicked listener : listeners) {
InteractionResult result = listener.mouseClicked(client, screen, mouseX, mouseY, button);
if (result != InteractionResult.PASS)
return result;
}
return InteractionResult.PASS;
};
});
Event<MouseReleased> MOUSE_RELEASED_PRE = EventFactory.of(listeners -> {
return (client, screen, mouseX, mouseY, button) -> {
for (MouseReleased listener : listeners) {
InteractionResult result = listener.mouseReleased(client, screen, mouseX, mouseY, button);
if (result != InteractionResult.PASS)
return result;
}
return InteractionResult.PASS;
};
});
Event<MouseReleased> MOUSE_RELEASED_POST = EventFactory.of(listeners -> {
return (client, screen, mouseX, mouseY, button) -> {
for (MouseReleased listener : listeners) {
InteractionResult result = listener.mouseReleased(client, screen, mouseX, mouseY, button);
if (result != InteractionResult.PASS)
return result;
}
return InteractionResult.PASS;
};
});
Event<MouseDragged> MOUSE_DRAGGED_PRE = EventFactory.of(listeners -> {
return (client, screen, mouseX1, mouseY1, button, mouseX2, mouseY2) -> {
for (MouseDragged listener : listeners) {
InteractionResult result = listener.mouseDragged(client, screen, mouseX1, mouseY1, button, mouseX2, mouseY2);
if (result != InteractionResult.PASS)
return result;
}
return InteractionResult.PASS;
};
});
Event<MouseDragged> MOUSE_DRAGGED_POST = EventFactory.of(listeners -> {
return (client, screen, mouseX1, mouseY1, button, mouseX2, mouseY2) -> {
for (MouseDragged listener : listeners) {
InteractionResult result = listener.mouseDragged(client, screen, mouseX1, mouseY1, button, mouseX2, mouseY2);
if (result != InteractionResult.PASS)
return result;
}
return InteractionResult.PASS;
};
});
Event<KeyTyped> CHAR_TYPED_PRE = EventFactory.of(listeners -> {
return (client, screen, character, keyCode) -> {
for (KeyTyped listener : listeners) {
InteractionResult result = listener.charTyped(client, screen, character, keyCode);
if (result != InteractionResult.PASS)
return result;
}
return InteractionResult.PASS;
};
});
Event<KeyTyped> CHAR_TYPED_POST = EventFactory.of(listeners -> {
return (client, screen, character, keyCode) -> {
for (KeyTyped listener : listeners) {
InteractionResult result = listener.charTyped(client, screen, character, keyCode);
if (result != InteractionResult.PASS)
return result;
}
return InteractionResult.PASS;
};
});
Event<KeyPressed> KEY_PRESSED_PRE = EventFactory.of(listeners -> {
return (client, screen, keyCode, scanCode, modifiers) -> {
for (KeyPressed listener : listeners) {
InteractionResult result = listener.keyPressed(client, screen, keyCode, scanCode, modifiers);
if (result != InteractionResult.PASS)
return result;
}
return InteractionResult.PASS;
};
});
Event<KeyPressed> KEY_PRESSED_POST = EventFactory.of(listeners -> {
return (client, screen, keyCode, scanCode, modifiers) -> {
for (KeyPressed listener : listeners) {
InteractionResult result = listener.keyPressed(client, screen, keyCode, scanCode, modifiers);
if (result != InteractionResult.PASS)
return result;
}
return InteractionResult.PASS;
};
});
Event<KeyReleased> KEY_RELEASED_PRE = EventFactory.of(listeners -> {
return (client, screen, keyCode, scanCode, modifiers) -> {
for (KeyReleased listener : listeners) {
InteractionResult result = listener.keyReleased(client, screen, keyCode, scanCode, modifiers);
if (result != InteractionResult.PASS)
return result;
}
return InteractionResult.PASS;
};
});
Event<KeyReleased> KEY_RELEASED_POST = EventFactory.of(listeners -> {
return (client, screen, keyCode, scanCode, modifiers) -> {
for (KeyReleased listener : listeners) {
InteractionResult result = listener.keyReleased(client, screen, keyCode, scanCode, modifiers);
if (result != InteractionResult.PASS)
return result;
}
return InteractionResult.PASS;
};
});
interface KeyPressed {
InteractionResult keyPressed(Minecraft client, Screen screen, int keyCode, int scanCode, int modifiers);
}
interface KeyReleased {
InteractionResult keyReleased(Minecraft client, Screen screen, int keyCode, int scanCode, int modifiers);
}
interface KeyTyped {
InteractionResult charTyped(Minecraft client, Screen screen, char character, int keyCode);
}
interface MouseScrolled {
InteractionResult mouseScrolled(Minecraft client, Screen screen, double mouseX, double mouseY, double amount);
}
interface MouseReleased {
InteractionResult mouseReleased(Minecraft client, Screen screen, double mouseX, double mouseY, int button);
}
interface MouseDragged {
InteractionResult mouseDragged(Minecraft client, Screen screen, double mouseX1, double mouseY1, int button, double mouseX2, double mouseY2);
}
interface MouseClicked {
InteractionResult mouseClicked(Minecraft client, Screen screen, double mouseX, double mouseY, int button);
}
}

View File

@@ -0,0 +1,123 @@
/*
* This file is part of architectury.
* Copyright (C) 2020 shedaniel
*
* 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 me.shedaniel.architectury.mixin.fabric.client;
import me.shedaniel.architectury.event.events.client.ClientGuiInputEvent;
import net.minecraft.client.KeyboardHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.events.ContainerEventHandler;
import net.minecraft.world.InteractionResult;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(KeyboardHandler.class)
public class MixinKeyboardHandler {
@Shadow
@Final
private Minecraft minecraft;
@Shadow
private boolean sendRepeatsToGui;
@Inject(method = "charTyped", at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/gui/screens/Screen;wrapScreenError(Ljava/lang/Runnable;Ljava/lang/String;Ljava/lang/String;)V",
ordinal = 0), cancellable = true)
public void onCharFirst(long long_1, int int_1, int int_2, CallbackInfo info) {
if (!info.isCancelled()) {
InteractionResult result = ClientGuiInputEvent.CHAR_TYPED_PRE.invoker().charTyped(minecraft, minecraft.screen, (char) int_1, int_2);
if (result != InteractionResult.PASS)
info.cancel();
}
}
@Inject(method = "charTyped", at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/gui/screens/Screen;wrapScreenError(Ljava/lang/Runnable;Ljava/lang/String;Ljava/lang/String;)V",
ordinal = 1), cancellable = true)
public void onCharSecond(long long_1, int int_1, int int_2, CallbackInfo info) {
if (!info.isCancelled()) {
InteractionResult result = ClientGuiInputEvent.CHAR_TYPED_PRE.invoker().charTyped(minecraft, minecraft.screen, (char) int_1, int_2);
if (result != InteractionResult.PASS)
info.cancel();
}
}
@Inject(method = "charTyped", at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/gui/screens/Screen;wrapScreenError(Ljava/lang/Runnable;Ljava/lang/String;Ljava/lang/String;)V",
ordinal = 0, shift = At.Shift.AFTER), cancellable = true)
public void onCharFirstPost(long long_1, int int_1, int int_2, CallbackInfo info) {
if (!info.isCancelled()) {
InteractionResult result = ClientGuiInputEvent.CHAR_TYPED_PRE.invoker().charTyped(minecraft, minecraft.screen, (char) int_1, int_2);
if (result != InteractionResult.PASS)
info.cancel();
}
}
@Inject(method = "charTyped", at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/gui/screens/Screen;wrapScreenError(Ljava/lang/Runnable;Ljava/lang/String;Ljava/lang/String;)V",
ordinal = 1, shift = At.Shift.AFTER), cancellable = true)
public void onCharSecondPost(long long_1, int int_1, int int_2, CallbackInfo info) {
if (!info.isCancelled()) {
InteractionResult result = ClientGuiInputEvent.CHAR_TYPED_PRE.invoker().charTyped(minecraft, minecraft.screen, (char) int_1, int_2);
if (result != InteractionResult.PASS)
info.cancel();
}
}
@Inject(method = "keyPress", at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/gui/screens/Screen;wrapScreenError(Ljava/lang/Runnable;Ljava/lang/String;Ljava/lang/String;)V",
ordinal = 0), cancellable = true)
public void onKey(long long_1, int int_1, int int_2, int int_3, int int_4, CallbackInfo info) {
if (!info.isCancelled()) {
if (int_3 != 1 && (int_3 != 2 || !this.sendRepeatsToGui)) {
if (int_3 == 0) {
InteractionResult result = ClientGuiInputEvent.KEY_RELEASED_PRE.invoker().keyReleased(minecraft, minecraft.screen, int_1, int_2, int_4);
if (result != InteractionResult.PASS)
info.cancel();
}
} else {
InteractionResult result = ClientGuiInputEvent.KEY_PRESSED_PRE.invoker().keyPressed(minecraft, minecraft.screen, int_1, int_2, int_4);
if (result != InteractionResult.PASS)
info.cancel();
}
}
}
@Inject(method = "keyPress", at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/gui/screens/Screen;wrapScreenError(Ljava/lang/Runnable;Ljava/lang/String;Ljava/lang/String;)V",
ordinal = 0, shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD,
cancellable = true)
public void onKeyAfter(long long_1, int int_1, int int_2, int int_3, int int_4, CallbackInfo info, ContainerEventHandler containerEventHandler, boolean bls[]) {
if (!info.isCancelled() && !bls[0]) {
InteractionResult result;
if (int_3 != 1 && (int_3 != 2 || !this.sendRepeatsToGui)) {
result = ClientGuiInputEvent.KEY_RELEASED_POST.invoker().keyReleased(minecraft, minecraft.screen, int_1, int_2, int_4);
} else {
result = ClientGuiInputEvent.KEY_PRESSED_POST.invoker().keyPressed(minecraft, minecraft.screen, int_1, int_2, int_4);
}
if (result != InteractionResult.PASS)
info.cancel();
}
}
}

View File

@@ -0,0 +1,132 @@
/*
* This file is part of architectury.
* Copyright (C) 2020 shedaniel
*
* 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 me.shedaniel.architectury.mixin.fabric.client;
import me.shedaniel.architectury.event.events.client.ClientGuiInputEvent;
import net.minecraft.client.Minecraft;
import net.minecraft.client.MouseHandler;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.world.InteractionResult;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(MouseHandler.class)
public class MixinMouseHandler {
@Shadow
@Final
private Minecraft minecraft;
@Shadow
private int activeButton;
@Shadow
private double xpos;
@Shadow
private double ypos;
@Inject(method = "onScroll",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;mouseScrolled(DDD)Z",
ordinal = 0), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
public void onMouseScrolled(long long_1, double double_1, double double_2, CallbackInfo info, double amount, double x, double y) {
if (!info.isCancelled()) {
InteractionResult result = ClientGuiInputEvent.MOUSE_SCROLLED_PRE.invoker().mouseScrolled(minecraft, minecraft.screen, x, y, amount);
if (result != InteractionResult.PASS)
info.cancel();
}
}
@Inject(method = "onScroll",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;mouseScrolled(DDD)Z",
ordinal = 0, shift = At.Shift.AFTER), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
public void onMouseScrolledPost(long long_1, double double_1, double double_2, CallbackInfo info, double amount, double x, double y) {
if (!info.isCancelled()) {
InteractionResult result = ClientGuiInputEvent.MOUSE_SCROLLED_POST.invoker().mouseScrolled(minecraft, minecraft.screen, x, y, amount);
}
}
@Inject(method = "onPress", at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/gui/screens/Screen;wrapScreenError(Ljava/lang/Runnable;Ljava/lang/String;Ljava/lang/String;)V",
ordinal = 0), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
public void onMouseClicked(long long_1, int button, int int_2, int int_3, CallbackInfo info, boolean bl, int i, boolean[] bls, double d, double e) {
if (!info.isCancelled()) {
InteractionResult result = ClientGuiInputEvent.MOUSE_CLICKED_PRE.invoker().mouseClicked(minecraft, minecraft.screen, d, e, button);
if (result != InteractionResult.PASS)
info.cancel();
}
}
@Inject(method = "onPress", at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/gui/screens/Screen;wrapScreenError(Ljava/lang/Runnable;Ljava/lang/String;Ljava/lang/String;)V",
ordinal = 0, shift = At.Shift.AFTER), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
public void onMouseClickedPost(long long_1, int button, int int_2, int int_3, CallbackInfo info, boolean bl, int i, boolean[] bls, double d, double e) {
if (!info.isCancelled()) {
InteractionResult result = ClientGuiInputEvent.MOUSE_CLICKED_POST.invoker().mouseClicked(minecraft, minecraft.screen, d, e, button);
if (result != InteractionResult.PASS)
info.cancel();
}
}
@Inject(method = "onPress", at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/gui/screens/Screen;wrapScreenError(Ljava/lang/Runnable;Ljava/lang/String;Ljava/lang/String;)V",
ordinal = 1), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
public void onMouseReleased(long long_1, int button, int int_2, int int_3, CallbackInfo info, boolean bl, int i, boolean[] bls, double d, double e) {
if (!info.isCancelled()) {
InteractionResult result = ClientGuiInputEvent.MOUSE_RELEASED_PRE.invoker().mouseReleased(minecraft, minecraft.screen, d, e, button);
if (result != InteractionResult.PASS)
info.cancel();
}
}
@Inject(method = "onPress", at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/gui/screens/Screen;wrapScreenError(Ljava/lang/Runnable;Ljava/lang/String;Ljava/lang/String;)V",
ordinal = 1, shift = At.Shift.AFTER), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
public void onMouseReleasedPost(long long_1, int button, int int_2, int int_3, CallbackInfo info, boolean bl, int i, boolean[] bls, double d, double e) {
if (!info.isCancelled()) {
InteractionResult result = ClientGuiInputEvent.MOUSE_RELEASED_POST.invoker().mouseReleased(minecraft, minecraft.screen, d, e, button);
if (result != InteractionResult.PASS)
info.cancel();
}
}
@SuppressWarnings("UnresolvedMixinReference")
@Inject(method = {"method_1602", "lambda$onMove$11"}, at = @At("HEAD"), cancellable = true)
public void onMouseDragged(GuiEventListener element, double d, double e, double f, double g, CallbackInfo info) {
if (!info.isCancelled()) {
InteractionResult result = ClientGuiInputEvent.MOUSE_DRAGGED_PRE.invoker().mouseDragged(minecraft, (Screen) element, d, e, activeButton, f, g);
if (result != InteractionResult.PASS)
info.cancel();
}
}
@SuppressWarnings("UnresolvedMixinReference")
@Inject(method = {"method_1602", "lambda$onMove$11"}, at = @At("RETURN"))
public void onMouseDraggedPost(GuiEventListener element, double d, double e, double f, double g, CallbackInfo info) {
if (!info.isCancelled()) {
ClientGuiInputEvent.MOUSE_DRAGGED_POST.invoker().mouseDragged(minecraft, (Screen) element, d, e, activeButton, f, g);
}
}
}

View File

@@ -5,7 +5,8 @@
"minVersion": "0.7.11",
"client": [
"client.MixinClientLevel", "client.MixinClientPacketListener", "client.MixinDebugScreenOverlay", "client.MixinGameRenderer", "client.MixinIntegratedServer",
"client.MixinMinecraft", "client.MixinMultiPlayerGameMode", "client.MixinScreen", "client.MixinTextureAtlas"
"client.MixinKeyboardHandler", "client.MixinMinecraft", "client.MixinMouseHandler", "client.MixinMultiPlayerGameMode", "client.MixinScreen",
"client.MixinTextureAtlas"
],
"mixins": [
"ExplosionPreInvoker", "LivingDeathInvoker", "MixinBlockItem", "MixinCommands", "MixinDedicatedServer", "MixinExplosion", "MixinFurnaceResultSlot",

View File

@@ -22,9 +22,7 @@ package me.shedaniel.architectury.event.forge;
import me.shedaniel.architectury.event.events.TextureStitchEvent;
import me.shedaniel.architectury.event.events.*;
import me.shedaniel.architectury.event.events.client.ClientChatEvent;
import me.shedaniel.architectury.event.events.client.ClientLifecycleEvent;
import me.shedaniel.architectury.event.events.client.ClientPlayerEvent;
import me.shedaniel.architectury.event.events.client.ClientTickEvent;
import me.shedaniel.architectury.event.events.client.*;
import me.shedaniel.architectury.impl.TooltipEventColorContextImpl;
import me.shedaniel.architectury.impl.TooltipEventPositionContextImpl;
import net.minecraft.client.Minecraft;
@@ -180,6 +178,90 @@ public class EventHandlerImplClient {
event.setBorderStart(colorContext.getOutlineGradientTopColor());
}
@SubscribeEvent
public static void event(GuiScreenEvent.MouseScrollEvent.Pre event) {
if (ClientGuiInputEvent.MOUSE_SCROLLED_PRE.invoker().mouseScrolled(Minecraft.getInstance(), event.getGui(), event.getMouseX(), event.getMouseY(), event.getScrollDelta()) == InteractionResult.FAIL) {
event.setCanceled(true);
}
}
@SubscribeEvent
public static void event(GuiScreenEvent.MouseScrollEvent.Post event) {
ClientGuiInputEvent.MOUSE_SCROLLED_POST.invoker().mouseScrolled(Minecraft.getInstance(), event.getGui(), event.getMouseX(), event.getMouseY(), event.getScrollDelta());
}
@SubscribeEvent
public static void event(GuiScreenEvent.MouseClickedEvent.Pre event) {
if (ClientGuiInputEvent.MOUSE_CLICKED_PRE.invoker().mouseClicked(Minecraft.getInstance(), event.getGui(), event.getMouseX(), event.getMouseY(), event.getButton()) == InteractionResult.FAIL) {
event.setCanceled(true);
}
}
@SubscribeEvent
public static void event(GuiScreenEvent.MouseClickedEvent.Post event) {
ClientGuiInputEvent.MOUSE_CLICKED_POST.invoker().mouseClicked(Minecraft.getInstance(), event.getGui(), event.getMouseX(), event.getMouseY(), event.getButton());
}
@SubscribeEvent
public static void event(GuiScreenEvent.MouseDragEvent.Pre event) {
if (ClientGuiInputEvent.MOUSE_DRAGGED_PRE.invoker().mouseDragged(Minecraft.getInstance(), event.getGui(), event.getMouseX(), event.getMouseY(), event.getMouseButton(), event.getDragX(), event.getDragY()) == InteractionResult.FAIL) {
event.setCanceled(true);
}
}
@SubscribeEvent
public static void event(GuiScreenEvent.MouseDragEvent.Post event) {
ClientGuiInputEvent.MOUSE_DRAGGED_POST.invoker().mouseDragged(Minecraft.getInstance(), event.getGui(), event.getMouseX(), event.getMouseY(), event.getMouseButton(), event.getDragX(), event.getDragY());
}
@SubscribeEvent
public static void event(GuiScreenEvent.MouseReleasedEvent.Pre event) {
if (ClientGuiInputEvent.MOUSE_RELEASED_PRE.invoker().mouseReleased(Minecraft.getInstance(), event.getGui(), event.getMouseX(), event.getMouseY(), event.getButton()) == InteractionResult.FAIL) {
event.setCanceled(true);
}
}
@SubscribeEvent
public static void event(GuiScreenEvent.MouseReleasedEvent.Post event) {
ClientGuiInputEvent.MOUSE_RELEASED_PRE.invoker().mouseReleased(Minecraft.getInstance(), event.getGui(), event.getMouseX(), event.getMouseY(), event.getButton());
}
@SubscribeEvent
public static void event(GuiScreenEvent.KeyboardCharTypedEvent.Pre event) {
if (ClientGuiInputEvent.CHAR_TYPED_PRE.invoker().charTyped(Minecraft.getInstance(), event.getGui(), event.getCodePoint(), event.getModifiers()) == InteractionResult.FAIL) {
event.setCanceled(true);
}
}
@SubscribeEvent
public static void event(GuiScreenEvent.KeyboardCharTypedEvent.Post event) {
ClientGuiInputEvent.CHAR_TYPED_POST.invoker().charTyped(Minecraft.getInstance(), event.getGui(), event.getCodePoint(), event.getModifiers());
}
@SubscribeEvent
public static void event(GuiScreenEvent.KeyboardKeyPressedEvent.Pre event) {
if (ClientGuiInputEvent.KEY_PRESSED_PRE.invoker().keyPressed(Minecraft.getInstance(), event.getGui(), event.getKeyCode(), event.getScanCode(), event.getModifiers()) == InteractionResult.FAIL) {
event.setCanceled(true);
}
}
@SubscribeEvent
public static void event(GuiScreenEvent.KeyboardKeyPressedEvent.Post event) {
ClientGuiInputEvent.KEY_PRESSED_POST.invoker().keyPressed(Minecraft.getInstance(), event.getGui(), event.getKeyCode(), event.getScanCode(), event.getModifiers());
}
@SubscribeEvent
public static void event(GuiScreenEvent.KeyboardKeyReleasedEvent.Pre event) {
if (ClientGuiInputEvent.KEY_RELEASED_PRE.invoker().keyReleased(Minecraft.getInstance(), event.getGui(), event.getKeyCode(), event.getScanCode(), event.getModifiers()) == InteractionResult.FAIL) {
event.setCanceled(true);
}
}
@SubscribeEvent
public static void event(GuiScreenEvent.KeyboardKeyReleasedEvent.Post event) {
ClientGuiInputEvent.KEY_RELEASED_POST.invoker().keyReleased(Minecraft.getInstance(), event.getGui(), event.getKeyCode(), event.getScanCode(), event.getModifiers());
}
@OnlyIn(Dist.CLIENT)
public static class ModBasedEventHandler {
@SubscribeEvent