Skip to content

Commit

Permalink
Improve accuracy of movement speed display (#788)
Browse files Browse the repository at this point in the history
Improve accuracy of movement speed display. #788
  • Loading branch information
qtlunya authored Dec 11, 2023
1 parent 8a9f68b commit 9d3603e
Showing 1 changed file with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit 9d3603e

Please sign in to comment.