From 3bb4b9b9826fadd8df3507ea86b6196b6487b981 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Sun, 12 May 2024 00:53:09 +0200 Subject: Feature: Blaze Slayer Fire Pillar Display (#1766) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 2 + .../config/features/slayer/SlayerConfig.java | 1 + .../config/features/slayer/blaze/BlazeConfig.java | 17 +++++++- .../features/slayer/blaze/FirePillarDisplay.kt | 51 ++++++++++++++++++++++ .../at/hannibal2/skyhanni/utils/StringUtils.kt | 12 ++--- 5 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/FirePillarDisplay.kt (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index e2dc9e1ea..ce273afd4 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -427,6 +427,7 @@ import at.hannibal2.skyhanni.features.slayer.VampireSlayerFeatures import at.hannibal2.skyhanni.features.slayer.blaze.BlazeSlayerClearView import at.hannibal2.skyhanni.features.slayer.blaze.BlazeSlayerDaggerHelper import at.hannibal2.skyhanni.features.slayer.blaze.BlazeSlayerFirePitsWarning +import at.hannibal2.skyhanni.features.slayer.blaze.FirePillarDisplay import at.hannibal2.skyhanni.features.slayer.blaze.HellionShieldHelper import at.hannibal2.skyhanni.features.slayer.enderman.EndermanSlayerFeatures import at.hannibal2.skyhanni.features.slayer.enderman.EndermanSlayerHideParticles @@ -689,6 +690,7 @@ class SkyHanniMod { loadModule(HellionShieldHelper()) loadModule(BlazeSlayerFirePitsWarning()) loadModule(BlazeSlayerClearView()) + loadModule(FirePillarDisplay()) loadModule(EndermanSlayerHideParticles()) loadModule(PlayerChatFilter()) loadModule(HideArmor()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/slayer/SlayerConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/slayer/SlayerConfig.java index 8edf7aa4a..d21fd1a9d 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/slayer/SlayerConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/slayer/SlayerConfig.java @@ -19,6 +19,7 @@ public class SlayerConfig { @Expose @Category(name = "Blaze", desc = "Blaze Slayer Features") + // TODO rename to "blaze" public BlazeConfig blazes = new BlazeConfig(); @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/slayer/blaze/BlazeConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/slayer/blaze/BlazeConfig.java index 99c4eb923..86d3e68f7 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/slayer/blaze/BlazeConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/slayer/blaze/BlazeConfig.java @@ -1,9 +1,11 @@ package at.hannibal2.skyhanni.config.features.slayer.blaze; import at.hannibal2.skyhanni.config.FeatureToggle; +import at.hannibal2.skyhanni.config.core.config.Position; import com.google.gson.annotations.Expose; import io.github.notenoughupdates.moulconfig.annotations.Accordion; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; +import io.github.notenoughupdates.moulconfig.annotations.ConfigLink; import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; public class BlazeConfig { @@ -12,7 +14,6 @@ public class BlazeConfig { @Accordion public BlazeHellionConfig hellion = new BlazeHellionConfig(); - @Expose @ConfigOption(name = "Fire Pits", desc = "Warning when the fire pit phase starts for the Blaze Slayer tier 3 and 4.") @ConfigEditorBoolean @@ -29,4 +30,18 @@ public class BlazeConfig { @ConfigEditorBoolean @FeatureToggle public boolean clearView = false; + + @Expose + @ConfigOption( + name = "Pillar Display", + desc = "Show a big display with a timer when the Fire Pillar is about to explode. " + + "Also shows for other player's bosses as well." + ) + @ConfigEditorBoolean + @FeatureToggle + public boolean firePillarDisplay = false; + + @Expose + @ConfigLink(owner = BlazeConfig.class, field = "firePillarDisplay") + public Position firePillarDisplayPosition = new Position(200, 120, false, true); } diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/FirePillarDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/FirePillarDisplay.kt new file mode 100644 index 000000000..4ffba9378 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/FirePillarDisplay.kt @@ -0,0 +1,51 @@ +package at.hannibal2.skyhanni.features.slayer.blaze + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.IslandType +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.utils.EntityUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland +import at.hannibal2.skyhanni.utils.RenderUtils.renderString +import at.hannibal2.skyhanni.utils.StringUtils.matchFirst +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import net.minecraft.entity.item.EntityArmorStand +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class FirePillarDisplay { + private val config get() = SkyHanniMod.feature.slayer.blazes + + /** + * REGEX-TEST: §6§l2s §c§l8 hits + */ + private val entityNamePattern by RepoPattern.pattern( + "slayer.blaze.firepillar.entityname", + "§6§l(?.*)s §c§l8 hits" + ) + + private var display = "" + + @SubscribeEvent + fun onTick(event: LorenzTickEvent) { + if (!isEnabled()) return + + val seconds = EntityUtils.getEntities() + .map { it.name } + .matchFirst(entityNamePattern) { + group("seconds") + } + + display = seconds?.let { + "§cFire Pillar: §b${seconds}s" + } ?: "" + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent) { + if (!isEnabled()) return + + config.firePillarDisplayPosition.renderString(display, posLabel = "Fire Pillar") + } + + fun isEnabled() = IslandType.CRIMSON_ISLE.isInIsland() && config.firePillarDisplay +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt index c048004f2..4e5bce010 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt @@ -106,6 +106,9 @@ object StringUtils { inline fun Pattern.findMatcher(text: String, consumer: Matcher.() -> T) = matcher(text).let { if (it.find()) consumer(it) else null } + inline fun Sequence.matchFirst(pattern: Pattern, consumer: Matcher.() -> T): T? = + toList().matchFirst(pattern, consumer) + inline fun List.matchFirst(pattern: Pattern, consumer: Matcher.() -> T): T? { for (line in this) { pattern.matcher(line).let { if (it.matches()) return consumer(it) } @@ -309,8 +312,9 @@ object StringUtils { fun String.convertToFormatted(): String = this.replace("&&", "§") - fun Pattern.matches(string: String?) = string?.let { matcher(it).matches() } ?: false - fun Pattern.anyMatches(list: List?) = list?.any { this.matches(it) } ?: false + fun Pattern.matches(string: String?): Boolean = string?.let { matcher(it).matches() } ?: false + fun Pattern.anyMatches(list: List?): Boolean = list?.any { this.matches(it) } ?: false + fun Pattern.anyMatches(list: Sequence?): Boolean = anyMatches(list?.toList()) fun Pattern.find(string: String?) = string?.let { matcher(it).find() } ?: false @@ -331,7 +335,6 @@ object StringUtils { return replaceIfNeeded(original, ChatComponentText(newText)) } - private val colorMap = EnumChatFormatting.entries.associateBy { it.toString()[1] } fun enumChatFormattingByCode(char: Char): EnumChatFormatting? { return colorMap[char] @@ -395,7 +398,6 @@ object StringUtils { } } - fun replaceIfNeeded( original: T, newText: T, @@ -435,7 +437,7 @@ object StringUtils { private fun IChatComponent.findAllEvents( clickEvents: MutableList, - hoverEvents: MutableList + hoverEvents: MutableList, ) { siblings.forEach { it.findAllEvents(clickEvents, hoverEvents) } -- cgit