Skip to content

Commit

Permalink
Revert changes to MixinMouseHelper
Browse files Browse the repository at this point in the history
Remove unneeded variable guiWasNotNull
  • Loading branch information
My-Name-Is-Jeff committed Oct 10, 2023
1 parent ea464e2 commit f4a139a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit f4a139a

Please sign in to comment.