Skip to content

Commit

Permalink
Backport of #154 and #172 to 1.16
Browse files Browse the repository at this point in the history
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 <[email protected]>
Co-authored-by: Mitchell Skaggs <[email protected]>

Signed-off-by: Max <[email protected]>
  • Loading branch information
MaxNeedsSnacks committed Dec 31, 2021
1 parent 71041f6 commit c68a637
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@ public DelegateScreen(Screen parent) {
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@

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;

Expand Down Expand Up @@ -150,11 +150,19 @@ public void onGuiMouseReleasedPost(boolean[] bls, double d, double e, int button
}

@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;
}
}

0 comments on commit c68a637

Please sign in to comment.