Skip to content

Commit

Permalink
Feature: Blaze Slayer Fire Pillar Display (#1766)
Browse files Browse the repository at this point in the history
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
  • Loading branch information
hannibal002 and hannibal002 authored May 11, 2024
1 parent b391c5d commit 3bb4b9b
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -689,6 +690,7 @@ class SkyHanniMod {
loadModule(HellionShieldHelper())
loadModule(BlazeSlayerFirePitsWarning())
loadModule(BlazeSlayerClearView())
loadModule(FirePillarDisplay())
loadModule(EndermanSlayerHideParticles())
loadModule(PlayerChatFilter())
loadModule(HideArmor())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
@@ -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(?<seconds>.*)s §c§l8 hits"
)

private var display = ""

@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
if (!isEnabled()) return

val seconds = EntityUtils.getEntities<EntityArmorStand>()
.map { it.name }
.matchFirst<String?>(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
}
12 changes: 7 additions & 5 deletions src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ object StringUtils {
inline fun <T> Pattern.findMatcher(text: String, consumer: Matcher.() -> T) =
matcher(text).let { if (it.find()) consumer(it) else null }

inline fun <T> Sequence<String>.matchFirst(pattern: Pattern, consumer: Matcher.() -> T): T? =
toList().matchFirst(pattern, consumer)

inline fun <T> List<String>.matchFirst(pattern: Pattern, consumer: Matcher.() -> T): T? {
for (line in this) {
pattern.matcher(line).let { if (it.matches()) return consumer(it) }
Expand Down Expand Up @@ -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<String>?) = list?.any { this.matches(it) } ?: false
fun Pattern.matches(string: String?): Boolean = string?.let { matcher(it).matches() } ?: false
fun Pattern.anyMatches(list: List<String>?): Boolean = list?.any { this.matches(it) } ?: false
fun Pattern.anyMatches(list: Sequence<String>?): Boolean = anyMatches(list?.toList())

fun Pattern.find(string: String?) = string?.let { matcher(it).find() } ?: false

Expand All @@ -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]
Expand Down Expand Up @@ -395,7 +398,6 @@ object StringUtils {
}
}


fun <T : IChatComponent> replaceIfNeeded(
original: T,
newText: T,
Expand Down Expand Up @@ -435,7 +437,7 @@ object StringUtils {

private fun IChatComponent.findAllEvents(
clickEvents: MutableList<ClickEvent>,
hoverEvents: MutableList<HoverEvent>
hoverEvents: MutableList<HoverEvent>,
) {
siblings.forEach { it.findAllEvents(clickEvents, hoverEvents) }

Expand Down

0 comments on commit 3bb4b9b

Please sign in to comment.