Add auto sprint toggle keybinding
This commit is contained in:
23
src/main/java/moe/nea/firmament/mixins/MixinInGameHud.java
Normal file
23
src/main/java/moe/nea/firmament/mixins/MixinInGameHud.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package moe.nea.firmament.mixins;
|
||||
|
||||
import moe.nea.firmament.events.HudRenderEvent;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.hud.InGameHud;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(InGameHud.class)
|
||||
public class MixinInGameHud {
|
||||
@Inject(method = "render", at = @At(value = "INVOKE",target = "Lnet/minecraft/client/network/ClientPlayerEntity;getSleepTimer()I"))
|
||||
public void renderCallBack(DrawContext context, float tickDelta, CallbackInfo ci) {
|
||||
HudRenderEvent.Companion.publish(new HudRenderEvent(context, tickDelta));
|
||||
}
|
||||
}
|
||||
16
src/main/kotlin/moe/nea/firmament/events/HudRenderEvent.kt
Normal file
16
src/main/kotlin/moe/nea/firmament/events/HudRenderEvent.kt
Normal file
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package moe.nea.firmament.events
|
||||
|
||||
import net.minecraft.client.gui.DrawContext
|
||||
|
||||
/**
|
||||
* Called when hud elements should be rendered, before the screen, but after the world.
|
||||
*/
|
||||
data class HudRenderEvent(val context: DrawContext, val tickDelta: Float) : FirmamentEvent() {
|
||||
companion object : FirmamentEventBus<HudRenderEvent>()
|
||||
}
|
||||
@@ -6,11 +6,15 @@
|
||||
|
||||
package moe.nea.firmament.features.fixes
|
||||
|
||||
import moe.nea.firmament.events.HudRenderEvent
|
||||
import moe.nea.firmament.events.WorldKeyboardEvent
|
||||
import moe.nea.firmament.features.FirmamentFeature
|
||||
import moe.nea.firmament.gui.config.ManagedConfig
|
||||
import moe.nea.firmament.util.MC
|
||||
import moe.nea.jarvis.api.Point
|
||||
import net.minecraft.client.MinecraftClient
|
||||
import net.minecraft.client.option.KeyBinding
|
||||
import net.minecraft.text.Text
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable
|
||||
|
||||
object Fixes : FirmamentFeature {
|
||||
@@ -19,7 +23,9 @@ object Fixes : FirmamentFeature {
|
||||
|
||||
object TConfig : ManagedConfig(identifier) {
|
||||
val fixUnsignedPlayerSkins by toggle("player-skins") { true }
|
||||
val autoSprint by toggle("auto-sprint") { false }
|
||||
var autoSprint by toggle("auto-sprint") { false }
|
||||
val autoSprintKeyBinding by keyBindingWithDefaultUnbound("auto-sprint-keybinding")
|
||||
val autoSprintHud by position("auto-sprint-hud", 80, 10) { Point(0.0, 1.0) }
|
||||
val peekChat by keyBindingWithDefaultUnbound("peek-chat")
|
||||
}
|
||||
|
||||
@@ -35,6 +41,27 @@ object Fixes : FirmamentFeature {
|
||||
}
|
||||
|
||||
override fun onLoad() {
|
||||
WorldKeyboardEvent.subscribe {
|
||||
if (it.matches(TConfig.autoSprintKeyBinding)) {
|
||||
TConfig.autoSprint = !TConfig.autoSprint
|
||||
}
|
||||
}
|
||||
HudRenderEvent.subscribe {
|
||||
if (!TConfig.autoSprintKeyBinding.isBound) return@subscribe
|
||||
it.context.matrices.push()
|
||||
TConfig.autoSprintHud.applyTransformations(it.context.matrices)
|
||||
it.context.drawText(
|
||||
MC.font, Text.translatable(
|
||||
if (TConfig.autoSprint)
|
||||
"firmament.fixes.auto-sprint.on"
|
||||
else if (MC.player?.isSprinting == true)
|
||||
"firmament.fixes.auto-sprint.sprinting"
|
||||
else
|
||||
"firmament.fixes.auto-sprint.not-sprinting"
|
||||
), 0, 0, -1, false
|
||||
)
|
||||
it.context.matrices.pop()
|
||||
}
|
||||
}
|
||||
|
||||
fun shouldPeekChat(): Boolean {
|
||||
|
||||
@@ -19,6 +19,8 @@ data class SavedKeyBinding(
|
||||
val ctrl: Boolean = false,
|
||||
val alt: Boolean = false,
|
||||
) : IKeyBinding {
|
||||
val isBound: Boolean get() = keyCode != GLFW.GLFW_KEY_UNKNOWN
|
||||
|
||||
constructor(keyCode: Int, mods: Triple<Boolean, Boolean, Boolean>) : this(
|
||||
keyCode,
|
||||
mods.first && keyCode != GLFW.GLFW_KEY_LEFT_SHIFT && keyCode != GLFW.GLFW_KEY_RIGHT_SHIFT,
|
||||
@@ -39,7 +41,7 @@ data class SavedKeyBinding(
|
||||
}
|
||||
|
||||
fun isPressed(atLeast: Boolean = false): Boolean {
|
||||
if (this.keyCode == GLFW.GLFW_KEY_UNKNOWN) return false
|
||||
if (!isBound) return false
|
||||
val h = MC.window.handle
|
||||
if (!InputUtil.isKeyPressed(h, keyCode)) return false
|
||||
|
||||
|
||||
@@ -89,6 +89,12 @@
|
||||
"firmament.config.slot-locking": "Slot Locking",
|
||||
"firmament.config.slot-locking.lock": "Lock Slot",
|
||||
"firmament.config.fixes.auto-sprint": "Auto Sprint",
|
||||
"firmament.config.fixes.auto-sprint-keybinding": "Auto Sprint KeyBinding",
|
||||
"firmament.config.fixes.auto-sprint-hud": "Sprint State Hud",
|
||||
"firmament.config.fixes.peek-chat": "Peek Chat",
|
||||
"firmament.fixes.auto-sprint.on": "Sprint toggled",
|
||||
"firmament.fixes.auto-sprint.sprinting": "Sprinting",
|
||||
"firmament.fixes.auto-sprint.not-sprinting": "Not Sprinting",
|
||||
"firmament.config.custom-skyblock-textures": "Custom SkyBlock Item Textures",
|
||||
"firmament.config.custom-skyblock-textures.cache-duration": "Model Cache Duration",
|
||||
"firmament.config.custom-skyblock-textures.enabled": "Enable Custom Item Textures",
|
||||
|
||||
Reference in New Issue
Block a user