diff options
author | Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> | 2024-07-07 11:39:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-07 11:39:05 +0200 |
commit | 6b3e2d7b0cf478deb2d8f5876a402c01508a5d43 (patch) | |
tree | a304fd65a19ed3367c7c53d402ddda8e1cf31a60 /src/main/java/at | |
parent | c4b42412d844bb943144fd17f3a4d134c8ed5eea (diff) | |
download | skyhanni-6b3e2d7b0cf478deb2d8f5876a402c01508a5d43.tar.gz skyhanni-6b3e2d7b0cf478deb2d8f5876a402c01508a5d43.tar.bz2 skyhanni-6b3e2d7b0cf478deb2d8f5876a402c01508a5d43.zip |
Backend: Mobdetection First Seen Event (#2096)
Diffstat (limited to 'src/main/java/at')
3 files changed, 33 insertions, 2 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/mob/MobData.kt b/src/main/java/at/hannibal2/skyhanni/data/mob/MobData.kt index 4eb79d6de..f955384c5 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/mob/MobData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/mob/MobData.kt @@ -28,6 +28,8 @@ object MobData { val entityToMob = mutableMapOf<EntityLivingBase, Mob>() + internal val notSeenMobs = MobSet() + internal val currentEntityLiving = mutableSetOf<EntityLivingBase>() internal val previousEntityLiving = mutableSetOf<EntityLivingBase>() @@ -91,12 +93,19 @@ object MobData { fun onMobEventSpawn(event: MobEvent.Spawn) { entityToMob.putAll(event.mob.makeEntityToMobAssociation()) currentMobs.add(event.mob) + notSeenMobs.add(event.mob) } @SubscribeEvent fun onMobEventDeSpawn(event: MobEvent.DeSpawn) { event.mob.fullEntityList().forEach { entityToMob.remove(it) } currentMobs.remove(event.mob) + notSeenMobs.remove(event.mob) + } + + @SubscribeEvent + fun onMobFirstSeen(event: MobEvent.FirstSeen) { + notSeenMobs.remove(event.mob) } @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/data/mob/MobDetection.kt b/src/main/java/at/hannibal2/skyhanni/data/mob/MobDetection.kt index 82aec2fc6..b7cc4dfaa 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/mob/MobDetection.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/mob/MobDetection.kt @@ -35,7 +35,6 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.concurrent.ConcurrentLinkedQueue import java.util.concurrent.atomic.AtomicBoolean - @SkyHanniModule object MobDetection { @@ -72,7 +71,6 @@ object MobDetection { shouldClear.set(false) } if (!LorenzUtils.inSkyBlock) return - if (event.isMod(2)) return makeEntityReferenceUpdate() @@ -95,6 +93,8 @@ object MobDetection { (MobData.currentEntityLiving - MobData.previousEntityLiving).forEach { addRetry(it) } // Spawn (MobData.previousEntityLiving - MobData.currentEntityLiving).forEach { entityDeSpawn(it) } // Despawn + MobData.notSeenMobs.removeIf(::canBeSeen) + if (forceReset) { mobDetectionReset() // Ensure that all mobs are cleared 100% } @@ -120,6 +120,19 @@ object MobDetection { /** @return always true */ private fun mobDetectionError(string: String) = MobData.logger.log(string).let { true } + private fun canBeSeen(mob: Mob): Boolean { + val isVisible = !mob.isInvisible() && mob.canBeSeen() + if (isVisible) when (mob.mobType) { + Mob.Type.PLAYER -> MobEvent.FirstSeen.Player(mob) + Mob.Type.SUMMON -> MobEvent.FirstSeen.Summon(mob) + Mob.Type.SPECIAL -> MobEvent.FirstSeen.Special(mob) + Mob.Type.PROJECTILE -> MobEvent.FirstSeen.Projectile(mob) + Mob.Type.DISPLAY_NPC -> MobEvent.FirstSeen.DisplayNPC(mob) + Mob.Type.BASIC, Mob.Type.DUNGEON, Mob.Type.BOSS, Mob.Type.SLAYER -> MobEvent.FirstSeen.SkyblockMob(mob) + } + return isVisible + } + /**@return a false means that it should try again (later)*/ private fun entitySpawn(entity: EntityLivingBase, roughType: Mob.Type): Boolean { when (roughType) { diff --git a/src/main/java/at/hannibal2/skyhanni/events/MobEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/MobEvent.kt index 34725c546..07990ff22 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/MobEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/MobEvent.kt @@ -20,4 +20,13 @@ open class MobEvent(val mob: Mob) : LorenzEvent() { class Special(mob: Mob) : DeSpawn(mob) class Projectile(mob: Mob) : DeSpawn(mob) } + + open class FirstSeen(mob: Mob) : MobEvent(mob) { + class SkyblockMob(mob: Mob) : FirstSeen(mob) + class Summon(mob: Mob) : FirstSeen(mob) + class Player(mob: Mob) : FirstSeen(mob) + class DisplayNPC(mob: Mob) : FirstSeen(mob) + class Special(mob: Mob) : FirstSeen(mob) + class Projectile(mob: Mob) : FirstSeen(mob) + } } |