aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorEmpa <42304516+ItsEmpa@users.noreply.github.com>2024-06-05 13:43:45 +0200
committerGitHub <noreply@github.com>2024-06-05 13:43:45 +0200
commita5687208788bf54491e1341dbd5b2e99ee408221 (patch)
treedf26e6d83ea90bbc2907b636507e02c54ab6854b /src/main
parent3fe6c5aa07a433c33916661b61eea72cc106c045 (diff)
downloadskyhanni-a5687208788bf54491e1341dbd5b2e99ee408221.tar.gz
skyhanni-a5687208788bf54491e1341dbd5b2e99ee408221.tar.bz2
skyhanni-a5687208788bf54491e1341dbd5b2e99ee408221.zip
Fix: Sea Creature Warning (#1985)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureFeatures.kt51
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedCache.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedSet.kt6
3 files changed, 39 insertions, 20 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureFeatures.kt
index e19593859..9dfab5c2b 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureFeatures.kt
@@ -3,17 +3,21 @@ package at.hannibal2.skyhanni.features.fishing
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.config.features.combat.damageindicator.DamageIndicatorConfig
+import at.hannibal2.skyhanni.data.mob.Mob
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.events.MobEvent
import at.hannibal2.skyhanni.events.RenderEntityOutlineEvent
import at.hannibal2.skyhanni.events.SeaCreatureFishEvent
+import at.hannibal2.skyhanni.features.combat.damageindicator.BossType
import at.hannibal2.skyhanni.features.dungeon.DungeonAPI
import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.baseMaxHealth
+import at.hannibal2.skyhanni.utils.MobUtils.mob
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SoundUtils
+import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.TimeLimitedSet
import net.minecraft.entity.Entity
import net.minecraft.entity.EntityLivingBase
@@ -25,31 +29,36 @@ class SeaCreatureFeatures {
private val config get() = SkyHanniMod.feature.fishing.rareCatches
private val damageIndicatorConfig get() = SkyHanniMod.feature.combat.damageIndicator
- private var rareSeaCreatures = listOf<EntityLivingBase>()
private var lastRareCatch = SimpleTimeMark.farPast()
- private var armorStandIds = TimeLimitedSet<Int>(6.minutes)
+ private var rareSeaCreatures = TimeLimitedSet<Mob>(6.minutes)
+ private var entityIds = TimeLimitedSet<Int>(6.minutes)
// TODO remove spawn event, check per tick if can see, cache if already warned about
@SubscribeEvent
fun onMobSpawn(event: MobEvent.Spawn.SkyblockMob) {
if (!isEnabled()) return
- val creature = SeaCreatureManager.allFishingMobs[event.mob.name] ?: return
+ val mob = event.mob
+ val creature = SeaCreatureManager.allFishingMobs[mob.name] ?: return
if (!creature.rare) return
- if (config.highlight && !(damageIndicatorConfig.enabled &&
- DamageIndicatorConfig.BossCategory.SEA_CREATURES in damageIndicatorConfig.bossesToShow)
- ) {
- event.mob.highlight(LorenzColor.GREEN.toColor())
- rareSeaCreatures += event.mob.baseEntity
+ val entity = mob.baseEntity
+ val shouldNotify = entity.entityId !in entityIds
+ entityIds.addIfAbsent(entity.entityId)
+ rareSeaCreatures.add(mob)
+
+ var shouldHighlight = config.highlight
+ if (damageIndicatorConfig.enabled && DamageIndicatorConfig.BossCategory.SEA_CREATURES in damageIndicatorConfig.bossesToShow) {
+ val seaCreaturesBosses =
+ BossType.entries.filter { it.bossTypeToggle == DamageIndicatorConfig.BossCategory.SEA_CREATURES }
+ if (seaCreaturesBosses.any { it.fullName.removeColor() == mob.name }) {
+ shouldHighlight = false
+ }
}
- val id = event.mob.armorStand?.entityId ?: return
- if (armorStandIds.contains(id)) return
- armorStandIds.add(id)
+ if (shouldHighlight) mob.highlight(LorenzColor.GREEN.toColor())
if (lastRareCatch.passedSince() < 1.seconds) return
- if (event.mob.name == "Water Hydra" && event.mob.baseEntity.health == (event.mob.baseEntity.baseMaxHealth.toFloat() / 2)) return
-
- if (config.alertOtherCatches) {
+ if (mob.name == "Water Hydra" && entity.health == (entity.baseMaxHealth.toFloat() / 2)) return
+ if (config.alertOtherCatches && shouldNotify) {
val text = if (config.creatureName) "${creature.displayName} NEARBY!"
else "${creature.rarity.chatColorCode}RARE SEA CREATURE!"
LorenzUtils.sendTitle(text, 1.5.seconds, 3.6, 7f)
@@ -59,7 +68,7 @@ class SeaCreatureFeatures {
@SubscribeEvent
fun onMobDeSpawn(event: MobEvent.DeSpawn.SkyblockMob) {
- rareSeaCreatures.filter { it != event.mob.baseEntity }
+ rareSeaCreatures.remove(event.mob)
}
@SubscribeEvent
@@ -78,8 +87,8 @@ class SeaCreatureFeatures {
@SubscribeEvent
fun onWorldChange(event: LorenzWorldChangeEvent) {
- rareSeaCreatures = listOf()
- armorStandIds.clear()
+ rareSeaCreatures.clear()
+ entityIds.clear()
}
@SubscribeEvent
@@ -97,8 +106,10 @@ class SeaCreatureFeatures {
private fun isEnabled() = LorenzUtils.inSkyBlock && !DungeonAPI.inDungeon() && !LorenzUtils.inKuudraFight
private val getEntityOutlineColor: (entity: Entity) -> Int? = { entity ->
- if (entity is EntityLivingBase && entity in rareSeaCreatures && entity.distanceToPlayer() < 30) {
- LorenzColor.GREEN.toColor().rgb
- } else null
+ (entity as? EntityLivingBase)?.mob?.let { mob ->
+ if (mob in rareSeaCreatures && entity.distanceToPlayer() < 30) {
+ LorenzColor.GREEN.toColor().rgb
+ } else null
+ }
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedCache.kt b/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedCache.kt
index caf5b7734..e17389c52 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedCache.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedCache.kt
@@ -25,6 +25,8 @@ class TimeLimitedCache<K: Any, V: Any>(
fun clear() = cache.invalidateAll()
+ fun remove(key: K) = cache.invalidate(key)
+
fun entries(): Set<Map.Entry<K, V>> = cache.asMap().entries
fun values(): Collection<V> = cache.asMap().values
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedSet.kt b/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedSet.kt
index aab5595da..242d06cf0 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedSet.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedSet.kt
@@ -13,6 +13,12 @@ class TimeLimitedSet<T : Any>(
cache[element] = Unit
}
+ fun addIfAbsent(element: T) {
+ if (!contains(element)) add(element)
+ }
+
+ fun remove(element: T) = cache.remove(element)
+
operator fun contains(element: T): Boolean = cache.containsKey(element)
fun clear() = cache.clear()