From 68abc8ade546de62aee76e0b786993fc59fbc3cc Mon Sep 17 00:00:00 2001 From: Walker Selby Date: Sat, 21 Oct 2023 07:31:19 +0100 Subject: Internal Change: Misc Refactoring (#551) Internal Change: Misc Refactoring #551 --- .../skyhanni/features/mobs/AreaMiniBossFeatures.kt | 121 --------------------- .../features/mobs/AshfangMinisNametagHider.kt | 28 ----- .../skyhanni/features/mobs/MobHighlight.kt | 99 ----------------- .../skyhanni/features/mobs/SpawnTimers.kt | 98 ----------------- 4 files changed, 346 deletions(-) delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/mobs/AreaMiniBossFeatures.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/mobs/AshfangMinisNametagHider.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/mobs/MobHighlight.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/mobs/SpawnTimers.kt (limited to 'src/main/java/at/hannibal2/skyhanni/features/mobs') diff --git a/src/main/java/at/hannibal2/skyhanni/features/mobs/AreaMiniBossFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/mobs/AreaMiniBossFeatures.kt deleted file mode 100644 index d603d97d6..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/mobs/AreaMiniBossFeatures.kt +++ /dev/null @@ -1,121 +0,0 @@ -package at.hannibal2.skyhanni.features.mobs - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.EntityMaxHealthUpdateEvent -import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent -import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent -import at.hannibal2.skyhanni.events.withAlpha -import at.hannibal2.skyhanni.mixins.hooks.RenderLivingEntityHelper -import at.hannibal2.skyhanni.utils.EntityUtils.hasMaxHealth -import at.hannibal2.skyhanni.utils.LocationUtils -import at.hannibal2.skyhanni.utils.LorenzColor -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzVec -import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText -import at.hannibal2.skyhanni.utils.TimeUtils -import net.minecraft.entity.EntityLiving -import net.minecraft.entity.monster.EntityBlaze -import net.minecraft.entity.monster.EntityEnderman -import net.minecraft.entity.monster.EntityZombie -import net.minecraft.entity.passive.EntityWolf -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -class AreaMiniBossFeatures { - private val config get() = SkyHanniMod.feature.combat.mobs - private var lastTime = 0L - private var miniBossType: AreaMiniBossType? = null - private var respawnCooldown = 11_000L - - @SubscribeEvent - fun onEntityHealthUpdate(event: EntityMaxHealthUpdateEvent) { - if (!LorenzUtils.inSkyBlock) return - - val entity = event.entity - val maxHealth = event.maxHealth - for (bossType in AreaMiniBossType.entries) { - if (!bossType.clazz.isInstance(entity)) continue - if (!entity.hasMaxHealth(bossType.health, false, maxHealth)) continue - - miniBossType = bossType - val time = System.currentTimeMillis() - val diff = time - lastTime - if (diff in 5_000..20_000) { - respawnCooldown = diff - } - lastTime = time - - if (config.areaBossHighlight) { - val color = bossType.color.toColor().withAlpha(bossType.colorOpacity) - RenderLivingEntityHelper.setEntityColor(entity, color) - { config.areaBossHighlight } - RenderLivingEntityHelper.setNoHurtTime(entity) { config.areaBossHighlight } - } - - // TODO add sound - } - } - - @SubscribeEvent - fun onRenderWorld(event: LorenzRenderWorldEvent) { - if (!LorenzUtils.inSkyBlock) return - if (!config.areaBossRespawnTimer) return - - miniBossType?.apply { - val time = getTime() - val playerLocation = LocationUtils.playerLocation() - spawnLocations.filter { it.distance(playerLocation) < 15 } - .forEach { event.drawDynamicText(it, time, 1.2, ignoreBlocks = false) } - } - } - - private fun AreaMiniBossType.getTime(): String { - val duration = System.currentTimeMillis() - lastTime - val estimatedTime = respawnCooldown - duration % respawnCooldown - val format = TimeUtils.formatDuration(estimatedTime, showMilliSeconds = true) - return color.getChatColor() + format - } - - @SubscribeEvent - fun onWorldChange(event: LorenzWorldChangeEvent) { - miniBossType = null - } - - enum class AreaMiniBossType( - val clazz: Class, - val health: Int, - val color: LorenzColor, - val colorOpacity: Int, - vararg val spawnLocations: LorenzVec - ) { - GOLDEN_GHOUL( - EntityZombie::class.java, 45_000, LorenzColor.YELLOW, 127, - LorenzVec(-99.7, 39.0, -86.4), - LorenzVec(-128.5, 42.0, -138.5), - ), - OLD_WOLF( - EntityWolf::class.java, 15_000, LorenzColor.GOLD, 60, - LorenzVec(-248.0, 123.0, 54.0), - LorenzVec(-256.7, 105.0, 75.7), - LorenzVec(-268.5, 90.0, 97.7), - LorenzVec(-258.1, 94.0, 75.5), - LorenzVec(-225.7, 92.0, 127.5), - ), - VOIDLING_EXTREMIST( - EntityEnderman::class.java, 8_000_000, LorenzColor.LIGHT_PURPLE, 127, - LorenzVec(-591.1, 10.0, -304.0), - LorenzVec(-544.8, 21.0, -301.1), - LorenzVec(-593.5, 26.0, -328.7), - LorenzVec(-565.0, 41.0, -307.1), - LorenzVec(-573.2, 51.0, -353.4), - ), - MILLENIA_AGED_BLAZE( - EntityBlaze::class.java, 30_000_000, LorenzColor.DARK_RED, 60, - LorenzVec(-292.5, 97.0, -999.7), - LorenzVec(-232.3, 77.0, -951.1), - LorenzVec(-304.1, 73.0, -952.9), - LorenzVec(-281.6, 82.0, -1010.7), - LorenzVec(-342.8, 86.0, -1035.2), - ), - ; - } -} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/mobs/AshfangMinisNametagHider.kt b/src/main/java/at/hannibal2/skyhanni/features/mobs/AshfangMinisNametagHider.kt deleted file mode 100644 index 87d4e5a13..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/mobs/AshfangMinisNametagHider.kt +++ /dev/null @@ -1,28 +0,0 @@ -package at.hannibal2.skyhanni.features.mobs - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.utils.LorenzUtils -import net.minecraft.entity.EntityLivingBase -import net.minecraft.entity.item.EntityArmorStand -import net.minecraftforge.client.event.RenderLivingEvent -import net.minecraftforge.fml.common.eventhandler.EventPriority -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -class AshfangMinisNametagHider { - private val config get() = SkyHanniMod.feature.combat.mobs - - @SubscribeEvent(priority = EventPriority.HIGH) - fun onRenderLiving(event: RenderLivingEvent.Specials.Pre) { - if (!LorenzUtils.inSkyBlock) return - if (!config.hideNameTagArachneMinis) return - - val entity = event.entity - if (entity !is EntityArmorStand) return - if (!entity.hasCustomName()) return - - val name = entity.name - if (name.contains("§cArachne's Brood§r")) { - event.isCanceled = true - } - } -} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/mobs/MobHighlight.kt b/src/main/java/at/hannibal2/skyhanni/features/mobs/MobHighlight.kt deleted file mode 100644 index b0b7fc3ca..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/mobs/MobHighlight.kt +++ /dev/null @@ -1,99 +0,0 @@ -package at.hannibal2.skyhanni.features.mobs - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.EntityHealthUpdateEvent -import at.hannibal2.skyhanni.events.EntityMaxHealthUpdateEvent -import at.hannibal2.skyhanni.events.withAlpha -import at.hannibal2.skyhanni.mixins.hooks.RenderLivingEntityHelper -import at.hannibal2.skyhanni.utils.EntityUtils.hasNameTagWith -import at.hannibal2.skyhanni.utils.LorenzColor -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.baseMaxHealth -import net.minecraft.client.entity.EntityOtherPlayerMP -import net.minecraft.entity.EntityLivingBase -import net.minecraft.entity.monster.EntityCaveSpider -import net.minecraft.entity.monster.EntityEnderman -import net.minecraft.entity.monster.EntitySpider -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -class MobHighlight { - private val config get() = SkyHanniMod.feature.combat.mobs - - @SubscribeEvent - fun onEntityHealthUpdate(event: EntityHealthUpdateEvent) { - if (!LorenzUtils.inSkyBlock) return - - val entity = event.entity - val baseMaxHealth = entity.baseMaxHealth - if (config.corruptedMobHighlight && event.health == baseMaxHealth * 3) { - RenderLivingEntityHelper.setEntityColor(entity, LorenzColor.DARK_PURPLE.toColor().withAlpha(127)) - { config.corruptedMobHighlight } - RenderLivingEntityHelper.setNoHurtTime(entity) { config.corruptedMobHighlight } - } - } - - @SubscribeEvent - fun onEntityHealthUpdate(event: EntityMaxHealthUpdateEvent) { - if (!LorenzUtils.inSkyBlock) return - - val entity = event.entity - val maxHealth = event.maxHealth - if (config.arachneKeeperHighlight && (maxHealth == 3_000 || maxHealth == 12_000) && entity is EntityCaveSpider) { - RenderLivingEntityHelper.setEntityColor(entity, LorenzColor.DARK_BLUE.toColor().withAlpha(127)) - { config.arachneKeeperHighlight } - RenderLivingEntityHelper.setNoHurtTime(entity) { config.arachneKeeperHighlight } - } - - if (config.corleoneHighlighter && maxHealth == 1_000_000 && entity is EntityOtherPlayerMP && entity.name == "Team Treasurite") { - RenderLivingEntityHelper.setEntityColor(entity, LorenzColor.DARK_PURPLE.toColor().withAlpha(127)) - { config.corleoneHighlighter } - RenderLivingEntityHelper.setNoHurtTime(entity) { config.corleoneHighlighter } - } - - if (config.zealotBruiserHighlighter) { - val isZealot = maxHealth == 13_000 || maxHealth == 13_000 * 4 // runic - val isBruiser = maxHealth == 65_000 || maxHealth == 65_000 * 4 // runic - if ((isZealot || isBruiser) && entity is EntityEnderman) { - RenderLivingEntityHelper.setEntityColor(entity, LorenzColor.DARK_AQUA.toColor().withAlpha(127)) - { config.zealotBruiserHighlighter } - RenderLivingEntityHelper.setNoHurtTime(entity) { config.zealotBruiserHighlighter } - } - } - - if (config.specialZealotHighlighter && maxHealth == 2_000 && entity is EntityEnderman) { - RenderLivingEntityHelper.setEntityColor(entity, LorenzColor.DARK_RED.toColor().withAlpha(50)) - { config.specialZealotHighlighter } - RenderLivingEntityHelper.setNoHurtTime(entity) { config.specialZealotHighlighter } - } - - if (config.arachneBossHighlighter && entity is EntitySpider) { - checkArachne(entity) - } - } - - private fun checkArachne(entity: EntitySpider) { - if (!entity.hasNameTagWith(1, "[§7Lv300§8] §cArachne") && - !entity.hasNameTagWith(1, "[§7Lv300§8] §lArachne") && - !entity.hasNameTagWith(1, "[§7Lv500§8] §cArachne") && - !entity.hasNameTagWith(1, "[§7Lv500§8] §lArachne") - ) return - - if (entity is EntityCaveSpider) { - markArachneMinis(entity) - } else if (entity.baseMaxHealth == 20_000 || entity.baseMaxHealth == 100_000) { - markArachne(entity) - } - } - - private fun markArachneMinis(entity: EntityLivingBase) { - RenderLivingEntityHelper.setEntityColor(entity, LorenzColor.GOLD.toColor().withAlpha(50)) - { config.arachneBossHighlighter } - RenderLivingEntityHelper.setNoHurtTime(entity) { config.arachneBossHighlighter } - } - - private fun markArachne(entity: EntityLivingBase) { - RenderLivingEntityHelper.setEntityColor(entity, LorenzColor.RED.toColor().withAlpha(50)) - { config.arachneBossHighlighter } - RenderLivingEntityHelper.setNoHurtTime(entity) { config.arachneBossHighlighter } - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/features/mobs/SpawnTimers.kt b/src/main/java/at/hannibal2/skyhanni/features/mobs/SpawnTimers.kt deleted file mode 100644 index 24a720508..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/mobs/SpawnTimers.kt +++ /dev/null @@ -1,98 +0,0 @@ -package at.hannibal2.skyhanni.features.mobs - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.data.IslandType -import at.hannibal2.skyhanni.events.LorenzChatEvent -import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent -import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent -import at.hannibal2.skyhanni.events.PacketEvent -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland -import at.hannibal2.skyhanni.utils.LorenzVec -import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText -import at.hannibal2.skyhanni.utils.SimpleTimeMark -import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import at.hannibal2.skyhanni.utils.TimeUtils.format -import at.hannibal2.skyhanni.utils.toLorenzVec -import net.minecraft.network.play.server.S2APacketParticles -import net.minecraft.util.EnumParticleTypes -import net.minecraftforge.fml.common.eventhandler.EventPriority -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import kotlin.time.Duration.Companion.seconds - -class SpawnTimers { - private val config get() = SkyHanniMod.feature.combat.mobs - - private val arachneAltarLocation = LorenzVec(-283f, 51f, -179f) - private var arachneSpawnTime = SimpleTimeMark.farPast() - private val arachneFragmentMessage = "^☄ [a-z0-9_]{2,22} placed an arachne's calling! something is awakening! \\(4/4\\)\$".toRegex() - private val arachneCrystalMessage = "^☄ [a-z0-9_]{2,22} placed an arachne crystal! something is awakening!$".toRegex() - private var saveNextTickParticles = false - private var particleCounter = 0 - private var tickTime: Long = 0 - private var searchTime: Long = 0 - - @SubscribeEvent - fun onWorldChange(event: LorenzWorldChangeEvent) { - searchTime = 0 - tickTime = 0 - particleCounter = 0 - saveNextTickParticles = false - arachneSpawnTime = SimpleTimeMark.farPast() - } - - @SubscribeEvent - fun onRenderWorld(event: LorenzRenderWorldEvent) { - if (!isEnabled()) return - if (arachneSpawnTime.isInPast()) return - val countDown = arachneSpawnTime.timeUntil() - - val format = countDown.format(showMilliSeconds = true) - event.drawDynamicText(arachneAltarLocation, "§b$format", 1.5) - } - - @SubscribeEvent - fun onChatReceived(event: LorenzChatEvent) { - if (!isEnabled()) return - val message = event.message.removeColor().lowercase() - - if (arachneFragmentMessage.matches(message) || arachneCrystalMessage.matches(message)) { - if (arachneCrystalMessage.matches(message)) { - saveNextTickParticles = true - searchTime = System.currentTimeMillis() - particleCounter = 0 - tickTime = 0L - } else arachneSpawnTime = SimpleTimeMark.now() + 19.seconds - } - } - - // All this to detect "quickspawn" vs regular arachne spawn - @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true) - fun onChatPacket(event: PacketEvent.ReceiveEvent) { - if (!saveNextTickParticles) return - if (System.currentTimeMillis() <= searchTime + 3000) return - - if (particleCounter == 0 && tickTime == 0L) tickTime = System.currentTimeMillis() - - if (System.currentTimeMillis() > tickTime + 60) { - arachneSpawnTime = if (particleCounter <= 20) { - SimpleTimeMark.now() + 21.seconds - } else { - SimpleTimeMark.now() + 37.seconds - } - saveNextTickParticles = false - return - } - - val packet = event.packet - if (packet is S2APacketParticles) { - val location = packet.toLorenzVec().round(2) - if (arachneAltarLocation.distance(location) > 30) return - if (packet.particleType == EnumParticleTypes.REDSTONE && packet.particleSpeed == 1.0f) { - particleCounter += 1 - } - } - } - - fun isEnabled() = IslandType.SPIDER_DEN.isInIsland() && LorenzUtils.skyBlockArea == "Arachne's Sanctuary" && config.showArachneSpawnTimer -} \ No newline at end of file -- cgit