diff options
author | alexia <me@alexia.lol> | 2023-12-11 22:12:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-11 22:12:03 +0100 |
commit | 9d3603e2efe7b0ce5532170d92dadf23d1ac110e (patch) | |
tree | 6c4f01a75a48bc10f208931a0334ff58de7bbd82 /src | |
parent | 8a9f68bc211a70a13470db8672fde6c96e856d5c (diff) | |
download | skyhanni-9d3603e2efe7b0ce5532170d92dadf23d1ac110e.tar.gz skyhanni-9d3603e2efe7b0ce5532170d92dadf23d1ac110e.tar.bz2 skyhanni-9d3603e2efe7b0ce5532170d92dadf23d1ac110e.zip |
Improve accuracy of movement speed display (#788)
Improve accuracy of movement speed display. #788
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/misc/MovementSpeedDisplay.kt | 20 |
1 files changed, 9 insertions, 11 deletions
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 52ca8a3d1..a5aca0f56 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/MovementSpeedDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/MovementSpeedDisplay.kt @@ -7,12 +7,12 @@ 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 lastLocation: LorenzVec? = null private var display = "" init { @@ -24,17 +24,15 @@ class MovementSpeedDisplay { private fun checkSpeed() { if (!isEnabled()) return - val currentLocation = LocationUtils.playerLocation() - if (lastLocation == null) { - lastLocation = currentLocation - return - } + val player = Minecraft.getMinecraft().thePlayer - lastLocation?.let { - val distance = it.distance(currentLocation) * 4 - display = "Movement Speed: ${distance.round(2)}" - lastLocation = currentLocation - } + val oldPos = LorenzVec(player.prevPosX, player.prevPosY, player.prevPosZ) + val newPos = LorenzVec(player.posX, player.posY, player.posZ) + + // Distance from previous tick, multiplied by TPS + val distance = oldPos.distance(newPos) * 20 + + display = "Movement Speed: ${distance.round(2)}" } @SubscribeEvent |