Browse Source

Backport of #154 and #172 to 1.16

Contains the following changes:
- Explicitly add `remap=true` to fix mixin failing in prod (#172)
- @Redirect workaround for closing #152 (#154)

Co-authored-by: shedaniel <daniel@shedaniel.me>
Co-authored-by: Mitchell Skaggs <skaggsm333@gmail.com>

Signed-off-by: Max <maxh2709@gmail.com>
Max 3 năm trước cách đây
mục cha
commit
c68a637975

+ 0 - 9
fabric/src/main/java/me/shedaniel/architectury/impl/fabric/ScreenInputDelegate.java

@@ -37,15 +37,6 @@ public interface ScreenInputDelegate {
             this.parent = parent;
         }
         
-        @Override
-        public boolean mouseDragged(double d, double e, int i, double f, double g) {
-            if (ClientScreenInputEvent.MOUSE_DRAGGED_PRE.invoker().mouseDragged(Minecraft.getInstance(), parent, d, e, i, f, g) != InteractionResult.PASS)
-                return true;
-            if (parent.mouseDragged(d, e, i, f, g))
-                return true;
-            return ClientScreenInputEvent.MOUSE_DRAGGED_POST.invoker().mouseDragged(Minecraft.getInstance(), parent, d, e, i, f, g) != InteractionResult.PASS;
-        }
-        
         @Override
         public boolean charTyped(char c, int i) {
             if (ClientScreenInputEvent.CHAR_TYPED_PRE.invoker().charTyped(Minecraft.getInstance(), parent, c, i) != InteractionResult.PASS)

+ 15 - 7
fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/client/MixinMouseHandler.java

@@ -21,17 +21,17 @@ package me.shedaniel.architectury.mixin.fabric.client;
 
 import me.shedaniel.architectury.event.events.client.ClientRawInputEvent;
 import me.shedaniel.architectury.event.events.client.ClientScreenInputEvent;
-import me.shedaniel.architectury.impl.fabric.ScreenInputDelegate;
 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.ModifyVariable;
+import org.spongepowered.asm.mixin.injection.Redirect;
 import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
 import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
 
@@ -150,11 +150,19 @@ public class MixinMouseHandler {
     }
     
     @SuppressWarnings("UnresolvedMixinReference")
-    @ModifyVariable(method = {"method_1602", "lambda$onMove$11"}, at = @At("HEAD"), ordinal = 0, argsOnly = true)
-    private GuiEventListener wrapMouseDragged(GuiEventListener screen) {
-        if (screen instanceof ScreenInputDelegate) {
-            return ((ScreenInputDelegate) screen).architectury_delegateInputs();
+    @Inject(method = {"method_1602", "lambda$onMove$11"}, at = @At("HEAD"), cancellable = true, remap = false)
+    private void onGuiMouseDraggedPre(GuiEventListener screen, double mouseX, double mouseY, double deltaX, double deltaY, CallbackInfo ci) {
+        if (ClientScreenInputEvent.MOUSE_DRAGGED_PRE.invoker().mouseDragged(Minecraft.getInstance(), (Screen) screen, mouseX, mouseY, this.activeButton, deltaX, deltaY) != InteractionResult.PASS) {
+            ci.cancel();
         }
-        return screen;
+    }
+    
+    @SuppressWarnings({"UnresolvedMixinReference", "DefaultAnnotationParam"})
+    @Redirect(method = {"method_1602", "lambda$onMove$11"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/components/events/GuiEventListener;mouseDragged(DDIDD)Z", remap = true), remap = false)
+    private boolean onGuiMouseDraggedPost(GuiEventListener screen, double mouseX, double mouseY, int button, double deltaX, double deltaY) {
+        if (screen.mouseDragged(mouseX, mouseY, button, deltaX, deltaY)) {
+            return true;
+        }
+        return ClientScreenInputEvent.MOUSE_DRAGGED_POST.invoker().mouseDragged(Minecraft.getInstance(), (Screen) screen, mouseX, mouseY, button, deltaX, deltaY) != InteractionResult.PASS;
     }
 }