aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2
diff options
context:
space:
mode:
authorEmpa <42304516+ItsEmpa@users.noreply.github.com>2024-06-16 17:37:47 +0200
committerGitHub <noreply@github.com>2024-06-16 17:37:47 +0200
commitcb828a9248e6c28da7abaa16cfbb9d112076bd24 (patch)
treebbdee6a45d76ff90a81fe89fc0de65aaeb20853a /src/main/java/at/hannibal2
parent7d5208ee0c843ed2f9cc385608e3a1fab11beb21 (diff)
downloadskyhanni-cb828a9248e6c28da7abaa16cfbb9d112076bd24.tar.gz
skyhanni-cb828a9248e6c28da7abaa16cfbb9d112076bd24.tar.bz2
skyhanni-cb828a9248e6c28da7abaa16cfbb9d112076bd24.zip
Improvement: Summoning Mob Display Mob Detection (#2092)
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/combat/SummoningsConfig.java5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/summonings/SummoningMobManager.kt231
2 files changed, 74 insertions, 162 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/combat/SummoningsConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/combat/SummoningsConfig.java
index cfa899b8f..521459ece 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/combat/SummoningsConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/combat/SummoningsConfig.java
@@ -37,4 +37,9 @@ public class SummoningsConfig {
@ConfigEditorBoolean
@FeatureToggle
public boolean summoningMobColored = false;
+
+ @Expose
+ @ConfigOption(name = "Summon Chat Messages", desc = "Sends a chat message when a summon dies and hides other summon related messages.")
+ @ConfigEditorBoolean
+ public boolean summonMessages = false;
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/summonings/SummoningMobManager.kt b/src/main/java/at/hannibal2/skyhanni/features/summonings/SummoningMobManager.kt
index 8c1f254ca..7a78280da 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/summonings/SummoningMobManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/summonings/SummoningMobManager.kt
@@ -2,55 +2,56 @@ package at.hannibal2.skyhanni.features.summonings
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
+import at.hannibal2.skyhanni.data.mob.Mob
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
-import at.hannibal2.skyhanni.events.LorenzTickEvent
-import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
+import at.hannibal2.skyhanni.events.MobEvent
import at.hannibal2.skyhanni.events.SkyHanniRenderEntityEvent
-import at.hannibal2.skyhanni.mixins.hooks.RenderLivingEntityHelper
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.ChatUtils
-import at.hannibal2.skyhanni.utils.ColorUtils.withAlpha
-import at.hannibal2.skyhanni.utils.EntityUtils
-import at.hannibal2.skyhanni.utils.LocationUtils
+import at.hannibal2.skyhanni.utils.DelayedRun
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.baseMaxHealth
+import at.hannibal2.skyhanni.utils.MobUtils.mob
import at.hannibal2.skyhanni.utils.NumberUtil
import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat
-import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
-import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
-import at.hannibal2.skyhanni.utils.getLorenzVec
+import at.hannibal2.skyhanni.utils.RegexUtils.matches
+import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderable
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
+import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
-import net.minecraft.entity.EntityLiving
-import net.minecraft.entity.EntityLivingBase
import net.minecraft.entity.item.EntityArmorStand
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.time.Duration.Companion.seconds
@SkyHanniModule
object SummoningMobManager {
private val config get() = SkyHanniMod.feature.combat.summonings
+ private var mobs = mutableSetOf<Mob>()
- private val summoningMobs = mutableMapOf<EntityLiving, SummoningMob>()
- private val summoningMobNametags = mutableListOf<EntityArmorStand>()
- private var summoningsSpawned = 0
- private var searchArmorStands = false
- private var searchMobs = false
+ private var lastChatTime: SimpleTimeMark = SimpleTimeMark.farPast()
+ private val timeOut = 2.seconds
private val patternGroup = RepoPattern.group("summoning.mobs")
- private val spawnPattern by patternGroup.pattern( //§aYou have spawned your Tank Zombie §r§asoul! §r§d(249 Mana)
+
+ /**
+ * REGEX-TEST: §aYou have spawned your Tank Zombie §r§asoul! §r§d(249 Mana)
+ */
+ private val spawnPattern by patternGroup.pattern(
"spawn",
- "§aYou have spawned your (.+) §r§asoul! §r§d\\((\\d+) Mana\\)"
+ "§aYou have spawned your (.+) §r§asoul! §r§d\\((\\d+) Mana\\)",
)
+
+ /**
+ * REGEX-TEST: §cYou have despawned your monster!
+ * REGEX-TEST: §cYou have despawned your monsters!
+ */
private val despawnPattern by patternGroup.pattern(
"despawn",
- "§cYou have despawned your (monster|monsters)!"
- )
- private val healthPattern by patternGroup.pattern( //§a§ohannibal2's Tank Zombie§r §a160k§c❤
- "health",
- "§a§o(.+)'s (.+)§r §[ae]([\\dkm]+)§c❤"
+ "§cYou have despawned your monsters?!",
)
/**
@@ -59,170 +60,76 @@ object SummoningMobManager {
*/
private val seraphRecallPattern by patternGroup.pattern(
"seraphrecall",
- "§cThe Seraph recalled your (\\d+) summoned allies!"
+ "§cThe Seraph recalled your (\\d+) summoned allies!",
+ )
+
+ private val despawnPatterns = listOf(
+ despawnPattern,
+ seraphRecallPattern,
)
@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
- if (!LorenzUtils.inSkyBlock) return
-
- val message = event.message
- spawnPattern.matchMatcher(message) {
- if (config.summoningMobDisplay) {
- event.blockedReason = "summoning_soul"
- }
- summoningsSpawned++
- searchArmorStands = true
- searchMobs = true
- }
+ if (!LorenzUtils.inSkyBlock || !config.summonMessages) return
+ if (spawnPattern.matches(event.message)) event.blockedReason = "summoning_soul"
- if (despawnPattern.matcher(message).matches() || message.startsWith("§c ☠ §r§7You ")) {
- despawned()
- if (config.summoningMobDisplay && !message.contains("☠")) {
- event.blockedReason = "summoning_soul"
- }
- }
- if (message == "§cThe Seraph recalled your summoned ally!" || seraphRecallPattern.matcher(message).matches()) {
- despawned()
- if (config.summoningMobDisplay) {
- event.blockedReason = "summoning_soul"
- }
+ if (despawnPatterns.any { it.matches(event.message) }) {
+ event.blockedReason = "summoning_soul"
+ lastChatTime = SimpleTimeMark.now()
}
}
@SubscribeEvent
- fun onTick(event: LorenzTickEvent) {
- if (!isEnabled()) return
-
- if (config.summoningMobDisplay && event.repeatSeconds(1)) {
- updateData()
- }
-
- if (searchArmorStands) {
- for (it in EntityUtils.getEntities<EntityArmorStand>().filter { it !in summoningMobNametags }) {
- val name = it.displayName.unformattedText
- healthPattern.matchMatcher(name) {
- val playerName = LorenzUtils.getPlayerName()
- if (name.contains(playerName)) {
- summoningMobNametags.add(it)
- if (summoningMobNametags.size == summoningsSpawned) {
- searchArmorStands = false
- }
- }
- }
- }
- }
+ fun onMobSpawn(event: MobEvent.Spawn.Summon) {
+ if (event.mob.owner?.ownerName != LorenzUtils.getPlayerName()) return
- if (!searchMobs) return
- val playerLocation = LocationUtils.playerLocation()
- val list = EntityUtils.getEntities<EntityLiving>().filter {
- it !in summoningMobs.keys && it.getLorenzVec()
- .distance(playerLocation) < 10 && it.ticksExisted < 2
- }
- for (entity in list) {
- summoningMobs[entity] = SummoningMob(System.currentTimeMillis(), name = "Mob")
- entity.setColor(LorenzColor.GREEN)
- updateData()
- if (summoningMobs.size == summoningsSpawned) {
- searchMobs = false
- }
- }
+ mobs += event.mob
+ if (config.summoningMobColored) event.mob.highlight(LorenzColor.GREEN.toColor())
}
- 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)
- entityLiving.setColor(null)
+ @SubscribeEvent
+ fun onMobDeSpawn(event: MobEvent.DeSpawn.Summon) {
+ val mob = event.mob
+ if (mob !in mobs) return
+ mobs -= mob
+
+ if (!mob.isInRender()) return
+ DelayedRun.runNextTick {
+ if (lastChatTime.passedSince() > timeOut) {
ChatUtils.chat("Your Summoning Mob just §cdied!")
- continue
}
-
- val maxHealth = entityLiving.baseMaxHealth
- val color = NumberUtil.percentageColor(currentHealth.toLong(), maxHealth.toLong()).getChatColor()
-
- val currentFormat = currentHealth.shortFormat()
- val maxFormat = maxHealth.shortFormat()
- summoningMob.lastDisplayName = "§a$name $color$currentFormat/$maxFormat"
}
}
- @SubscribeEvent
- fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) {
- if (!LorenzUtils.inSkyBlock) return
- if (!config.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++
- }
-
- config.summoningMobDisplayPos.renderStrings(list, posLabel = "Summoning Mob Display")
+ @SubscribeEvent(priority = EventPriority.HIGH)
+ fun onRenderLiving(event: SkyHanniRenderEntityEvent.Specials.Pre<EntityArmorStand>) {
+ if (!LorenzUtils.inSkyBlock || !config.summoningMobHideNametag) return
+ if (event.entity.mob !in mobs) return
+ event.cancel()
}
@SubscribeEvent
- fun onWorldChange(event: LorenzWorldChangeEvent) {
- despawned()
- }
-
- @SubscribeEvent(priority = EventPriority.HIGH)
- fun onRenderLiving(event: SkyHanniRenderEntityEvent.Specials.Pre<EntityLivingBase>) {
- if (!LorenzUtils.inSkyBlock) return
- if (!config.summoningMobHideNametag) return
-
- val entity = event.entity
- if (entity !is EntityArmorStand) return
- if (!entity.hasCustomName()) return
- if (entity.isDead) return
+ fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) {
+ if (!LorenzUtils.inSkyBlock || !config.summoningMobDisplay) return
+ if (mobs.isEmpty()) return
+
+ val list = buildList {
+ add("Summoning mobs: " + mobs.size)
+ mobs.forEachIndexed { index, mob ->
+ val entity = mob.baseEntity
+ val health = entity.health
+ val maxHealth = entity.baseMaxHealth
+ val color = NumberUtil.percentageColor(health.toLong(), maxHealth.toLong()).getChatColor()
+ add("#${index + 1} §a${mob.name} $color${health.shortFormat()}§2/${maxHealth.shortFormat()}§c❤")
+ }
+ }.map { Renderable.string(it) }
- if (entity in summoningMobNametags) {
- event.cancel()
- }
+ val renderable = Renderable.verticalContainer(list)
+ config.summoningMobDisplayPos.renderRenderable(renderable, posLabel = "Summoning Mob Display")
}
@SubscribeEvent
fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
event.move(2, "summonings", "combat.summonings")
}
-
- private fun despawned() {
- summoningMobs.clear()
- summoningMobNametags.clear()
- summoningsSpawned = 0
- searchArmorStands = false
- searchMobs = false
- }
-
- private fun isEnabled(): Boolean {
- return LorenzUtils.inSkyBlock && (config.summoningMobDisplay || config.summoningMobHideNametag)
- }
-
- class SummoningMob(
- val spawnTime: Long,
- var name: String = "",
- var lastDisplayName: String = "",
- )
-
- private infix fun EntityLivingBase.setColor(color: LorenzColor?) {
- if (color != null) {
- RenderLivingEntityHelper.setEntityColorWithNoHurtTime(
- this,
- color.toColor().withAlpha(127),
- ) { isEnabled() && config.summoningMobColored }
- } else {
- RenderLivingEntityHelper.removeCustomRender(this)
- }
- }
}