From 2ce84766100584a5aaf516a2cbf0907585aaa07e Mon Sep 17 00:00:00 2001 From: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Date: Fri, 3 Nov 2023 06:48:51 +1100 Subject: actually fix mouse locking (#662) Fixed mouse sensitivity stuck after restarting by storing old sensitivity. #662 --- .../java/at/hannibal2/skyhanni/config/Storage.java | 11 ++-- .../skyhanni/features/misc/LockMouseLook.kt | 72 +++++++++++----------- 2 files changed, 43 insertions(+), 40 deletions(-) (limited to 'src/main/java/at') diff --git a/src/main/java/at/hannibal2/skyhanni/config/Storage.java b/src/main/java/at/hannibal2/skyhanni/config/Storage.java index 21ed83b00..a63477a07 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/Storage.java +++ b/src/main/java/at/hannibal2/skyhanni/config/Storage.java @@ -1,16 +1,16 @@ package at.hannibal2.skyhanni.config; import at.hannibal2.skyhanni.data.model.ComposterUpgrade; +import at.hannibal2.skyhanni.features.combat.endernodetracker.EnderNode; +import at.hannibal2.skyhanni.features.combat.ghostcounter.GhostData; import at.hannibal2.skyhanni.features.dungeon.DungeonAPI; +import at.hannibal2.skyhanni.features.event.jerry.frozentreasure.FrozenTreasure; import at.hannibal2.skyhanni.features.fishing.trophy.TrophyRarity; import at.hannibal2.skyhanni.features.garden.CropAccessory; import at.hannibal2.skyhanni.features.garden.CropType; import at.hannibal2.skyhanni.features.garden.farming.FarmingArmorDrops; import at.hannibal2.skyhanni.features.garden.fortuneguide.FarmingItems; import at.hannibal2.skyhanni.features.garden.visitor.VisitorReward; -import at.hannibal2.skyhanni.features.combat.endernodetracker.EnderNode; -import at.hannibal2.skyhanni.features.event.jerry.frozentreasure.FrozenTreasure; -import at.hannibal2.skyhanni.features.combat.ghostcounter.GhostData; import at.hannibal2.skyhanni.features.mining.powdertracker.PowderChestReward; import at.hannibal2.skyhanni.features.misc.trevor.TrevorTracker; import at.hannibal2.skyhanni.features.misc.visualwords.VisualWord; @@ -31,6 +31,9 @@ public class Storage { @Expose public boolean hasPlayedBefore = false; + @Expose + public Float savedMouseSensitivity = .5f; + @Expose public Map> knownFeatureToggles = new HashMap<>(); @@ -457,4 +460,4 @@ public class Storage { public Map bosses = new HashMap<>(); } } -} \ No newline at end of file +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/LockMouseLook.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/LockMouseLook.kt index 8873c7402..b4ab08459 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/LockMouseLook.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/LockMouseLook.kt @@ -1,36 +1,36 @@ -package at.hannibal2.skyhanni.features.misc - -import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent -import at.hannibal2.skyhanni.utils.LorenzUtils -import net.minecraft.client.Minecraft -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -object LockMouseLook { - private var lockedMouse = false - private var oldSensitivity = 0F - private val lockedPosition = -1F / 3F - - @SubscribeEvent - fun onWorldChange(event: LorenzWorldChangeEvent) { - if (lockedMouse) toggleLock() - val gameSettings = Minecraft.getMinecraft().gameSettings - if (gameSettings.mouseSensitivity == lockedPosition) { - gameSettings.mouseSensitivity = 0.5f - LorenzUtils.chat("§e[SkyHanni] §bReset your mouse sensitivity to 100%.") - } - } - - fun toggleLock() { - lockedMouse = !lockedMouse - - val gameSettings = Minecraft.getMinecraft().gameSettings - if (lockedMouse) { - oldSensitivity = gameSettings.mouseSensitivity - gameSettings.mouseSensitivity = lockedPosition - LorenzUtils.chat("§e[SkyHanni] §bMouse rotation is now locked. Type /shmouselock to unlock your rotation") - } else { - gameSettings.mouseSensitivity = oldSensitivity - LorenzUtils.chat("§e[SkyHanni] §bMouse rotation is now unlocked.") - } - } -} +package at.hannibal2.skyhanni.features.misc + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent +import at.hannibal2.skyhanni.utils.LorenzUtils +import net.minecraft.client.Minecraft +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +object LockMouseLook { + private var lockedMouse = false + private const val lockedPosition = -1F / 3F + + @SubscribeEvent + fun onWorldChange(event: LorenzWorldChangeEvent) { + if (lockedMouse) toggleLock() + val gameSettings = Minecraft.getMinecraft().gameSettings + if (gameSettings.mouseSensitivity == lockedPosition) { + gameSettings.mouseSensitivity = SkyHanniMod.feature.storage.savedMouseSensitivity + LorenzUtils.chat("§e[SkyHanni] §bMouse rotation is now unlocked because you left it locked.") + } + } + + fun toggleLock() { + val gameSettings = Minecraft.getMinecraft().gameSettings ?: return + lockedMouse = !lockedMouse + + if (lockedMouse) { + SkyHanniMod.feature.storage.savedMouseSensitivity = gameSettings.mouseSensitivity + gameSettings.mouseSensitivity = lockedPosition + LorenzUtils.chat("§e[SkyHanni] §bMouse rotation is now locked. Type /shmouselock to unlock your rotation") + } else { + gameSettings.mouseSensitivity = SkyHanniMod.feature.storage.savedMouseSensitivity + LorenzUtils.chat("§e[SkyHanni] §bMouse rotation is now unlocked.") + } + } +} -- cgit