Skip to content

Commit

Permalink
actually fix mouse locking
Browse files Browse the repository at this point in the history
  • Loading branch information
CalMWolfs committed Nov 2, 2023
1 parent ad12389 commit d7f8d87
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 40 deletions.
11 changes: 7 additions & 4 deletions src/main/java/at/hannibal2/skyhanni/config/Storage.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -31,6 +31,9 @@ public class Storage {
@Expose
public boolean hasPlayedBefore = false;

@Expose
public Float savedMouseSensitivity = .5f;

@Expose
public Map<String, List<String>> knownFeatureToggles = new HashMap<>();

Expand Down Expand Up @@ -457,4 +460,4 @@ public static class DungeonStorage {
public Map<DungeonAPI.DungeonFloor, Integer> bosses = new HashMap<>();
}
}
}
}
72 changes: 36 additions & 36 deletions src/main/java/at/hannibal2/skyhanni/features/misc/LockMouseLook.kt
Original file line number Diff line number Diff line change
@@ -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.")
}
}
}

0 comments on commit d7f8d87

Please sign in to comment.