diff options
Diffstat (limited to 'src/main')
4 files changed, 28 insertions, 18 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/DamageIndicatorManager.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/DamageIndicatorManager.kt index 1c50a65ab..1b4f1fc32 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/DamageIndicatorManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/DamageIndicatorManager.kt @@ -31,13 +31,15 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.baseMaxHealth import at.hannibal2.skyhanni.utils.LorenzUtils.editCopy import at.hannibal2.skyhanni.utils.LorenzUtils.put import at.hannibal2.skyhanni.utils.LorenzUtils.round +import at.hannibal2.skyhanni.utils.LorenzUtils.ticks import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText +import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.asTimeMark import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import at.hannibal2.skyhanni.utils.TimeUtils +import at.hannibal2.skyhanni.utils.TimeUtils.format import at.hannibal2.skyhanni.utils.getLorenzVec import net.minecraft.client.Minecraft import net.minecraft.client.entity.EntityOtherPlayerMP @@ -55,6 +57,8 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.UUID import kotlin.math.max +import kotlin.time.Duration +import kotlin.time.Duration.Companion.seconds class DamageIndicatorManager { @@ -168,9 +172,11 @@ class DamageIndicatorManager { var healthText = data.healthText val delayedStart = data.delayedStart - if (delayedStart != -1L && delayedStart > System.currentTimeMillis()) { - val delay = delayedStart - System.currentTimeMillis() - healthText = formatDelay(delay) + delayedStart?.let { + if (!it.isInPast()) { + val delay = it.timeUntil() + healthText = formatDelay(delay) + } } val location = if (data.dead && data.deathLocation != null) { @@ -297,14 +303,14 @@ class DamageIndicatorManager { damageCounter.oldDamages.removeIf { now > it.time + 5_000 } } - private fun formatDelay(delay: Long): String { + private fun formatDelay(delay: Duration): String { val color = when { - delay < 1_000 -> LorenzColor.DARK_PURPLE - delay < 3_000 -> LorenzColor.LIGHT_PURPLE + delay < 1.seconds -> LorenzColor.DARK_PURPLE + delay < 3.seconds -> LorenzColor.LIGHT_PURPLE else -> LorenzColor.WHITE } - val format = TimeUtils.formatDuration(delay, showMilliSeconds = true) + val format = delay.format(showMilliSeconds = true) return color.getChatColor() + format } @@ -646,15 +652,16 @@ class DamageIndicatorManager { //Laser phase if (config.enderSlayer.laserPhaseTimer && entity.ridingEntity != null) { - val ticksAlive = entity.ridingEntity.ticksExisted.toLong() //TODO more tests, more exact values, better logic? idk make this working perfectly pls - //val remainingTicks = 8 * 20 - ticksAlive - val remainingTicks = (7.4 * 20).toLong() - ticksAlive + val totalTimeAlive = 7.4.seconds + val ticksAlive = entity.ridingEntity.ticksExisted.ticks + val remainingTime = totalTimeAlive - ticksAlive + val formatDelay = formatDelay(remainingTime) if (config.enderSlayer.showHealthDuringLaser) { - entityData.nameSuffix = " §f" + formatDelay(remainingTicks * 50) + entityData.nameSuffix = " §f$formatDelay" } else { - return formatDelay(remainingTicks * 50) + return formatDelay } } @@ -789,7 +796,7 @@ class DamageIndicatorManager { val entityData = EntityData( entity, entityResult.ignoreBlocks, - entityResult.delayedStart, + entityResult.delayedStart?.asTimeMark(), entityResult.finalDungeonBoss, entityResult.bossType, foundTime = System.currentTimeMillis() diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/EntityData.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/EntityData.kt index 50e5b4547..7d8f52a74 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/EntityData.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/EntityData.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.features.combat.damageindicator import at.hannibal2.skyhanni.utils.LorenzVec +import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.TimeUnit import at.hannibal2.skyhanni.utils.TimeUtils import net.minecraft.entity.EntityLivingBase @@ -8,7 +9,7 @@ import net.minecraft.entity.EntityLivingBase class EntityData( val entity: EntityLivingBase, var ignoreBlocks: Boolean, - var delayedStart: Long, + var delayedStart: SimpleTimeMark?, val finalDungeonBoss: Boolean, val bossType: BossType, val damageCounter: DamageCounter = DamageCounter(), diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/EntityResult.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/EntityResult.kt index 4f6920293..2488b00ef 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/EntityResult.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/EntityResult.kt @@ -1,8 +1,8 @@ package at.hannibal2.skyhanni.features.combat.damageindicator class EntityResult( - val delayedStart: Long = -1L, + val delayedStart: Long? = null, val ignoreBlocks: Boolean = false, val finalDungeonBoss: Boolean = false, val bossType: BossType = BossType.GENERIC_DUNGEON_BOSS, -)
\ No newline at end of file +) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index 8371c9176..cd71efe65 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -42,8 +42,8 @@ import java.util.Queue import java.util.Timer import java.util.TimerTask import java.util.WeakHashMap -import java.util.regex.Matcher import java.util.concurrent.ConcurrentLinkedQueue +import java.util.regex.Matcher import kotlin.properties.ReadWriteProperty import kotlin.reflect.KMutableProperty1 import kotlin.reflect.KProperty @@ -712,4 +712,6 @@ object LorenzUtils { fun <T> MutableCollection<T>.filterToMutable(predicate: (T) -> Boolean) = filterTo(mutableListOf(), predicate) + val Long.ticks get() = (this * 50).milliseconds + val Int.ticks get() = (this * 50).milliseconds } |