blob: dbf76a3dc2242442128f6f85917543d32a2870f4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
package at.hannibal2.skyhanni.features.misc
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.GuiRenderEvent
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 = ""
init {
fixedRateTimer(name = "skyhanni-movement-speed-display", period = 250, initialDelay = 1_000) {
checkSpeed()
}
}
private fun checkSpeed() {
if (!isEnabled()) return
val distance = 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: ${distance.round(2)}"
}
@SubscribeEvent
fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) {
if (!isEnabled()) return
config.playerMovementSpeedPos.renderString(display, posLabel = "Movement Speed")
}
fun isEnabled() = LorenzUtils.inSkyBlock && config.playerMovementSpeed
}
|