aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormartimavocado <39881008+martimavocado@users.noreply.github.com>2024-02-16 07:23:48 +0000
committerGitHub <noreply@github.com>2024-02-16 08:23:48 +0100
commit20f087a2597ee46260c949414bed3ce16df8a8bb (patch)
tree44e71ba3a91499df270931c9ce867fddab569182 /src
parente8212f12c77e4d77002cd4ccadb8056c25ae6cb6 (diff)
downloadskyhanni-20f087a2597ee46260c949414bed3ce16df8a8bb.tar.gz
skyhanni-20f087a2597ee46260c949414bed3ce16df8a8bb.tar.bz2
skyhanni-20f087a2597ee46260c949414bed3ce16df8a8bb.zip
Fixed mouse rotation unlocks after doing /warp garden (with Sensitivity Reducer on). #1007
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/SensitivityReducer.kt30
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/LockMouseLook.kt33
2 files changed, 50 insertions, 13 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/SensitivityReducer.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/SensitivityReducer.kt
index 8755860fd..a613a65f1 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/SensitivityReducer.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/SensitivityReducer.kt
@@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.events.DebugDataCollectEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.HypixelJoinEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
+import at.hannibal2.skyhanni.features.misc.LockMouseLook
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.ConditionalUtils.afterChange
import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld
@@ -23,6 +24,7 @@ object SensitivityReducer {
private var isToggled = false
private var isManualToggle = false
private var lastCheckCooldown = SimpleTimeMark.farPast()
+ private const val LOCKED = -1F / 3F
private val mc get() = Minecraft.getMinecraft()
private val gameSettings = mc.gameSettings
@@ -55,8 +57,8 @@ object SensitivityReducer {
}
SensitivityReducerConfig.Mode.KEYBIND -> {
- if (config.keybind.isKeyHeld() && !isToggled) toggle(true)
- else if (isToggled && !config.keybind.isKeyHeld()) toggle(false)
+ if (isHoldingKey() && !isToggled) toggle(true)
+ else if (isToggled && !isHoldingKey()) toggle(false)
}
else -> return
@@ -111,6 +113,14 @@ object SensitivityReducer {
return GardenAPI.toolInHand != null
}
+ private fun isHoldingKey(): Boolean {
+ return config.keybind.isKeyHeld() && mc.currentScreen == null
+ }
+
+ fun isEnabled(): Boolean {
+ return isToggled || isManualToggle
+ }
+
fun manualToggle() {
if (isToggled) {
ChatUtils.chat("This command is disabled while the Sensitivity is lowered.")
@@ -123,18 +133,17 @@ object SensitivityReducer {
}
private fun lowerSensitivity(showMessage: Boolean = false) {
- storage.savedMouseloweredSensitivity = gameSettings.mouseSensitivity
val divisor = config.reducingFactor.get()
ChatUtils.debug("dividing by $divisor")
+
storage.savedMouseloweredSensitivity = gameSettings.mouseSensitivity
- val newSens =
- ((storage.savedMouseloweredSensitivity + (1F / 3F)) / divisor) - (1F / 3F)
+ val newSens = doTheMath(storage.savedMouseloweredSensitivity)
gameSettings?.mouseSensitivity = newSens
if (showMessage) ChatUtils.chat("§bMouse sensitivity is now lowered. Type /shsensreduce to restore your sensitivity.")
}
private fun restoreSensitivity(showMessage: Boolean = false) {
- gameSettings?.mouseSensitivity = SkyHanniMod.feature.storage.savedMouseloweredSensitivity
+ if (!LockMouseLook.lockedMouse) gameSettings?.mouseSensitivity = storage.savedMouseloweredSensitivity
if (showMessage) ChatUtils.chat("§bMouse sensitivity is now restored.")
}
@@ -147,10 +156,17 @@ object SensitivityReducer {
isToggled = state
}
+
+ fun doTheMath(input: Float, reverse: Boolean = false): Float {
+ val divisor = config.reducingFactor.get()
+ return if (!reverse) ((input - LOCKED) / divisor) + LOCKED
+ else (divisor * (input - LOCKED)) + LOCKED
+ }
+
@SubscribeEvent
fun onLogin(event: HypixelJoinEvent) {
val divisor = config.reducingFactor.get()
- val expectedLoweredSensitivity = ((divisor * (gameSettings.mouseSensitivity + 1F / 3F)) - 1F / 3F)
+ val expectedLoweredSensitivity = doTheMath(gameSettings.mouseSensitivity, true)
if (abs(storage.savedMouseloweredSensitivity - expectedLoweredSensitivity) <= 0.0001) {
ChatUtils.debug("Fixing incorrectly lowered sensitivity")
isToggled = false
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 b7dd83d5f..194b2e310 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/LockMouseLook.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/LockMouseLook.kt
@@ -1,9 +1,11 @@
package at.hannibal2.skyhanni.features.misc
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.events.DebugDataCollectEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
+import at.hannibal2.skyhanni.features.garden.SensitivityReducer
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
import net.minecraft.client.Minecraft
@@ -12,7 +14,8 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
object LockMouseLook {
private val config get() = SkyHanniMod.feature.misc
- private var lockedMouse = false
+ private val storage get() = SkyHanniMod.feature.storage
+ var lockedMouse = false
private const val lockedPosition = -1F / 3F
@SubscribeEvent
@@ -20,29 +23,33 @@ object LockMouseLook {
if (lockedMouse) toggleLock()
val gameSettings = Minecraft.getMinecraft().gameSettings
if (gameSettings.mouseSensitivity == lockedPosition) {
- gameSettings.mouseSensitivity = SkyHanniMod.feature.storage.savedMouselockedSensitivity
+ gameSettings.mouseSensitivity = storage.savedMouselockedSensitivity
ChatUtils.chat("§bMouse rotation is now unlocked because you left it locked.")
}
}
@SubscribeEvent
- fun onChat (event: LorenzChatEvent) {
+ fun onChat(event: LorenzChatEvent) {
if (!event.message.startsWith("§aTeleported you to §r§aPlot")) return
if (lockedMouse) toggleLock()
}
fun toggleLock() {
- val gameSettings = Minecraft.getMinecraft().gameSettings ?: return
lockedMouse = !lockedMouse
+ val gameSettings = Minecraft.getMinecraft().gameSettings ?: return
+ var mouseSensitivity = gameSettings.mouseSensitivity
+ if (SensitivityReducer.isEnabled()) mouseSensitivity = SensitivityReducer.doTheMath(mouseSensitivity, true)
+
if (lockedMouse) {
- SkyHanniMod.feature.storage.savedMouselockedSensitivity = gameSettings.mouseSensitivity
+ storage.savedMouselockedSensitivity = mouseSensitivity
gameSettings.mouseSensitivity = lockedPosition
if (config.lockMouseLookChatMessage) {
ChatUtils.chat("§bMouse rotation is now locked. Type /shmouselock to unlock your rotation")
}
} else {
- gameSettings.mouseSensitivity = SkyHanniMod.feature.storage.savedMouselockedSensitivity
+ if (!SensitivityReducer.isEnabled()) gameSettings.mouseSensitivity = storage.savedMouselockedSensitivity
+ else gameSettings.mouseSensitivity = SensitivityReducer.doTheMath(storage.savedMouselockedSensitivity)
if (config.lockMouseLookChatMessage) {
ChatUtils.chat("§bMouse rotation is now unlocked.")
}
@@ -60,4 +67,18 @@ object LockMouseLook {
toggleLock()
}
}
+
+ @SubscribeEvent
+ fun onDebugDataCollect(event: DebugDataCollectEvent) {
+ event.title("Mouse Lock")
+
+ if (!lockedMouse) {
+ event.addIrrelevant("not enabled")
+ return
+ }
+
+ event.addData {
+ add("Stored Sensitivity: ${storage.savedMouselockedSensitivity}")
+ }
+ }
}