diff options
Diffstat (limited to 'src/main/java/at')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/slayer/HideMobNames.kt | 17 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/summonings/SummoningSoulsName.kt | 15 |
2 files changed, 19 insertions, 13 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/HideMobNames.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/HideMobNames.kt index 28b03f597..c2534b02b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/slayer/HideMobNames.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/HideMobNames.kt @@ -5,16 +5,18 @@ import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.events.SkyHanniRenderEntityEvent import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.TimeLimitedCache import net.minecraft.entity.EntityLivingBase import net.minecraft.entity.item.EntityArmorStand import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.regex.Pattern +import kotlin.time.Duration.Companion.minutes class HideMobNames { - private val lastMobName = mutableMapOf<EntityArmorStand, String>() - private val mobNamesHidden = mutableListOf<EntityArmorStand>() + private val lastMobName = TimeLimitedCache<Int, String>(2.minutes) + private val mobNamesHidden = mutableListOf<Int>() private val patterns = mutableListOf<Pattern>() init { @@ -56,19 +58,20 @@ class HideMobNames { if (!entity.hasCustomName()) return val name = entity.name - if (lastMobName.getOrDefault(entity, "abc") == name) { - if (entity in mobNamesHidden) { + val id = entity.entityId + if (lastMobName.getOrNull(id) == name) { + if (id in mobNamesHidden) { event.isCanceled = true } return } - lastMobName[entity] = name - mobNamesHidden.remove(entity) + lastMobName.put(id, name) + mobNamesHidden.remove(id) if (shouldNameBeHidden(name)) { event.isCanceled = true - mobNamesHidden.add(entity) + mobNamesHidden.add(id) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/summonings/SummoningSoulsName.kt b/src/main/java/at/hannibal2/skyhanni/features/summonings/SummoningSoulsName.kt index ce4a5e406..cabd8dd4e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/summonings/SummoningSoulsName.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/summonings/SummoningSoulsName.kt @@ -11,10 +11,12 @@ import at.hannibal2.skyhanni.utils.EntityUtils.hasSkullTexture import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.RenderUtils.drawString +import at.hannibal2.skyhanni.utils.TimeLimitedCache import at.hannibal2.skyhanni.utils.getLorenzVec import net.minecraft.entity.EntityLiving import net.minecraft.entity.item.EntityArmorStand import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.minutes class SummoningSoulsName { @@ -27,8 +29,8 @@ class SummoningSoulsName { "NjkxNzc4ZDVlOTU4NDAxNzAyMjdlYjllM2UyOTQzYmVhODUzOTI5Y2U5MjNjNTk4OWFkIgogICAgfQogIH0KfQ" private val souls = mutableMapOf<EntityArmorStand, String>() - private val mobsLastLocation = mutableMapOf<EntityLiving, LorenzVec>() - private val mobsName = mutableMapOf<EntityLiving, String>() + private val mobsLastLocation = TimeLimitedCache<Int, LorenzVec>(6.minutes) + private val mobsName = TimeLimitedCache<Int, String>(6.minutes) @SubscribeEvent fun onTick(event: LorenzTickEvent) { @@ -45,7 +47,7 @@ class SummoningSoulsName { if (entity.hasSkullTexture(texture)) { val soulLocation = entity.getLorenzVec() - val map = mutableMapOf<EntityLiving, Double>() + val map = mutableMapOf<Int, Double>() for ((mob, loc) in mobsLastLocation) { val distance = loc.distance(soulLocation) map[mob] = distance @@ -53,16 +55,17 @@ class SummoningSoulsName { val nearestMob = map.sorted().firstNotNullOfOrNull { it.key } if (nearestMob != null) { - souls[entity] = mobsName[nearestMob]!! + souls[entity] = mobsName.getOrNull(nearestMob)!! } } } for (entity in EntityUtils.getEntities<EntityLiving>()) { + val id = entity.entityId val consumer = entity.getNameTagWith(2, "§c❤") if (consumer != null && !consumer.name.contains("§e0")) { - mobsLastLocation[entity] = entity.getLorenzVec() - mobsName[entity] = consumer.name + mobsLastLocation.put(id, entity.getLorenzVec()) + mobsName.put(id, consumer.name) } } |