generated from isXander/FabricKotlinTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add separate keybinds for hold/toggle and fix controlify compat
- Loading branch information
Showing
13 changed files
with
144 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Zoomify 2.13.5 | ||
|
||
Zoomify now targets the following Minecraft versions: | ||
|
||
- 1.20.1 | ||
- 1.20.4 (also supports 1.20.3) | ||
- 1.20.6 (also supports 1.20.5) | ||
|
||
Make sure you download the correct version for your Minecraft version! | ||
|
||
## Changes | ||
|
||
- Fix Controlify compatibility | ||
- Remove zoom key behaviour option and instead have two separate keybinds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 51 additions & 12 deletions
63
src/main/kotlin/dev/isxander/zoomify/integrations/ControlifyIntegration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,70 @@ | ||
package dev.isxander.zoomify.integrations | ||
|
||
import dev.isxander.controlify.api.ControlifyApi | ||
import dev.isxander.controlify.api.bind.ControlifyBindingsApi | ||
import dev.isxander.controlify.api.bind.ControlifyBindApi | ||
import dev.isxander.controlify.api.bind.InputBinding | ||
import dev.isxander.controlify.api.bind.InputBindingSupplier | ||
import dev.isxander.controlify.api.entrypoint.ControlifyEntrypoint | ||
import dev.isxander.controlify.api.event.ControlifyEvents | ||
import dev.isxander.controlify.api.ingameinput.LookInputModifier | ||
import dev.isxander.controlify.controller.ControllerEntity | ||
import dev.isxander.controlify.bindings.BindContext | ||
import dev.isxander.controlify.bindings.RadialIcons | ||
import dev.isxander.zoomify.Zoomify | ||
import dev.isxander.zoomify.config.ZoomifySettings | ||
import dev.isxander.zoomify.utils.KeySource | ||
import net.minecraft.network.chat.Component | ||
import net.minecraft.util.Mth | ||
import net.minecraft.world.item.Items | ||
|
||
object ControlifyIntegration : ControlifyEntrypoint { | ||
private val category = Component.translatable("zoomify.key.category") | ||
|
||
val ZOOM_HOLD = ControlifyBindApi.get().registerBinding { it.apply { | ||
id("zoomify", "zoom_hold") | ||
allowedContexts(BindContext.IN_GAME) | ||
addKeyCorrelation(Zoomify.zoomHoldKeyMapping) | ||
category(category) | ||
name(Component.translatable(Zoomify.zoomHoldKeyMapping.name)) | ||
} } | ||
val ZOOM_TOGGLE = ControlifyBindApi.get().registerBinding { it.apply { | ||
id("zoomify", "zoom_toggle") | ||
allowedContexts(BindContext.IN_GAME) | ||
addKeyCorrelation(Zoomify.zoomToggleKeyMapping) | ||
radialCandidate(RadialIcons.getItem(Items.SPYGLASS)) | ||
category(category) | ||
name(Component.translatable(Zoomify.zoomToggleKeyMapping.name)) | ||
} } | ||
val SECONDARY_ZOOM = ControlifyBindApi.get().registerBinding { it.apply { | ||
id("zoomify", "secondary_zoom") | ||
allowedContexts(BindContext.IN_GAME) | ||
addKeyCorrelation(Zoomify.secondaryZoomKeyMapping) | ||
radialCandidate(RadialIcons.getItem(Items.SPYGLASS)) | ||
category(category) | ||
name(Component.translatable(Zoomify.secondaryZoomKeyMapping.name)) | ||
} } | ||
|
||
override fun onControlifyPreInit(controlify: ControlifyApi) { | ||
ControlifyEvents.LOOK_INPUT_MODIFIER.register(SensitivityModifier) | ||
ControlifyEvents.LOOK_INPUT_MODIFIER.register { event -> | ||
event.lookInput.x /= Mth.lerp(ZoomifySettings.relativeSensitivity / 100.0, 1.0, Zoomify.previousZoomDivisor).toFloat() | ||
event.lookInput.y /= Mth.lerp(ZoomifySettings.relativeSensitivity / 100.0, 1.0, Zoomify.previousZoomDivisor).toFloat() | ||
} | ||
|
||
Zoomify.zoomHoldKey.addSource(InputBindingKeySource(ZOOM_HOLD)) | ||
Zoomify.zoomToggleKey.addSource(InputBindingKeySource(ZOOM_TOGGLE)) | ||
Zoomify.secondaryZoomKey.addSource(InputBindingKeySource(SECONDARY_ZOOM)) | ||
} | ||
|
||
override fun onControllersDiscovered(controlify: ControlifyApi) { | ||
|
||
} | ||
} | ||
|
||
object SensitivityModifier : LookInputModifier { | ||
override fun modifyX(x: Float, controller: ControllerEntity): Float { | ||
return x * Mth.lerp(ZoomifySettings.relativeSensitivity / 100.0, 1.0, Zoomify.previousZoomDivisor).toFloat() | ||
} | ||
private class InputBindingKeySource(private val bindingSupplier: InputBindingSupplier) : KeySource { | ||
private val binding: InputBinding? | ||
get() = ControlifyApi.get().currentController.orElse(null)?.let { bindingSupplier.on(it) } | ||
|
||
override fun modifyY(y: Float, controller: ControllerEntity): Float { | ||
return y * Mth.lerp(ZoomifySettings.relativeSensitivity / 100.0, 1.0, Zoomify.previousZoomDivisor).toFloat() | ||
} | ||
} | ||
override val justPressed: Boolean | ||
get() = binding?.justPressed() == true | ||
|
||
override val isDown: Boolean | ||
get() = binding?.digitalNow() == true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package dev.isxander.zoomify.utils | ||
|
||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper | ||
import net.minecraft.client.KeyMapping | ||
|
||
interface KeySource { | ||
val justPressed: Boolean | ||
|
||
val isDown: Boolean | ||
} | ||
|
||
class MultiKeySource(sources: List<KeySource>) : KeySource { | ||
private val sources = sources.toMutableList() | ||
|
||
constructor(vararg sources: KeySource) : this(sources.toList()) | ||
constructor() : this(emptyList()) | ||
|
||
override val justPressed: Boolean | ||
get() = sources.any { it.justPressed } | ||
|
||
override val isDown: Boolean | ||
get() = sources.any { it.isDown } | ||
|
||
fun addSource(source: KeySource) { | ||
sources.add(source) | ||
} | ||
} | ||
|
||
fun KeyMapping.toKeySource(register: Boolean = false) = object : KeySource { | ||
override val justPressed: Boolean | ||
get() = this@toKeySource.consumeClick() | ||
|
||
override val isDown: Boolean | ||
get() = this@toKeySource.isDown | ||
}.also { if (register) KeyBindingHelper.registerKeyBinding(this) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,7 @@ | |
"modmenu": "*" | ||
}, | ||
"breaks": { | ||
"optifabric": "*" | ||
"optifabric": "*", | ||
"controlify": "<2.0.0-beta.9" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters