diff --git a/fabric/build.gradle b/fabric/build.gradle index 15ceeb97..f8e4d2b9 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -128,7 +128,7 @@ unifiedPublishing { curseforge { token = CURSE_API_KEY id = rootProject.curseforge_id - gameVersions.addAll "Java 21", "1.21.2-Snapshot"//, project.minecraft_version + gameVersions.addAll "Java 21", "1.21.2-Snapshot", project.minecraft_version } } diff --git a/fabric/src/main/java/dev/architectury/mixin/fabric/client/MixinKeyboardHandler.java b/fabric/src/main/java/dev/architectury/mixin/fabric/client/MixinKeyboardHandler.java index b28e4128..c0c64767 100644 --- a/fabric/src/main/java/dev/architectury/mixin/fabric/client/MixinKeyboardHandler.java +++ b/fabric/src/main/java/dev/architectury/mixin/fabric/client/MixinKeyboardHandler.java @@ -19,21 +19,19 @@ package dev.architectury.mixin.fabric.client; -import com.llamalad7.mixinextras.sugar.Local; -import dev.architectury.event.EventResult; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import dev.architectury.event.events.client.ClientRawInputEvent; import dev.architectury.event.events.client.ClientScreenInputEvent; import dev.architectury.impl.fabric.ScreenInputDelegate; import net.minecraft.client.KeyboardHandler; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.screens.Screen; 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.ModifyVariable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(KeyboardHandler.class) @@ -42,56 +40,34 @@ public class MixinKeyboardHandler { @Final private Minecraft minecraft; - @ModifyVariable(method = {"method_1458", "lambda$charTyped$6"}, at = @At("HEAD"), ordinal = 0, argsOnly = true) - private static GuiEventListener wrapCharTypedFirst(GuiEventListener screen) { + @WrapOperation(method = "charTyped", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;charTyped(CI)Z")) + private boolean wrapCharTyped(Screen screen, char chr, int mods, Operation original) { if (screen instanceof ScreenInputDelegate delegate) { - return delegate.architectury_delegateInputs(); + return original.call(delegate.architectury_delegateInputs(), chr, mods); } - return screen; + return original.call(screen, chr, mods); } - @ModifyVariable(method = {"method_1473", "lambda$charTyped$7"}, at = @At("HEAD"), ordinal = 0, argsOnly = true) - private static GuiEventListener wrapCharTypedSecond(GuiEventListener screen) { - if (screen instanceof ScreenInputDelegate delegate) { - return delegate.architectury_delegateInputs(); - } - return screen; - } - - @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) { - if (int_3 == 0) { - var result = ClientScreenInputEvent.KEY_RELEASED_PRE.invoker().keyReleased(minecraft, minecraft.screen, int_1, int_2, int_4); - if (result.isPresent()) - info.cancel(); - } - } else { - var result = ClientScreenInputEvent.KEY_PRESSED_PRE.invoker().keyPressed(minecraft, minecraft.screen, int_1, int_2, int_4); - if (result.isPresent()) - info.cancel(); - } - } + @WrapOperation(method = "keyPress", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;keyPressed(III)Z")) + private boolean wrapKeyPressed(Screen screen, int keyCode, int scanCode, int modifiers, Operation original) { + var result = ClientScreenInputEvent.KEY_PRESSED_PRE.invoker().keyPressed(minecraft, screen, keyCode, scanCode, modifiers); + if (result.isPresent()) + return true; + if (original.call(screen, keyCode, scanCode, modifiers)) + return true; + result = ClientScreenInputEvent.KEY_PRESSED_POST.invoker().keyPressed(minecraft, screen, keyCode, scanCode, modifiers); + return result.isPresent(); } - @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), - cancellable = true) - public void onKeyAfter(long long_1, int int_1, int int_2, int int_3, int int_4, CallbackInfo info, @Local Screen screen, @Local boolean[] bls) { - if (!info.isCancelled() && !bls[0]) { - EventResult result; - if (int_3 != 1 && int_3 != 2) { - result = ClientScreenInputEvent.KEY_RELEASED_POST.invoker().keyReleased(minecraft, screen, int_1, int_2, int_4); - } else { - result = ClientScreenInputEvent.KEY_PRESSED_POST.invoker().keyPressed(minecraft, screen, int_1, int_2, int_4); - } - if (result.isPresent()) - info.cancel(); - } + @WrapOperation(method = "keyPress", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;keyReleased(III)Z")) + private boolean wrapKeyReleased(Screen screen, int keyCode, int scanCode, int modifiers, Operation original) { + var result = ClientScreenInputEvent.KEY_PRESSED_PRE.invoker().keyPressed(minecraft, screen, keyCode, scanCode, modifiers); + if (result.isPresent()) + return true; + if (original.call(screen, keyCode, scanCode, modifiers)) + return true; + result = ClientScreenInputEvent.KEY_PRESSED_POST.invoker().keyPressed(minecraft, screen, keyCode, scanCode, modifiers); + return result.isPresent(); } @Inject(method = "keyPress", at = @At("RETURN"), cancellable = true) diff --git a/fabric/src/main/java/dev/architectury/mixin/fabric/client/MixinMouseHandler.java b/fabric/src/main/java/dev/architectury/mixin/fabric/client/MixinMouseHandler.java index c641d1cd..0fe8ee89 100644 --- a/fabric/src/main/java/dev/architectury/mixin/fabric/client/MixinMouseHandler.java +++ b/fabric/src/main/java/dev/architectury/mixin/fabric/client/MixinMouseHandler.java @@ -19,6 +19,9 @@ package dev.architectury.mixin.fabric.client; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; import dev.architectury.event.events.client.ClientRawInputEvent; import dev.architectury.event.events.client.ClientScreenInputEvent; import net.minecraft.client.Minecraft; @@ -29,7 +32,6 @@ 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.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; @@ -79,27 +81,25 @@ public void onRawMouseScrolled(long handle, double xOffset, double yOffset, Call } } - @SuppressWarnings("UnresolvedMixinReference") - @Inject(method = {"lambda$onPress$0", "method_1611"}, at = @At("HEAD"), cancellable = true, remap = false) - private static void onGuiMouseClicked(boolean[] bls, Screen screen, double d, double e, int button, CallbackInfo info) { + @Inject(method = "onPress", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;mouseClicked(DDI)Z", ordinal = 0), cancellable = true) + private void onGuiMouseClicked(long window, int button, int action, int mods, CallbackInfo info, + @Local(ordinal = 0) double mouseX, @Local(ordinal = 1) double mouseY, @Local(ordinal = 3) int b) { var minecraft = Minecraft.getInstance(); if (!info.isCancelled()) { - var result = ClientScreenInputEvent.MOUSE_CLICKED_PRE.invoker().mouseClicked(minecraft, screen, d, e, button); + var result = ClientScreenInputEvent.MOUSE_CLICKED_PRE.invoker().mouseClicked(minecraft, minecraft.screen, mouseX, mouseY, b); if (result.isPresent()) { - bls[0] = true; info.cancel(); } } } - @SuppressWarnings("UnresolvedMixinReference") - @Inject(method = {"lambda$onPress$0", "method_1611"}, at = @At("RETURN"), cancellable = true, remap = false) - private static void onGuiMouseClickedPost(boolean[] bls, Screen screen, double d, double e, int button, CallbackInfo info) { + @Inject(method = "onPress", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;mouseClicked(DDI)Z", ordinal = 0, shift = At.Shift.AFTER), cancellable = true) + private void onGuiMouseClickedPost(long window, int button, int action, int mods, CallbackInfo info, + @Local(ordinal = 0) double mouseX, @Local(ordinal = 1) double mouseY, @Local(ordinal = 3) int b) { var minecraft = Minecraft.getInstance(); - if (!info.isCancelled() && !bls[0]) { - var result = ClientScreenInputEvent.MOUSE_CLICKED_POST.invoker().mouseClicked(minecraft, screen, d, e, button); + if (!info.isCancelled()) { + var result = ClientScreenInputEvent.MOUSE_CLICKED_POST.invoker().mouseClicked(minecraft, minecraft.screen, mouseX, mouseY, b); if (result.isPresent()) { - bls[0] = true; info.cancel(); } } @@ -125,46 +125,44 @@ public void onRawMouseClickedPost(long handle, int button, int action, int mods, } } - @SuppressWarnings("UnresolvedMixinReference") - @Inject(method = {"lambda$onPress$1", "method_1605"}, at = @At("HEAD"), cancellable = true, remap = false) - private static void onGuiMouseReleased(boolean[] bls, Screen screen, double d, double e, int button, CallbackInfo info) { + @Inject(method = "onPress", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;mouseReleased(DDI)Z", ordinal = 0), cancellable = true) + private void onGuiMouseReleased(long window, int button, int action, int mods, CallbackInfo info, + @Local(ordinal = 0) double mouseX, @Local(ordinal = 1) double mouseY, @Local(ordinal = 3) int b) { var minecraft = Minecraft.getInstance(); if (!info.isCancelled()) { - var result = ClientScreenInputEvent.MOUSE_RELEASED_PRE.invoker().mouseReleased(minecraft, screen, d, e, button); + var result = ClientScreenInputEvent.MOUSE_RELEASED_PRE.invoker().mouseReleased(minecraft, minecraft.screen, mouseX, mouseY, b); if (result.isPresent()) { - bls[0] = true; info.cancel(); } } } - @SuppressWarnings("UnresolvedMixinReference") - @Inject(method = {"lambda$onPress$1", "method_1605"}, at = @At("RETURN"), cancellable = true, remap = false) - private static void onGuiMouseReleasedPost(boolean[] bls, Screen screen, double d, double e, int button, CallbackInfo info) { + @Inject(method = "onPress", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;mouseReleased(DDI)Z", ordinal = 0, shift = At.Shift.AFTER), cancellable = true) + private void onGuiMouseReleasedPost(long window, int button, int action, int mods, CallbackInfo info, + @Local(ordinal = 0) double mouseX, @Local(ordinal = 1) double mouseY, @Local(ordinal = 3) int b) { var minecraft = Minecraft.getInstance(); - if (!info.isCancelled() && !bls[0]) { - var result = ClientScreenInputEvent.MOUSE_RELEASED_POST.invoker().mouseReleased(minecraft, screen, d, e, button); + if (!info.isCancelled()) { + var result = ClientScreenInputEvent.MOUSE_RELEASED_POST.invoker().mouseReleased(minecraft, minecraft.screen, mouseX, mouseY, b); if (result.isPresent()) { - bls[0] = true; info.cancel(); } } } - @SuppressWarnings("UnresolvedMixinReference") - @Inject(method = {"method_55795", "lambda$handleAccumulatedMovement$11"}, at = @At("HEAD"), cancellable = true, remap = false) - private void onGuiMouseDraggedPre(Screen screen, double mouseX, double mouseY, double deltaX, double deltaY, CallbackInfo ci) { - if (ClientScreenInputEvent.MOUSE_DRAGGED_PRE.invoker().mouseDragged(Minecraft.getInstance(), screen, mouseX, mouseY, this.activeButton, deltaX, deltaY).isPresent()) { + @Inject(method = "handleAccumulatedMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;mouseDragged(DDIDD)Z", ordinal = 0), cancellable = true) + private void onGuiMouseDraggedPre(CallbackInfo ci, @Local(ordinal = 2) double mouseX, @Local(ordinal = 3) double mouseY, @Local(ordinal = 4) double deltaX, @Local(ordinal = 5) double deltaY) { + if (ClientScreenInputEvent.MOUSE_DRAGGED_PRE.invoker().mouseDragged(Minecraft.getInstance(), Minecraft.getInstance().screen, mouseX, mouseY, this.activeButton, deltaX, deltaY).isPresent()) { ci.cancel(); } } @SuppressWarnings({"UnresolvedMixinReference", "DefaultAnnotationParam"}) - @Redirect(method = {"method_55795", "lambda$handleAccumulatedMovement$11"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;mouseDragged(DDIDD)Z", remap = true), remap = false) - private boolean onGuiMouseDraggedPost(Screen screen, double mouseX, double mouseY, int button, double deltaX, double deltaY) { - if (screen.mouseDragged(mouseX, mouseY, button, deltaX, deltaY)) { + @WrapOperation(method = "handleAccumulatedMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;mouseDragged(DDIDD)Z")) + private boolean onGuiMouseDraggedPost(Screen screen, double mouseX, double mouseY, int button, double deltaX, double deltaY, Operation original) { + if (original.call(screen, mouseX, mouseY, button, deltaX, deltaY)) { return true; } + return ClientScreenInputEvent.MOUSE_DRAGGED_POST.invoker().mouseDragged(Minecraft.getInstance(), screen, mouseX, mouseY, button, deltaX, deltaY).isPresent(); } } diff --git a/gradle.properties b/gradle.properties index 63ed672a..3771bde4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,10 +3,10 @@ org.gradle.daemon=false platforms=fabric -minecraft_version=24w40a -supported_version=1.21.2 (24w40a) +minecraft_version=1.21.2 +supported_version=1.21.2 -artifact_type=beta +artifact_type=release archives_base_name=architectury archives_base_name_snapshot=architectury-snapshot @@ -14,8 +14,8 @@ base_version=14.0 maven_group=dev.architectury version_suffix= -fabric_loader_version=0.16.5 -fabric_api_version=0.105.2+1.21.2 +fabric_loader_version=0.16.7 +fabric_api_version=0.106.1+1.21.2 mod_menu_version=11.0.1 forge_version=51.0.0