diff options
author | Empa <42304516+ItsEmpa@users.noreply.github.com> | 2024-05-29 22:34:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-29 22:34:18 +0200 |
commit | 568a3a864ef6970a8fb7b31b6cc65d117f749681 (patch) | |
tree | b12a597723f56e5dafc0f15a5b938eae5ad62c48 /src/main/java/at/hannibal2/skyhanni/features | |
parent | 97f4433127b9a0e9963eb727a0c5fd8594ac70f5 (diff) | |
download | skyhanni-568a3a864ef6970a8fb7b31b6cc65d117f749681.tar.gz skyhanni-568a3a864ef6970a8fb7b31b6cc65d117f749681.tar.bz2 skyhanni-568a3a864ef6970a8fb7b31b6cc65d117f749681.zip |
Improvement + Fix: Sea Creature Alert (#1858)
Co-authored-by: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureFeatures.kt | 96 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureManager.kt | 4 |
2 files changed, 39 insertions, 61 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 bbead46b4..5bebcfe27 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureFeatures.kt @@ -2,77 +2,75 @@ package at.hannibal2.skyhanni.features.fishing import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator -import at.hannibal2.skyhanni.events.EntityMaxHealthUpdateEvent +import at.hannibal2.skyhanni.config.features.combat.damageindicator.DamageIndicatorConfig 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.DamageIndicatorManager import at.hannibal2.skyhanni.features.dungeon.DungeonAPI -import at.hannibal2.skyhanni.mixins.hooks.RenderLivingEntityHelper -import at.hannibal2.skyhanni.utils.CollectionUtils.editCopy -import at.hannibal2.skyhanni.utils.ColorUtils.withAlpha -import at.hannibal2.skyhanni.utils.EntityUtils.hasMaxHealth -import at.hannibal2.skyhanni.utils.EntityUtils.hasNameTagWith 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.LorenzUtils.ignoreDerpy import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.SoundUtils +import at.hannibal2.skyhanni.utils.TimeLimitedSet import net.minecraft.entity.Entity import net.minecraft.entity.EntityLivingBase -import net.minecraft.entity.monster.EntityGuardian -import net.minecraft.entity.monster.EntityIronGolem -import net.minecraft.entity.monster.EntitySkeleton -import net.minecraft.entity.monster.EntityZombie -import net.minecraft.entity.passive.EntitySquid -import net.minecraft.entity.player.EntityPlayer import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds 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) @SubscribeEvent - fun onEntityHealthUpdate(event: EntityMaxHealthUpdateEvent) { + fun onMobSpawn(event: MobEvent.Spawn.SkyblockMob) { if (!isEnabled()) return - val entity = event.entity as? EntityLivingBase ?: return - if (DamageIndicatorManager.isBoss(entity)) return - - // TODO remove workaround by change derpy logic either in hasMaxHealth or in EntityMaxHealthUpdateEvent - val maxHealth = event.maxHealth.ignoreDerpy() - for (creatureType in RareSeaCreatureType.entries) { - if (!creatureType.health.any { entity.hasMaxHealth(it, false, maxHealth) }) continue - if (!creatureType.clazz.isInstance(entity)) continue - if (!entity.hasNameTagWith(3, creatureType.nametag)) continue - - rareSeaCreatures = rareSeaCreatures.editCopy { add(entity) } - RenderLivingEntityHelper.setEntityColorWithNoHurtTime(entity, LorenzColor.RED.toColor().withAlpha(50)) - { config.highlight } + val creature = SeaCreatureManager.allFishingMobs[event.mob.name] ?: return + if (!creature.rare) return + + if (config.highlight && !(damageIndicatorConfig.enabled && damageIndicatorConfig.bossesToShow.contains( + DamageIndicatorConfig.BossCategory.SEA_CREATURES + )) + ) { + event.mob.highlight(LorenzColor.GREEN.toColor()) + rareSeaCreatures += event.mob.baseEntity + } + val id = event.mob.armorStand?.entityId ?: return + if (armorStandIds.contains(id)) return + armorStandIds.add(id) - // Water hydra splitting in two - if (creatureType == RareSeaCreatureType.WATER_HYDRA && entity.health == (entity.baseMaxHealth.toFloat() / 2)) continue + 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 && lastRareCatch.passedSince() > 1.seconds) { - val creature = SeaCreatureManager.allFishingMobs[creatureType.nametag] - val text = "${creature?.rarity?.chatColorCode ?: "§6"}RARE SEA CREATURE!" - LorenzUtils.sendTitle(text, 1.5.seconds, 3.6, 7f) - if (config.playSound) SoundUtils.playBeepSound() - } + if (config.alertOtherCatches) { + val text = if (config.creatureName) "${creature.displayName} NEARBY!" + else "${creature.rarity.chatColorCode}RARE SEA CREATURE!" + LorenzUtils.sendTitle(text, 1.5.seconds, 3.6, 7f) + if (config.playSound) SoundUtils.playBeepSound() } } @SubscribeEvent + fun onMobDeSpawn(event: MobEvent.DeSpawn.SkyblockMob) { + rareSeaCreatures.filter { it != event.mob.baseEntity } + } + + @SubscribeEvent fun onSeaCreatureFish(event: SeaCreatureFishEvent) { if (!LorenzUtils.inSkyBlock) return if (!config.alertOwnCatches) return if (event.seaCreature.rare) { - LorenzUtils.sendTitle("${event.seaCreature.rarity.chatColorCode}RARE CATCH!", 3.seconds, 2.8, 7f) + val text = if (config.creatureName) "${event.seaCreature.displayName}!" + else "${event.seaCreature.rarity.chatColorCode}RARE CATCH!" + LorenzUtils.sendTitle(text, 3.seconds, 2.8, 7f) if (config.playSound) SoundUtils.playBeepSound() lastRareCatch = SimpleTimeMark.now() } @@ -80,7 +78,8 @@ class SeaCreatureFeatures { @SubscribeEvent fun onWorldChange(event: LorenzWorldChangeEvent) { - rareSeaCreatures = emptyList() + rareSeaCreatures = listOf() + armorStandIds.clear() } @SubscribeEvent @@ -102,25 +101,4 @@ class SeaCreatureFeatures { LorenzColor.GREEN.toColor().rgb } else null } - - enum class RareSeaCreatureType( - val clazz: Class<out EntityLivingBase>, - val nametag: String, - vararg val health: Int, - ) { - - WATER_HYDRA(EntityZombie::class.java, "Water Hydra", 500_000), - SEA_EMPEROR(EntityGuardian::class.java, "Sea Emperor", 750_000, 800_000), - SEA_EMPEROR_RIDER(EntitySkeleton::class.java, "Sea Emperor", 750_000, 800_000), - ZOMBIE_MINER(EntityPlayer::class.java, "Zombie Miner", 2_000_000), - PHANTOM_FISHERMAN(EntityPlayer::class.java, "Phantom Fisher", 1_000_000), - GRIM_REAPER(EntityPlayer::class.java, "Grim Reaper", 3_000_000), - YETI(EntityPlayer::class.java, "Yeti", 2_000_000), - NUTCRACKER(EntityZombie::class.java, "Nutcracker", 4_000_000), - GREAT_WHITE_SHARK(EntityPlayer::class.java, "Great White Shark", 1_500_000), - THUNDER(EntityGuardian::class.java, "Thunder", 35_000_000), - LORD_JAWBUS(EntityIronGolem::class.java, "Lord Jawbus", 100_000_000), - PLHLEGBLAST(EntitySquid::class.java, "Plhlegblast", 500_000_000), - ; - } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureManager.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureManager.kt index bfff1d7be..59d9d818b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureManager.kt @@ -21,7 +21,7 @@ class SeaCreatureManager { } doubleHook = true } else { - val seaCreature = getSeaCreature(event.message) + val seaCreature = getSeaCreatureFromMessage(event.message) if (seaCreature != null) { SeaCreatureFishEvent(seaCreature, event, doubleHook).postAndCatch() } @@ -72,7 +72,7 @@ class SeaCreatureManager { "§eIt's a §r§aDouble Hook§r§e!" ) - fun getSeaCreature(message: String): SeaCreature? { + fun getSeaCreatureFromMessage(message: String): SeaCreature? { return seaCreatureMap.getOrDefault(message, null) } } |