diff options
author | Lorenz <lo.scherf@gmail.com> | 2022-08-26 21:05:20 +0200 |
---|---|---|
committer | Lorenz <lo.scherf@gmail.com> | 2022-08-26 21:05:20 +0200 |
commit | ddbf374e9302ae47d43aa981c0caf33a264b2496 (patch) | |
tree | 1e5f4dc18170060d204164373f2261b14f0f8e8d /src/main/java/at/hannibal2/skyhanni/features/SummoningMobManager.kt | |
parent | d3e2991644880b2766d9d50b7419466ece9027c1 (diff) | |
download | skyhanni-ddbf374e9302ae47d43aa981c0caf33a264b2496.tar.gz skyhanni-ddbf374e9302ae47d43aa981c0caf33a264b2496.tar.bz2 skyhanni-ddbf374e9302ae47d43aa981c0caf33a264b2496.zip |
added summoning mob features
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/SummoningMobManager.kt')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/SummoningMobManager.kt | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/SummoningMobManager.kt b/src/main/java/at/hannibal2/skyhanni/features/SummoningMobManager.kt new file mode 100644 index 000000000..5dca40d1b --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/SummoningMobManager.kt @@ -0,0 +1,184 @@ +package at.hannibal2.skyhanni.features + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.utils.LocationUtils +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.baseMaxHealth +import at.hannibal2.skyhanni.utils.NumberUtil +import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings +import at.hannibal2.skyhanni.utils.getLorenzVec +import net.minecraft.client.Minecraft +import net.minecraft.entity.EntityLiving +import net.minecraft.entity.EntityLivingBase +import net.minecraft.entity.item.EntityArmorStand +import net.minecraftforge.client.event.RenderGameOverlayEvent +import net.minecraftforge.client.event.RenderLivingEvent +import net.minecraftforge.event.world.WorldEvent +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent +import java.util.regex.Pattern + +class SummoningMobManager { + + private val summoningMobs = mutableMapOf<EntityLiving, SummoningMob>() + private val summoningMobNametags = mutableListOf<EntityArmorStand>() + private var summoningsSpawned = 0 + private var searchArmorStands = false + private var searchMobs = false + + //§aYou have spawned your Tank Zombie §r§asoul! §r§d(249 Mana) + private val spawnPatter = Pattern.compile("§aYou have spawned your (.+) §r§asoul! §r§d\\((\\d+) Mana\\)") + private val despawnPatter = Pattern.compile("§cYou have despawned your (monster|monsters)!") + + //§a§ohannibal2's Tank Zombie§r §a160k§c❤ + private val healthPattern = Pattern.compile("§a§o(.+)'s (.+)§r §[ae]([\\dkm]+)§c❤") + + @SubscribeEvent + fun onChatMessage(event: LorenzChatEvent) { + if (!LorenzUtils.isOnHypixel) return + + val message = event.message + val matcher = spawnPatter.matcher(message) + if (matcher.matches()) { + if (SkyHanniMod.feature.abilities.summoningMobDisplay) { + event.blockedReason = "summoning_soul" + } + summoningsSpawned++ + searchArmorStands = true + searchMobs = true + } + + if (despawnPatter.matcher(message).matches() || message.startsWith("§c ☠ §r§7You ")) { + despawned() + if (SkyHanniMod.feature.abilities.summoningMobDisplay && !message.contains("☠")) { + event.blockedReason = "summoning_soul" + } + } + } + + var tick = 0 + + @SubscribeEvent + fun onTick(event: TickEvent.ClientTickEvent) { + if (!isEnabled()) return + + if (SkyHanniMod.feature.abilities.summoningMobDisplay) { + if (tick++ % 20 == 0) { + updateData() + } + } + + if (searchArmorStands) { + Minecraft.getMinecraft().theWorld.loadedEntityList + .filter { it is EntityArmorStand && it !in summoningMobNametags } + .forEach { + val name = it.displayName.unformattedText + val matcher = healthPattern.matcher(name) + if (matcher.matches()) { + val playerName = Minecraft.getMinecraft().thePlayer.name + if (name.contains(playerName)) { + summoningMobNametags.add(it as EntityArmorStand) + if (summoningMobNametags.size == summoningsSpawned) { + searchArmorStands = false + } + } + } + } + } + if (searchMobs) { + + val playerLocation = LocationUtils.playerLocation() + Minecraft.getMinecraft().theWorld.loadedEntityList + .filter { + it is EntityLiving && it !in summoningMobs.keys && it.getLorenzVec().distance(playerLocation) < 3 + } + .forEach { + summoningMobs[it as EntityLiving] = SummoningMob(System.currentTimeMillis(), name = "Mob") + updateData() + if (summoningMobs.size == summoningsSpawned) { + searchMobs = false + } + } + } + } + + private fun updateData() { + if (summoningMobs.isEmpty()) return + + for (entry in HashMap(summoningMobs)) { + val entityLiving = entry.key + val summoningMob = entry.value + + val currentHealth = entityLiving.health.toInt() + val name = summoningMob.name + if (currentHealth == 0) { + summoningMobs.remove(entityLiving) + LorenzUtils.chat("§e[SkyHanni] your Summoning Mob just §cdied!") + continue + } + + val maxHealth = entityLiving.baseMaxHealth.toInt() + val color = NumberUtil.percentageColor(currentHealth, maxHealth).getChatColor() + + val currentFormat = NumberUtil.format(currentHealth) + val maxFormat = NumberUtil.format(maxHealth) + summoningMob.lastDisplayName = "§a$name $color$currentFormat/$maxFormat" + } + } + + @SubscribeEvent + fun renderOverlay(event: RenderGameOverlayEvent.Post) { + if (!SkyHanniMod.feature.abilities.summoningMobDisplay) return + if (summoningMobs.isEmpty()) return + + val list = mutableListOf<String>() + list.add("Summoning mobs: " + summoningMobs.size) + var id = 1 + for (mob in summoningMobs) { + val name = mob.value.lastDisplayName + list.add("#$id $name") + id++ + } + + SkyHanniMod.feature.abilities.summoningMobDisplayPos.renderStrings(list) + } + + @SubscribeEvent + fun renderOverlay(event: WorldEvent.Load) { + despawned() + } + + @SubscribeEvent(priority = EventPriority.HIGH) + fun onRenderLiving(event: RenderLivingEvent.Specials.Pre<EntityLivingBase>) { + if (!LorenzUtils.inSkyblock) return + if (!SkyHanniMod.feature.abilities.summoningMobHideNametag) return + + val entity = event.entity + if (entity !is EntityArmorStand) return + if (!entity.hasCustomName()) return + if (entity.isDead) return + + event.isCanceled = entity in summoningMobNametags + } + + private fun despawned() { + summoningMobs.clear() + summoningMobNametags.clear() + summoningsSpawned = 0 + searchArmorStands = false + searchMobs = false + println("despawning") + } + + private fun isEnabled(): Boolean { + return LorenzUtils.inSkyblock && (SkyHanniMod.feature.abilities.summoningMobDisplay || SkyHanniMod.feature.abilities.summoningMobHideNametag) + } + + class SummoningMob( + val spawnTime: Long, + var name: String = "", + var lastDisplayName: String = "", + ) +}
\ No newline at end of file |