From f4a139a35f4917e947e934db0c7e84178ad2a9b7 Mon Sep 17 00:00:00 2001 From: My-Name-Is-Jeff <37018278+My-Name-Is-Jeff@users.noreply.github.com> Date: Mon, 9 Oct 2023 22:18:31 -0400 Subject: [PATCH] Revert changes to MixinMouseHelper Remove unneeded variable guiWasNotNull --- .../transformers/util/MixinMouseHelper.java | 13 ++++-------- .../mixins/hooks/util/MouseHelperHook.kt | 20 ++++++++----------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/main/java/gg/skytils/skytilsmod/mixins/transformers/util/MixinMouseHelper.java b/src/main/java/gg/skytils/skytilsmod/mixins/transformers/util/MixinMouseHelper.java index 64159c5d1..4c091cdab 100644 --- a/src/main/java/gg/skytils/skytilsmod/mixins/transformers/util/MixinMouseHelper.java +++ b/src/main/java/gg/skytils/skytilsmod/mixins/transformers/util/MixinMouseHelper.java @@ -18,21 +18,16 @@ package gg.skytils.skytilsmod.mixins.transformers.util; +import com.llamalad7.mixinextras.injector.WrapWithCondition; import gg.skytils.skytilsmod.mixins.hooks.util.MouseHelperHook; import net.minecraft.util.MouseHelper; -import org.lwjgl.input.Mouse; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(MouseHelper.class) public class MixinMouseHelper { - @Inject(method = "ungrabMouseCursor", at = @At("HEAD"), cancellable = true) - private void ungrabMouseCursor(CallbackInfo ci) { - if (MouseHelperHook.INSTANCE.shouldResetMouseToCenter()) { - ci.cancel(); - Mouse.setGrabbed(false); - } + @WrapWithCondition(method = "ungrabMouseCursor", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Mouse;setCursorPosition(II)V", remap = false)) + private boolean shouldSetCursorPos(int newX, int newY) { + return MouseHelperHook.INSTANCE.shouldResetMouseToCenter(); } } diff --git a/src/main/kotlin/gg/skytils/skytilsmod/mixins/hooks/util/MouseHelperHook.kt b/src/main/kotlin/gg/skytils/skytilsmod/mixins/hooks/util/MouseHelperHook.kt index ff31def3c..d0fa95799 100644 --- a/src/main/kotlin/gg/skytils/skytilsmod/mixins/hooks/util/MouseHelperHook.kt +++ b/src/main/kotlin/gg/skytils/skytilsmod/mixins/hooks/util/MouseHelperHook.kt @@ -19,30 +19,26 @@ package gg.skytils.skytilsmod.mixins.hooks.util import gg.skytils.skytilsmod.Skytils -import net.minecraft.client.Minecraft -import net.minecraftforge.client.event.GuiOpenEvent +import gg.skytils.skytilsmod.Skytils.Companion.mc import net.minecraft.client.gui.inventory.GuiChest import net.minecraft.client.gui.inventory.GuiContainer +import net.minecraftforge.client.event.GuiOpenEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.common.gameevent.TickEvent object MouseHelperHook { private var lastOpen = -1L - private var guiWasNotNull = false + @SubscribeEvent fun onGuiOpen(e: GuiOpenEvent) { - val oldGui = Minecraft.getMinecraft().currentScreen - if (e.gui is GuiChest && (oldGui is GuiContainer || oldGui == null)) { + val oldGui = mc.currentScreen + if (e.gui == null) { + lastOpen = -1L + } else if (e.gui is GuiChest && (oldGui is GuiContainer || oldGui == null)) { lastOpen = System.currentTimeMillis() } } - @SubscribeEvent - fun onTick(event: TickEvent.ClientTickEvent) { - guiWasNotNull = Minecraft.getMinecraft().currentScreen != null - } - fun shouldResetMouseToCenter(): Boolean { - return Skytils.config.preventCursorReset && System.currentTimeMillis() - lastOpen <= 150 && guiWasNotNull + return Skytils.config.preventCursorReset && System.currentTimeMillis() - lastOpen <= 150 } } \ No newline at end of file