From a82b6f8d2567cc68a97128180bc75997da3daf32 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Fri, 22 Mar 2024 21:41:48 +0100 Subject: Fix: Lane Detection (#1239) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../skyhanni/features/misc/MovementSpeedDisplay.kt | 32 ++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/features/misc') diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/MovementSpeedDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/MovementSpeedDisplay.kt index a30635fb5..42308466b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/MovementSpeedDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/MovementSpeedDisplay.kt @@ -3,20 +3,48 @@ package at.hannibal2.skyhanni.features.misc import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.enums.OutsideSbFeature import at.hannibal2.skyhanni.events.GuiRenderEvent -import at.hannibal2.skyhanni.utils.LocationUtils import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.round +import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.RenderUtils.renderString +import net.minecraft.client.Minecraft import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.concurrent.fixedRateTimer class MovementSpeedDisplay { private val config get() = SkyHanniMod.feature.misc + private var display = "" + + companion object { + var speedInLastTick = 0.0 + } + + init { + fixedRateTimer(name = "skyhanni-movement-speed-display", period = 250, initialDelay = 1_000) { + checkSpeed() + } + } + + private fun checkSpeed() { + if (!isEnabled()) return + + speedInLastTick = with(Minecraft.getMinecraft().thePlayer) { + val oldPos = LorenzVec(prevPosX, prevPosY, prevPosZ) + val newPos = LorenzVec(posX, posY, posZ) + + // Distance from previous tick, multiplied by TPS + oldPos.distance(newPos) * 20 + } + display = "Movement Speed: ${speedInLastTick.round(2)}" + } + @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { if (!isEnabled()) return - config.playerMovementSpeedPos.renderString("Movement Speed: ${LocationUtils.distanceFromPreviousTick()}", posLabel = "Movement Speed") + config.playerMovementSpeedPos.renderString(display, posLabel = "Movement Speed") } fun isEnabled() = LorenzUtils.onHypixel && -- cgit