diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-15 17:37:41 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-15 17:37:41 +0100 |
commit | 20cbd14729cd4c9ebc51cc9aee1672964a705fa3 (patch) | |
tree | bfdfaaf07cb6942a321ec8ffca8b83958bdc072b /src/main/java/at/hannibal2/skyhanni/test/HotSwapDetection.kt | |
parent | 3b33e91e5ec71100b212c650ec405b349958bd4b (diff) | |
download | skyhanni-20cbd14729cd4c9ebc51cc9aee1672964a705fa3.tar.gz skyhanni-20cbd14729cd4c9ebc51cc9aee1672964a705fa3.tar.bz2 skyhanni-20cbd14729cd4c9ebc51cc9aee1672964a705fa3.zip |
Fixed hotswap detection not working.
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/test/HotSwapDetection.kt')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/test/HotSwapDetection.kt | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/test/HotSwapDetection.kt b/src/main/java/at/hannibal2/skyhanni/test/HotSwapDetection.kt index 20a0d99a5..f1ab28974 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/HotSwapDetection.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/HotSwapDetection.kt @@ -3,42 +3,39 @@ package at.hannibal2.skyhanni.test import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.MinecraftData import at.hannibal2.skyhanni.utils.LorenzUtils +import net.minecraft.client.Minecraft import kotlin.concurrent.fixedRateTimer object HotSwapDetection { private val config get() = SkyHanniMod.feature.dev.debug private var latestTick = 0 + private var beforeThatTick = 0 private var lastTps = 0 private var hotswap = false init { // TODO seems broken somehow? - fixedRateTimer(name = "skyhanni-hot-swap-detection", period = 1000L) { + fixedRateTimer(name = "skyhanni-hot-swap-detection", period = 250) { val currentTick = MinecraftData.totalTicks val diff = currentTick - latestTick latestTick = currentTick // we count 2 client ticks per tick, we are bad - handleTps(diff / 2) + handleTps(diff * 2) } } private fun handleTps(tps: Int) { + Minecraft.getMinecraft().theWorld ?: return if (!config.hotSwapDetection) return // ignore below one minute if (latestTick < 20 * 60) return - println("diff: $tps") - - if (tps < 5) { - LorenzUtils.debug("Lags! Only $tps tps") - } - if (!hotswap) { - if (tps < 2) { - if (lastTps > 15) { + if (tps < 5) { + if (beforeThatTick > 18) { LorenzUtils.debug("Detected hotswap now!") hotswap = true } @@ -46,9 +43,9 @@ object HotSwapDetection { } else { if (tps > 15) { hotswap = false - LorenzUtils.debug("Detected hotswap end!") } } + beforeThatTick = lastTps lastTps = tps } } |