diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
3 files changed, 10 insertions, 3 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt index 20bf02bb7..3aa530c22 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt @@ -1040,6 +1040,7 @@ object RenderUtils { } fun exactLocation(entity: Entity, partialTicks: Float): LorenzVec { + if (entity.isDead) return entity.getLorenzVec() val x = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * partialTicks val y = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * partialTicks val z = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * partialTicks diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedCache.kt b/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedCache.kt index 8b4b0c372..182b1381b 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedCache.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedCache.kt @@ -4,10 +4,10 @@ import com.google.common.cache.CacheBuilder import java.util.concurrent.TimeUnit import kotlin.time.Duration -class TimeLimitedCache<K, V>( +class TimeLimitedCache<K: Any, V: Any>( expireAfterWrite: Duration, private val removalListener: (K?, V?) -> Unit = { _, _ -> }, -) { +): Iterable<Map.Entry<K, V>> { private val cache = CacheBuilder.newBuilder() .expireAfterWrite(expireAfterWrite.inWholeMilliseconds, TimeUnit.MILLISECONDS) @@ -18,11 +18,17 @@ class TimeLimitedCache<K, V>( fun getOrNull(key: K): V? = cache.getIfPresent(key) + fun getOrPut(key: K, defaultValue: () -> V) = getOrNull(key) ?: defaultValue().also { put(key, it) } + fun clear() = cache.invalidateAll() + fun entries(): Set<Map.Entry<K, V>> = cache.asMap().entries + fun values(): Collection<V> = cache.asMap().values fun keys(): Set<K> = cache.asMap().keys fun containsKey(key: K): Boolean = cache.getIfPresent(key) != null + + override fun iterator(): Iterator<Map.Entry<K, V>> = entries().iterator() } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedSet.kt b/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedSet.kt index 5f0ccd404..fae86fac5 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedSet.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedSet.kt @@ -2,7 +2,7 @@ package at.hannibal2.skyhanni.utils import kotlin.time.Duration -class TimeLimitedSet<T>( +class TimeLimitedSet<T: Any>( expireAfterWrite: Duration, private val removalListener: (T) -> Unit = {}, ) { |