diff --git a/build.gradle.kts b/build.gradle.kts index 7975c8a..7024072 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,7 +17,7 @@ plugins { } group = "dev.isxander" -version = "2.6.0" +version = "2.7.0" repositories { mavenCentral() diff --git a/changelogs/2.7.0.md b/changelogs/2.7.0.md new file mode 100644 index 0000000..40c7ebb --- /dev/null +++ b/changelogs/2.7.0.md @@ -0,0 +1,2 @@ +- Keybind Scrolling: Instead of using scroll wheel, use keybinds! (Configurable) +- Fix funky behaviour with Spyglass integration diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e7d9eca..3a8ef96 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -10,7 +10,7 @@ yet_another_config_lib = "1.2.0" mod_menu = "4.0.6" mixin_extras = "0.0.12" -settxi = "2.10.2" +settxi = "2.10.3" [libraries] minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" } diff --git a/src/main/java/dev/isxander/zoomify/mixins/zoom/MouseMixin.java b/src/main/java/dev/isxander/zoomify/mixins/zoom/MouseMixin.java index 3c88941..33564b5 100644 --- a/src/main/java/dev/isxander/zoomify/mixins/zoom/MouseMixin.java +++ b/src/main/java/dev/isxander/zoomify/mixins/zoom/MouseMixin.java @@ -23,7 +23,7 @@ public class MouseMixin { cancellable = true ) private void scrollStepCounter(CallbackInfo ci) { - if (ZoomifySettings.INSTANCE.getScrollZoom() && Zoomify.INSTANCE.getZooming() && eventDeltaWheel != 0) { + if (ZoomifySettings.INSTANCE.getScrollZoom() && Zoomify.INSTANCE.getZooming() && eventDeltaWheel != 0 && !ZoomifySettings.INSTANCE.getKeybindScrolling()) { Zoomify.mouseZoom(eventDeltaWheel); ci.cancel(); } diff --git a/src/main/kotlin/dev/isxander/zoomify/Zoomify.kt b/src/main/kotlin/dev/isxander/zoomify/Zoomify.kt index af454b2..f7f1946 100644 --- a/src/main/kotlin/dev/isxander/zoomify/Zoomify.kt +++ b/src/main/kotlin/dev/isxander/zoomify/Zoomify.kt @@ -20,7 +20,9 @@ import org.slf4j.LoggerFactory object Zoomify : ClientModInitializer { val LOGGER = LoggerFactory.getLogger("Zoomify")!! - val zoomKey = KeyBinding("zoomify.key.zoom", InputUtil.Type.KEYSYM, InputUtil.GLFW_KEY_C, "zoomify.key.category") + private val zoomKey = KeyBinding("zoomify.key.zoom", InputUtil.Type.KEYSYM, InputUtil.GLFW_KEY_C, "zoomify.key.category") + private val scrollZoomIn = KeyBinding("zoomify.key.zoom.in", -1, "zoomify.key.category") + private val scrollZoomOut = KeyBinding("zoomify.key.zoom.out", -1, "zoomify.key.category") var zooming = false private val zoomHelper = ZoomHelper() @@ -40,6 +42,10 @@ object Zoomify : ClientModInitializer { ZoomifySettings KeyBindingHelper.registerKeyBinding(zoomKey) + if (ZoomifySettings.keybindScrolling) { + KeyBindingHelper.registerKeyBinding(scrollZoomIn) + KeyBindingHelper.registerKeyBinding(scrollZoomOut) + } ClientCommandRegistrationCallback.EVENT.register { dispatcher, _ -> dispatcher.register( @@ -54,7 +60,6 @@ object Zoomify : ClientModInitializer { } private fun tick(client: MinecraftClient) { - val cameraEntity = client.cameraEntity val prevZooming = zooming when (ZoomifySettings.zoomKeyBehaviour) { @@ -66,6 +71,52 @@ object Zoomify : ClientModInitializer { } } + if (ZoomifySettings.keybindScrolling) { + while (scrollZoomIn.wasPressed()) { + scrollSteps++ + } + while (scrollZoomOut.wasPressed()) { + scrollSteps-- + } + + scrollSteps = scrollSteps.coerceIn(0..maxScrollTiers) + } + + handleSpyglass(client, prevZooming) + + zoomHelper.tick(zooming, scrollSteps) + + if (displayGui) { + displayGui = false + client.setScreen(ZoomifySettings.gui(client.currentScreen)) + } + } + + @JvmStatic + fun getZoomDivisor(tickDelta: Float): Double { + if (!zooming) { + if (!ZoomifySettings.retainZoomSteps) + scrollSteps = 0 + + zoomHelper.reset() + } + + return zoomHelper.getZoomDivisor(tickDelta).also { previousZoomDivisor = it } + } + + @JvmStatic + fun mouseZoom(mouseDelta: Double) { + if (mouseDelta > 0) { + scrollSteps++ + } else if (mouseDelta < 0) { + scrollSteps-- + } + scrollSteps = scrollSteps.coerceIn(0..maxScrollTiers) + } + + private fun handleSpyglass(client: MinecraftClient, prevZooming: Boolean) { + val cameraEntity = client.cameraEntity + if (cameraEntity is AbstractClientPlayerEntity) { when (ZoomifySettings.spyglassBehaviour) { SpyglassBehaviour.ONLY_ZOOM_WHILE_HOLDING -> { @@ -108,35 +159,6 @@ object Zoomify : ClientModInitializer { } } } - - zoomHelper.tick(zooming, scrollSteps) - - if (displayGui) { - displayGui = false - client.setScreen(ZoomifySettings.gui(client.currentScreen)) - } - } - - @JvmStatic - fun getZoomDivisor(tickDelta: Float): Double { - if (!zooming) { - if (!ZoomifySettings.retainZoomSteps) - scrollSteps = 0 - - zoomHelper.reset() - } - - return zoomHelper.getZoomDivisor(tickDelta).also { previousZoomDivisor = it } - } - - @JvmStatic - fun mouseZoom(mouseDelta: Double) { - if (mouseDelta > 0) { - scrollSteps++ - } else if (mouseDelta < 0) { - scrollSteps-- - } - scrollSteps = scrollSteps.coerceIn(0..maxScrollTiers) } @JvmStatic diff --git a/src/main/kotlin/dev/isxander/zoomify/config/ZoomifySettings.kt b/src/main/kotlin/dev/isxander/zoomify/config/ZoomifySettings.kt index 031ab21..c60e65c 100644 --- a/src/main/kotlin/dev/isxander/zoomify/config/ZoomifySettings.kt +++ b/src/main/kotlin/dev/isxander/zoomify/config/ZoomifySettings.kt @@ -6,6 +6,7 @@ import dev.isxander.settxi.serialization.PrimitiveType import dev.isxander.settxi.serialization.SettxiFileConfig import dev.isxander.settxi.serialization.kotlinxSerializer import dev.isxander.yacl.api.Option +import dev.isxander.yacl.api.OptionFlag import dev.isxander.yacl.api.utils.OptionUtils import dev.isxander.zoomify.Zoomify import dev.isxander.zoomify.utils.TransitionType @@ -169,6 +170,16 @@ object ZoomifySettings : SettxiFileConfig( } } + var keybindScrolling = false + private set + + private var _keybindScrolling by boolean(false) { + name = "zoomify.gui.keybindScrolling.name" + description = "zoomify.gui.keybindScrolling.description" + category = CONTROLS + yaclFlags = setOf(OptionFlag.GAME_RESTART) + } + var relativeSensitivity by int(100) { name = "zoomify.gui.relativeSensitivity.name" description = "zoomify.gui.relativeSensitivity.description" @@ -254,7 +265,6 @@ object ZoomifySettings : SettxiFileConfig( val presetGroup = Group(Text.translatable("zoomify.gui.subcategory.presets")) yaclLabel(Text.translatable("zoomify.gui.preset.apply.warning").formatted(Formatting.RED)) { - name = "" yaclGroup = presetGroup category = MISC } @@ -284,6 +294,8 @@ object ZoomifySettings : SettxiFileConfig( export() needsSaving = false } + + keybindScrolling = _keybindScrolling } fun gui(parent: Screen? = null): Screen = diff --git a/src/main/resources/assets/zoomify/lang/en_gb.json b/src/main/resources/assets/zoomify/lang/en_gb.json index a53d8de..476f9ac 100644 --- a/src/main/resources/assets/zoomify/lang/en_gb.json +++ b/src/main/resources/assets/zoomify/lang/en_gb.json @@ -1,6 +1,7 @@ { "zoomify.key.zoom": "Zoom", - "zoomify.key.gui": "Open GUI", + "zoomify.key.zoom.in": "Scroll Zoom In", + "zoomify.key.zoom.out": "Scroll Zoom Out", "zoomify.key.category": "Zoomify", @@ -37,6 +38,8 @@ "zoomify.gui.category.controls": "Controls", "zoomify.gui.zoomKeyBehaviour.name": "Zoom Key Behaviour", "zoomify.gui.zoomKeyBehaviour.description": "The behaviour of the zoom key.", + "zoomify.gui.keybindScrolling.name": "Keybind Scrolling", + "zoomify.gui.keybindScrolling.description": "Use Minecraft keybinds to control scroll zoom instead of the scroll wheel.", "zoomify.gui.relativeSensitivity.name": "Relative Sensitivity", "zoomify.gui.relativeSensitivity.description": "Controls the sensitivity based on the zoom level.", "zoomify.gui.relativeViewBobbing.name": "Relative View Bobbing", diff --git a/src/main/resources/assets/zoomify/lang/en_us.json b/src/main/resources/assets/zoomify/lang/en_us.json index a5c4fb2..59be9fd 100644 --- a/src/main/resources/assets/zoomify/lang/en_us.json +++ b/src/main/resources/assets/zoomify/lang/en_us.json @@ -1,6 +1,7 @@ { "zoomify.key.zoom": "Zoom", - "zoomify.key.gui": "Open GUI", + "zoomify.key.zoom.in": "Scroll Zoom In", + "zoomify.key.zoom.out": "Scroll Zoom Out", "zoomify.key.category": "Zoomify", @@ -37,6 +38,8 @@ "zoomify.gui.category.controls": "Controls", "zoomify.gui.zoomKeyBehaviour.name": "Zoom Key Behavior", "zoomify.gui.zoomKeyBehaviour.description": "The behavior of the zoom key.", + "zoomify.gui.keybindScrolling.name": "Keybind Scrolling", + "zoomify.gui.keybindScrolling.description": "Use Minecraft keybinds to control scroll zoom instead of the scroll wheel.", "zoomify.gui.relativeSensitivity.name": "Relative Sensitivity", "zoomify.gui.relativeSensitivity.description": "Controls the sensitivity based on the zoom level.", "zoomify.gui.relativeViewBobbing.name": "Relative View Bobbing",