diff options
author | Lorenz <lo.scherf@gmail.com> | 2022-08-17 04:37:44 +0200 |
---|---|---|
committer | Lorenz <lo.scherf@gmail.com> | 2022-08-17 04:37:44 +0200 |
commit | d422182e1e11b9d2413676682bf8b9f8a68dc1af (patch) | |
tree | 196a4d3d1190fdcf6d37de660e4a8f4ad839a325 /src/main/java/at/hannibal2 | |
parent | 0fa33ad856ce250553fc9e1adf5fc860b2e06378 (diff) | |
download | skyhanni-d422182e1e11b9d2413676682bf8b9f8a68dc1af.tar.gz skyhanni-d422182e1e11b9d2413676682bf8b9f8a68dc1af.tar.bz2 skyhanni-d422182e1e11b9d2413676682bf8b9f8a68dc1af.zip |
created a method for the custom stuff in damage indicator
Diffstat (limited to 'src/main/java/at/hannibal2')
3 files changed, 236 insertions, 216 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/SummoningSoulsName.kt b/src/main/java/at/hannibal2/skyhanni/features/SummoningSoulsName.kt index 478cdc100..0ca601a54 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/SummoningSoulsName.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/SummoningSoulsName.kt @@ -1,7 +1,7 @@ package at.hannibal2.skyhanni.features import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.features.damageindicator.hasNameTagWith +import at.hannibal2.skyhanni.features.damageindicator.getNameTagWith import at.hannibal2.skyhanni.test.GriffinJavaUtils import at.hannibal2.skyhanni.utils.ItemUtils.getSkullTexture import at.hannibal2.skyhanni.utils.LocationUtils @@ -15,7 +15,6 @@ import net.minecraft.entity.item.EntityArmorStand import net.minecraftforge.client.event.RenderWorldLastEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent -import java.util.concurrent.atomic.AtomicReference class SummoningSoulsName { @@ -79,18 +78,12 @@ class SummoningSoulsName { } for (entity in world.loadedEntityList) { - if (entity is EntityLiving) { - val boo = AtomicReference<String>() - if (entity.hasNameTagWith(2, "§c❤", consumer = { - if (!it.name.contains("§e0")) { - boo.set(it.name) - } - })) { - val name = boo.get() - if (name != null) { + val consumer = entity.getNameTagWith(2, "§c❤") + if (consumer != null) { + if (!consumer.name.contains("§e0")) { mobsLastLocation[entity] = entity.getLorenzVec() - mobsName[entity] = name + mobsName[entity] = consumer.name } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/damageindicator/BossFinder.kt b/src/main/java/at/hannibal2/skyhanni/features/damageindicator/BossFinder.kt index e030d8904..421394d7e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/damageindicator/BossFinder.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/damageindicator/BossFinder.kt @@ -538,21 +538,31 @@ class BossFinder { } } +//TODO move into utils method fun EntityLiving.hasNameTagWith( y: Int, contains: String, debugRightEntity: Boolean = false, - consumer: (EntityArmorStand) -> Unit = {}, inaccuracy: Double = 1.6, debugWrongEntity: Boolean = false, ): Boolean { + return getNameTagWith(y, contains, debugRightEntity, inaccuracy, debugWrongEntity) != null +} + +fun EntityLiving.getNameTagWith( + y: Int, + contains: String, + debugRightEntity: Boolean = false, + inaccuracy: Double = 1.6, + debugWrongEntity: Boolean = false, +): EntityArmorStand? { val center = getLorenzVec().add(0, y, 0) val a = center.add(-inaccuracy, -inaccuracy - 3, -inaccuracy).toBlocPos() val b = center.add(inaccuracy, inaccuracy + 3, inaccuracy).toBlocPos() val alignedBB = AxisAlignedBB(a, b) val clazz = EntityArmorStand::class.java val found = worldObj.getEntitiesWithinAABB(clazz, alignedBB) - return found.any { + return found.find { val result = it.name.contains(contains) if (debugWrongEntity && !result) { println("wrong entity in aabb: '" + it.name + "'") @@ -562,7 +572,6 @@ fun EntityLiving.hasNameTagWith( println("nametag: " + it.getLorenzVec().printWithAccuracy(2)) println("accuracy: " + it.getLorenzVec().subtract(center).printWithAccuracy(3)) } - if (result) consumer(it) result } }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/damageindicator/DamageIndicatorManager.kt b/src/main/java/at/hannibal2/skyhanni/features/damageindicator/DamageIndicatorManager.kt index ddfaed4cf..6d15289af 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/damageindicator/DamageIndicatorManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/damageindicator/DamageIndicatorManager.kt @@ -198,11 +198,9 @@ class DamageIndicatorManager { checkFinalBoss(entityData.finalDungeonBoss, entity.entityId) } - val biggestHealth = getMaxHealthFor(entity) - val health = entity.health.toInt() val maxHealth: Int - + val biggestHealth = getMaxHealthFor(entity) if (biggestHealth == 0) { val currentMaxHealth = entity.baseMaxHealth.toInt() maxHealth = max(currentMaxHealth, health) @@ -211,204 +209,13 @@ class DamageIndicatorManager { maxHealth = biggestHealth } - var calcHealth = health - var calcMaxHealth = maxHealth entityData.namePrefix = "" entityData.nameSuffix = "" - var customHealthText = "" - - //TODO implement - if (!entityData.dead) { - - if (entityData.bossType == BossType.DUNGEON_F4_THORN) { - if (DungeonData.isOneOf("F4")) { - calcHealth = when (health) { - 300_000, 600_000 -> 4 - 222_000, 444_000 -> 3 - 144_000, 288_000 -> 2 - 66_000, 132_000 -> 1 - 0 -> 0 - else -> { - LorenzUtils.error("Unexpected health of thorn in f4! (${ - LorenzUtils.formatDouble(LorenzUtils.formatDouble( - health.toDouble()).toDouble()) - })") - return - } - } - calcMaxHealth = 4 - } else if (DungeonData.isOneOf("M4")) { - calcHealth = when (health) { - //TODO test all non derpy values! - 1_800_000 / 2, 1_800_000 -> 6 - 1_494_000 / 2, 1_494_000 -> 5 - 1_188_000 / 2, 1_188_000 -> 4 - 882_000 / 2, 882_000 -> 3 - 576_000 / 2, 576_000 -> 2 - 270_000 / 2, 270_000 -> 1 - 0 -> 0 - else -> { - LorenzTest.enabled = true - LorenzTest.text = "thorn has ${LorenzUtils.formatDouble(health.toDouble())} hp!" - LorenzUtils.error("Unexpected health of thorn in m4! (${ - LorenzUtils.formatDouble(LorenzUtils.formatDouble( - health.toDouble()).toDouble()) - })") - return - } - } - calcMaxHealth = 4 - } - } - - if (entityData.bossType == BossType.SLAYER_ENDERMAN_1 || - entityData.bossType == BossType.SLAYER_ENDERMAN_2 || - entityData.bossType == BossType.SLAYER_ENDERMAN_3 || - entityData.bossType == BossType.SLAYER_ENDERMAN_4 - ) { - var statePrefix = "" - //Hides the damage indicator when in hit phase or in laser phase - if (entity is EntityEnderman) { - entity.hasNameTagWith(3, " Hit", consumer = { - val name = it.name.removeColor() - - val maxHits = when (entityData.bossType) { - BossType.SLAYER_ENDERMAN_1 -> 15 - BossType.SLAYER_ENDERMAN_2 -> 30 - BossType.SLAYER_ENDERMAN_3 -> 60 - BossType.SLAYER_ENDERMAN_4 -> 100 - else -> 100 - } - val hits = name.between("Seraph ", " Hit").toInt() - val color = percentageColor(hits, maxHits) - - customHealthText = color.getChatColor() + "$hits Hits" - }) - if (entity.ridingEntity != null) { - val ticksAlive = entity.ridingEntity.ticksExisted.toLong() - //TODO more tests, more exact values, better logic? idk make this working perfectly pls -// val remainingTicks = 8 * 20 - ticksAlive - val remainingTicks = (8.9 * 20).toLong() - ticksAlive - customHealthText = formatDelay(remainingTicks * 50) - } - } - - when (entityData.bossType) { - BossType.SLAYER_ENDERMAN_4 -> { - val step = maxHealth / 6 - calcMaxHealth = step - if (health > step * 5) { - calcHealth -= step * 5 - statePrefix = "§c1/6 " - } else if (health > step * 4) { - calcHealth -= step * 4 - statePrefix = "§e2/6 " - } else if (health > step * 3) { - calcHealth -= step * 3 - statePrefix = "§e3/6 " - } else if (health > step * 2) { - calcHealth -= step * 2 - statePrefix = "§e4/6 " - } else if (health > step) { - calcHealth -= step - statePrefix = "§e5/6 " - } else { - calcHealth = health - statePrefix = "§a6/6 " - } - } - BossType.SLAYER_ENDERMAN_1, - BossType.SLAYER_ENDERMAN_2, - BossType.SLAYER_ENDERMAN_3, - -> { - val step = maxHealth / 3 - - calcMaxHealth = step - if (health > step * 2) { - calcHealth -= step * 2 - statePrefix = "§c1/3 " - } else if (health > step) { - calcHealth -= step - statePrefix = "§e2/3 " - } else { - calcHealth = health - statePrefix = "§a3/3 " - } - - } - else -> {} - } - entityData.namePrefix = statePrefix + entityData.namePrefix - } - if (entityData.bossType == BossType.NETHER_MAGMA_BOSS) { - if (entity is EntityMagmaCube) { - val slimeSize = entity.slimeSize - entityData.namePrefix = when (slimeSize) { - 24 -> "§c1/6" - 22 -> "§e2/6" - 20 -> "§e3/6" - 18 -> "§e4/6" - 16 -> "§e5/6" - else -> { - calcMaxHealth = 10_000_000 - "§a6/6" - } - } + " §f" - - //hide while in the middle - val position = entity.getLorenzVec() - entityData.healthLineHidden = position.x == -368.0 && position.z == -804.0 - - for (line in ScoreboardData.sidebarLinesRaw) { - if (line.contains("▎")) { - val color: String - if (line.startsWith("§7")) { - color = "§7" - } else if (line.startsWith("§e")) { - color = "§e" - } else if (line.startsWith("§6") || line.startsWith("§a") || line.startsWith("§c")) { - calcHealth = 0 - break - } else { - LorenzUtils.error("unknown magma boss health sidebar format!") - break - } - - val text = line.replace("\uD83C\uDF81" + color, "") - val max = 25.0 - val length = text.split("§e", "§7")[1].length - val missing = (health.toDouble() / max) * length - calcHealth = (health - missing).toInt() - } - } - } - } - if (entityData.bossType == BossType.SLAYER_ZOMBIE_5) { - if (entity is EntityZombie) { - entity.hasNameTagWith(3, "§fBoom!", consumer = { - val ticksAlive = entity.ticksExisted % (20 * 5) - val remainingTicks = (5 * 20).toLong() - ticksAlive - val format = formatDelay(remainingTicks * 50) - //TODO fix -// entityData.nameSuffix = " §lBOOM - $format" - entityData.nameSuffix = " §lBOOM!" - }) - } - } - if (entityData.bossType == BossType.SLAYER_WOLF_3 || - entityData.bossType == BossType.SLAYER_WOLF_4 - ) { - if (entity is EntityWolf) { - if (entity.hasNameTagWith(2, "§bCalling the pups!")) { - customHealthText = "Pups!" - } - } - } - } - - if (health == 0) { - customHealthText = "§cDead" + val customHealthText = if (health == 0) { entityData.dead = true + "§cDead" + } else { + getCustomHealth(entityData, health, entity, maxHealth) ?: return } if (data.containsKey(entity.uniqueID)) { @@ -419,13 +226,13 @@ class DamageIndicatorManager { } checkDamage(entityData, health, lastHealth, bossType) } - entityData.lastHealth = health + if (customHealthText.isNotEmpty()) { entityData.healthText = customHealthText } else { - val color = percentageColor(calcHealth, calcMaxHealth) - entityData.healthText = color.getChatColor() + NumberUtil.format(calcHealth) + val color = percentageColor(health, maxHealth) + entityData.healthText = color.getChatColor() + NumberUtil.format(health) } entityData.timeLastTick = System.currentTimeMillis() data[entity.uniqueID] = entityData @@ -435,6 +242,217 @@ class DamageIndicatorManager { } } + private fun getCustomHealth( + entityData: EntityData, + health: Int, + entity: EntityLivingBase, + maxHealth: Int, + ): String? { + if (entityData.bossType == BossType.DUNGEON_F4_THORN) { + val thornHealth: Int + val thornMaxHealth: Int + if (DungeonData.isOneOf("F4")) { + thornHealth = when (health) { + 300_000, 600_000 -> 4 + 222_000, 444_000 -> 3 + 144_000, 288_000 -> 2 + 66_000, 132_000 -> 1 + 0 -> 0 + else -> { + LorenzUtils.error("Unexpected health of thorn in f4! (${ + LorenzUtils.formatDouble(LorenzUtils.formatDouble( + health.toDouble()).toDouble()) + })") + return null + } + } + thornMaxHealth = 4 + } else if (DungeonData.isOneOf("M4")) { + thornHealth = when (health) { + //TODO test all non derpy values! + 1_800_000 / 2, 1_800_000 -> 6 + 1_494_000 / 2, 1_494_000 -> 5 + 1_188_000 / 2, 1_188_000 -> 4 + 882_000 / 2, 882_000 -> 3 + 576_000 / 2, 576_000 -> 2 + 270_000 / 2, 270_000 -> 1 + 0 -> 0 + else -> { + LorenzTest.enabled = true + LorenzTest.text = "thorn has ${LorenzUtils.formatDouble(health.toDouble())} hp!" + LorenzUtils.error("Unexpected health of thorn in m4! (${ + LorenzUtils.formatDouble(LorenzUtils.formatDouble( + health.toDouble()).toDouble()) + })") + return null + } + } + thornMaxHealth = 4 + } else { + LorenzUtils.error("Invalid thorn floor!") + return null + } + val color = percentageColor(thornHealth, thornMaxHealth) + return color.getChatColor() + thornHealth + "/" + thornMaxHealth + } + if (entityData.bossType == BossType.SLAYER_ENDERMAN_1 || + entityData.bossType == BossType.SLAYER_ENDERMAN_2 || + entityData.bossType == BossType.SLAYER_ENDERMAN_3 || + entityData.bossType == BossType.SLAYER_ENDERMAN_4 + ) { + + //Hides the damage indicator when in hit phase or in laser phase + if (entity is EntityEnderman) { + val armorStandHits = entity.getNameTagWith(3, " Hit") + if (armorStandHits != null) { + val name = armorStandHits.name.removeColor() + + val maxHits = when (entityData.bossType) { + BossType.SLAYER_ENDERMAN_1 -> 15 + BossType.SLAYER_ENDERMAN_2 -> 30 + BossType.SLAYER_ENDERMAN_3 -> 60 + BossType.SLAYER_ENDERMAN_4 -> 100 + else -> 100 + } + val hits = name.between("Seraph ", " Hit").toInt() + val color = percentageColor(hits, maxHits) + + return color.getChatColor() + "$hits Hits" + } + + if (entity.ridingEntity != null) { + val ticksAlive = entity.ridingEntity.ticksExisted.toLong() + //TODO more tests, more exact values, better logic? idk make this working perfectly pls + // val remainingTicks = 8 * 20 - ticksAlive + val remainingTicks = (8.9 * 20).toLong() - ticksAlive + return formatDelay(remainingTicks * 50) + } + } + + var calcHealth = health + val calcMaxHealth: Int + val statePrefix: String + when (entityData.bossType) { + BossType.SLAYER_ENDERMAN_1, + BossType.SLAYER_ENDERMAN_2, + BossType.SLAYER_ENDERMAN_3, + -> { + val step = maxHealth / 3 + calcMaxHealth = step + if (health > step * 2) { + calcHealth -= step * 2 + statePrefix = "§c1/3 " + } else if (health > step) { + calcHealth -= step + statePrefix = "§e2/3 " + } else { + calcHealth = health + statePrefix = "§a3/3 " + } + } + BossType.SLAYER_ENDERMAN_4 -> { + val step = maxHealth / 6 + calcMaxHealth = step + if (health > step * 5) { + calcHealth -= step * 5 + statePrefix = "§c1/6 " + } else if (health > step * 4) { + calcHealth -= step * 4 + statePrefix = "§e2/6 " + } else if (health > step * 3) { + calcHealth -= step * 3 + statePrefix = "§e3/6 " + } else if (health > step * 2) { + calcHealth -= step * 2 + statePrefix = "§e4/6 " + } else if (health > step) { + calcHealth -= step + statePrefix = "§e5/6 " + } else { + calcHealth = health + statePrefix = "§a6/6 " + } + } + else -> return null + } + entityData.namePrefix = statePrefix + entityData.namePrefix + val color = percentageColor(calcHealth, calcMaxHealth) + return color.getChatColor() + NumberUtil.format(calcHealth) + } + if (entityData.bossType == BossType.NETHER_MAGMA_BOSS) { + if (entity is EntityMagmaCube) { + val slimeSize = entity.slimeSize + entityData.namePrefix = when (slimeSize) { + 24 -> "§c1/6" + 22 -> "§e2/6" + 20 -> "§e3/6" + 18 -> "§e4/6" + 16 -> "§e5/6" + else -> { + val color = percentageColor(health, 10_000_000) + entityData.namePrefix = "§a6/6" + return color.getChatColor() + NumberUtil.format(health) + } + } + " §f" + + //hide while in the middle + val position = entity.getLorenzVec() + entityData.healthLineHidden = position.x == -368.0 && position.z == -804.0 + + var calcHealth = -1 + for (line in ScoreboardData.sidebarLinesRaw) { + if (line.contains("▎")) { + val color: String + if (line.startsWith("§7")) { + color = "§7" + } else if (line.startsWith("§e")) { + color = "§e" + } else if (line.startsWith("§6") || line.startsWith("§a") || line.startsWith("§c")) { + calcHealth = 0 + break + } else { + LorenzUtils.error("unknown magma boss health sidebar format!") + break + } + + val text = line.replace("\uD83C\uDF81" + color, "") + val max = 25.0 + val length = text.split("§e", "§7")[1].length + val missing = (health.toDouble() / max) * length + calcHealth = (health - missing).toInt() + } + } + if (calcHealth == -1) return null + + val color = percentageColor(calcHealth, maxHealth) + return color.getChatColor() + NumberUtil.format(calcHealth) + } + } + if (entityData.bossType == BossType.SLAYER_ZOMBIE_5) { + if (entity is EntityZombie) { + if (entity.hasNameTagWith(3, "§fBoom!")) { + //TODO fix +// val ticksAlive = entity.ticksExisted % (20 * 5) +// val remainingTicks = (5 * 20).toLong() - ticksAlive +// val format = formatDelay(remainingTicks * 50) +// entityData.nameSuffix = " §lBOOM - $format" + entityData.nameSuffix = " §lBOOM!" + } + } + } + if (entityData.bossType == BossType.SLAYER_WOLF_3 || + entityData.bossType == BossType.SLAYER_WOLF_4 + ) { + if (entity is EntityWolf) { + if (entity.hasNameTagWith(2, "§bCalling the pups!")) { + return "Pups!" + } + } + } + + return "" + } + private fun checkDamage(entityData: EntityData, health: Int, lastHealth: Int, bossType: BossType) { val damage = lastHealth - health val healing = health - lastHealth |