diff options
author | martimavocado <39881008+martimavocado@users.noreply.github.com> | 2024-02-09 21:57:05 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-09 22:57:05 +0100 |
commit | d134fece41b7cfe4d8ff1c9176ff0e7f8a05420f (patch) | |
tree | ab91741347a4082f2942aaae80ae6641475d39c0 /src/main/java/at | |
parent | fc7a9d08b4d4e6fd1a089a58d789efc818a22430 (diff) | |
download | skyhanni-d134fece41b7cfe4d8ff1c9176ff0e7f8a05420f.tar.gz skyhanni-d134fece41b7cfe4d8ff1c9176ff0e7f8a05420f.tar.bz2 skyhanni-d134fece41b7cfe4d8ff1c9176ff0e7f8a05420f.zip |
Added Sensitivity Reducer. #716
Diffstat (limited to 'src/main/java/at')
7 files changed, 264 insertions, 4 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index f88b169e0..ad50e01a0 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -160,6 +160,7 @@ import at.hannibal2.skyhanni.features.garden.GardenPlotAPI import at.hannibal2.skyhanni.features.garden.GardenPlotBorders import at.hannibal2.skyhanni.features.garden.GardenWarpCommands import at.hannibal2.skyhanni.features.garden.GardenYawAndPitch +import at.hannibal2.skyhanni.features.garden.SensitivityReducer import at.hannibal2.skyhanni.features.garden.ToolTooltipTweaks import at.hannibal2.skyhanni.features.garden.composter.ComposterDisplay import at.hannibal2.skyhanni.features.garden.composter.ComposterInventoryNumbers @@ -716,6 +717,7 @@ class SkyHanniMod { loadModule(ArrowTrail()) loadModule(ShiftClickEquipment()) loadModule(LockMouseLook) + loadModule(SensitivityReducer) loadModule(DungeonFinderFeatures()) loadModule(PabloHelper()) loadModule(FishingBaitWarnings()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/Storage.java b/src/main/java/at/hannibal2/skyhanni/config/Storage.java index 486ec5369..a9364d695 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/Storage.java +++ b/src/main/java/at/hannibal2/skyhanni/config/Storage.java @@ -44,7 +44,10 @@ public class Storage { public boolean hasPlayedBefore = false; @Expose - public Float savedMouseSensitivity = .5f; + public Float savedMouselockedSensitivity = .5f; + + @Expose + public Float savedMouseloweredSensitivity = .5f; @Deprecated @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt index 69b096b31..771bf7055 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -29,6 +29,7 @@ import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.features.garden.GardenCropTimeCommand import at.hannibal2.skyhanni.features.garden.GardenCropsInCommand import at.hannibal2.skyhanni.features.garden.GardenNextJacobContest +import at.hannibal2.skyhanni.features.garden.SensitivityReducer import at.hannibal2.skyhanni.features.garden.composter.ComposterOverlay import at.hannibal2.skyhanni.features.garden.farming.ArmorDropTracker import at.hannibal2.skyhanni.features.garden.farming.CropMoneyDisplay @@ -217,6 +218,10 @@ object Commands { "Lock/Unlock the mouse so it will no longer rotate the player (for farming)" ) { LockMouseLook.toggleLock() } registerCommand( + "shsensreduce", + "Lowers the mouse sensitivity for easier small adjustments (for farming)" + ) { SensitivityReducer.manualToggle() } + registerCommand( "shresetvermintracker", "Resets the Vermin Tracker" ) { VerminTracker.resetCommand(it) } diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java index cdea4e3ee..9ef1fd31b 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java @@ -105,6 +105,11 @@ public class GardenConfig { public YawPitchDisplayConfig yawPitchDisplay = new YawPitchDisplayConfig(); @Expose + @ConfigOption(name = "Sensitivity Reducer", desc = "") + @Accordion + public SensitivityReducerConfig sensitivityReducerConfig = new SensitivityReducerConfig(); + + @Expose @ConfigOption(name = "Crop Start Location", desc = "") @Accordion public CropStartLocationConfig cropStartLocation = new CropStartLocationConfig(); diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/SensitivityReducerConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/SensitivityReducerConfig.java new file mode 100644 index 000000000..1904dbdc1 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/SensitivityReducerConfig.java @@ -0,0 +1,69 @@ +package at.hannibal2.skyhanni.config.features.garden; + +import at.hannibal2.skyhanni.config.core.config.Position; +import com.google.gson.annotations.Expose; +import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean; +import io.github.moulberry.moulconfig.annotations.ConfigEditorDropdown; +import io.github.moulberry.moulconfig.annotations.ConfigEditorKeybind; +import io.github.moulberry.moulconfig.annotations.ConfigEditorSlider; +import io.github.moulberry.moulconfig.annotations.ConfigOption; +import io.github.moulberry.moulconfig.observer.Property; +import org.lwjgl.input.Keyboard; + +public class SensitivityReducerConfig { + @Expose + @ConfigOption( + name = "Mode", + desc = "Lowers mouse sensitivity while in the garden.") + @ConfigEditorDropdown() + public Mode mode = Mode.OFF; + + public enum Mode { + OFF("Disabled"), + TOOL("Holding farming tool"), + KEYBIND("Holding Keybind"); + private final String str; + + Mode(String str) { + this.str = str; + } + @Override + public String toString() { + return str; + } + } + + @Expose + @ConfigOption(name = "Keybind", desc = "When selected above, press this key to reduce the mouse sensitivity.") + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_N) + public int keybind = Keyboard.KEY_N; + + @Expose + @ConfigOption(name = "Reducing factor", desc = "Changes by how much the sensitivity is lowered by.") + @ConfigEditorSlider(minValue = 1, maxValue = 50, minStep = 1) + public Property<Float> reducingFactor = Property.of(15.0F); + + @Expose + @ConfigOption( + name = "Show GUI", + desc = "Shows the GUI element while the feature is enabled.") + @ConfigEditorBoolean + public boolean showGUI = true; + + @Expose + @ConfigOption( + name = "Only in Ground", + desc = "Lower sensitivity when standing on the ground.") + @ConfigEditorBoolean + public Property<Boolean> onGround = Property.of(false); + + @Expose + @ConfigOption( + name = "Disable in Barn", + desc = "Disable reduced sensitivity in barn plot.") + @ConfigEditorBoolean + public Property<Boolean> onlyPlot = Property.of(true); + + @Expose + public Position position = new Position(400, 400, 0.8f); +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/SensitivityReducer.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/SensitivityReducer.kt new file mode 100644 index 000000000..e43563b14 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/SensitivityReducer.kt @@ -0,0 +1,176 @@ +package at.hannibal2.skyhanni.features.garden + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.features.garden.SensitivityReducerConfig +import at.hannibal2.skyhanni.events.ConfigLoadEvent +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.utils.KeyboardManager.isKeyHeld +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.afterChange +import at.hannibal2.skyhanni.utils.RenderUtils.renderString +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import net.minecraft.client.Minecraft +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.math.abs +import kotlin.time.Duration.Companion.seconds + +object SensitivityReducer { + private val config get() = SkyHanniMod.feature.garden.sensitivityReducerConfig + private val storage get() = SkyHanniMod.feature.storage + private var isToggled = false + private var isManualToggle = false + private var lastCheckCooldown = SimpleTimeMark.farPast() + + private val mc get() = Minecraft.getMinecraft() + private val gameSettings = mc.gameSettings + + @SubscribeEvent + fun onTick(event: LorenzTickEvent) { + if (!GardenAPI.inGarden()) { + if (isToggled && lastCheckCooldown.passedSince() > 1.seconds) { + lastCheckCooldown = SimpleTimeMark.now() + isToggled = false + restoreSensitivity() + } + return + } + if (isManualToggle) return + if (isToggled && config.onGround.get() && !mc.thePlayer.onGround) { + restoreSensitivity() + isToggled = false + return + } + when (config.mode) { + SensitivityReducerConfig.Mode.OFF -> { + if (isToggled) toggle(false) + return + } + SensitivityReducerConfig.Mode.TOOL -> { + if (isHoldingTool() && !isToggled) toggle(true) + else if (isToggled && !isHoldingTool()) toggle(false) + } + SensitivityReducerConfig.Mode.KEYBIND -> { + if (config.keybind.isKeyHeld() && !isToggled) toggle(true) + else if (isToggled && !config.keybind.isKeyHeld()) toggle(false) + } + else -> return + } + } + + @SubscribeEvent + fun onConfigInit(event: ConfigLoadEvent) { + config.reducingFactor.afterChange { + reloadSensitivity() + } + config.onlyPlot.afterChange { + if (isToggled && config.onlyPlot.get() && GardenAPI.onBarnPlot) { + restoreSensitivity() + isToggled = false + } + } + config.onGround.afterChange { + if (isToggled && config.onGround.get() && mc.thePlayer.onGround) { + restoreSensitivity() + isToggled = false + } + } + } + + private fun reloadSensitivity() { + if (isToggled || isManualToggle) { + restoreSensitivity() + lowerSensitivity() + } + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { + if (!(isToggled || isManualToggle)) return + if (!config.showGUI) return + config.position.renderString("§eSensitivity Lowered", posLabel = "Sensitivity Lowered") + } + + private fun isHoldingTool(): Boolean { + return GardenAPI.toolInHand != null + } + + fun manualToggle() { + if (isToggled) { + LorenzUtils.chat("This command is disabled while holding a farming tool.") + return + } + isManualToggle = !isManualToggle + if (isManualToggle) { + lowerSensitivity(true) + } else restoreSensitivity(true) + } + + private fun lowerSensitivity(showMessage: Boolean = false) { + storage.savedMouseloweredSensitivity = gameSettings.mouseSensitivity + val divisor = config.reducingFactor.get() + LorenzUtils.debug("dividing by $divisor") + storage.savedMouseloweredSensitivity = gameSettings.mouseSensitivity + val newSens = + ((storage.savedMouseloweredSensitivity + (1F / 3F)) / divisor) - (1F / 3F) + gameSettings?.mouseSensitivity = newSens + if (showMessage) LorenzUtils.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 (showMessage) LorenzUtils.chat("§bMouse sensitivity is now restored.") + } + + private fun toggle(state: Boolean) { + if (config.onlyPlot.get() && GardenAPI.onBarnPlot) return + if (config.onGround.get() && !mc.thePlayer.onGround) return + if (!isToggled) { + lowerSensitivity() + } else restoreSensitivity() + isToggled = state + } + + @SubscribeEvent + fun onLogin(event: HypixelJoinEvent) { + val divisor = config.reducingFactor.get() + val expectedLoweredSensitivity = ((divisor * (gameSettings.mouseSensitivity + 1F / 3F)) - 1F / 3F) + if (abs(storage.savedMouseloweredSensitivity - expectedLoweredSensitivity) <= 0.0001) { + LorenzUtils.debug("Fixing incorrectly lowered sensitivity") + isToggled = false + isManualToggle = false + restoreSensitivity() + } + } + + @SubscribeEvent + fun onDebugDataCollect(event: DebugDataCollectEvent) { + event.title("Garden Sensitivity Reducer") + + if (!GardenAPI.inGarden()) { + event.addIrrelevant("not in garden") + return + } + + if (config.mode == SensitivityReducerConfig.Mode.OFF) { + event.addIrrelevant("disabled in config") + return + } + + event.addData { + add("Current Sensitivity: ${gameSettings.mouseSensitivity}") + add("Stored Sensitivity: ${storage.savedMouseloweredSensitivity}") + add("onGround: ${mc.thePlayer.onGround}") + add("onBarn: ${GardenAPI.onBarnPlot}") + add("enabled: ${isToggled || isManualToggle}") + add("--- config ---") + add("mode: ${config.mode.name}") + add("Current Divisor: ${config.reducingFactor.get()}") + add("Keybind: ${config.keybind}") + add("onlyGround: ${config.onGround}") + add("onlyPlot: ${config.onlyPlot}") + } + } +} 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 4025c32e2..be4bb05f3 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/LockMouseLook.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/LockMouseLook.kt @@ -18,7 +18,7 @@ object LockMouseLook { if (lockedMouse) toggleLock() val gameSettings = Minecraft.getMinecraft().gameSettings if (gameSettings.mouseSensitivity == lockedPosition) { - gameSettings.mouseSensitivity = SkyHanniMod.feature.storage.savedMouseSensitivity + gameSettings.mouseSensitivity = SkyHanniMod.feature.storage.savedMouselockedSensitivity LorenzUtils.chat("§bMouse rotation is now unlocked because you left it locked.") } } @@ -28,13 +28,13 @@ object LockMouseLook { lockedMouse = !lockedMouse if (lockedMouse) { - SkyHanniMod.feature.storage.savedMouseSensitivity = gameSettings.mouseSensitivity + SkyHanniMod.feature.storage.savedMouselockedSensitivity = gameSettings.mouseSensitivity gameSettings.mouseSensitivity = lockedPosition if (config.lockMouseLookChatMessage) { LorenzUtils.chat("§bMouse rotation is now locked. Type /shmouselock to unlock your rotation") } } else { - gameSettings.mouseSensitivity = SkyHanniMod.feature.storage.savedMouseSensitivity + gameSettings.mouseSensitivity = SkyHanniMod.feature.storage.savedMouselockedSensitivity if (config.lockMouseLookChatMessage) { LorenzUtils.chat("§bMouse rotation is now unlocked.") } |