smoother ability cooldown display (rubberbanding due to late sync)

This commit is contained in:
YuRaNnNzZZ 2023-11-16 13:28:15 +03:00
parent f13f9481ea
commit 8dcf484362
Signed by: YuRaNnNzZZ
GPG Key ID: 5F71738C85A6006D

View File

@ -1,8 +1,10 @@
package ru.dbotthepony.mc.otm.android
import net.minecraft.client.gui.GuiGraphics
import net.minecraft.client.multiplayer.ClientLevel
import net.minecraft.nbt.CompoundTag
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
import ru.dbotthepony.mc.otm.client.minecraft
import ru.dbotthepony.mc.otm.core.math.RGBAColor
import ru.dbotthepony.mc.otm.core.nbt.set
@ -31,6 +33,11 @@ abstract class AndroidSwitchableFeature(type: AndroidFeatureType<*>, android: Ma
val cooldownPercent: Float get() {
if (maxCooldown <= 0) return 0.0f
if (ply.level() is ClientLevel) {
return ((cooldown.toFloat() - minecraft.partialTick) / maxCooldown.toFloat()).coerceIn(0.0f, 1.0f)
}
return (cooldown.toFloat() / maxCooldown.toFloat()).coerceIn(0.0f, 1.0f)
}