aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/lorenz/mod/dungeon
diff options
context:
space:
mode:
authorLorenz <ESs95s3P5z8Pheb>2022-07-12 12:35:19 +0200
committerLorenz <ESs95s3P5z8Pheb>2022-07-12 12:35:19 +0200
commitafdba2c6a3b27a53817cef0b0a306c05162fbcac (patch)
tree4dfeeac095fc394cdc4114a29cc3a0dbf0f65023 /src/main/java/at/lorenz/mod/dungeon
parent08a857ae8d599fcc9206420cc14c164289ce1297 (diff)
downloadskyhanni-afdba2c6a3b27a53817cef0b0a306c05162fbcac.tar.gz
skyhanni-afdba2c6a3b27a53817cef0b0a306c05162fbcac.tar.bz2
skyhanni-afdba2c6a3b27a53817cef0b0a306c05162fbcac.zip
add dungeon death counter display
Diffstat (limited to 'src/main/java/at/lorenz/mod/dungeon')
-rw-r--r--src/main/java/at/lorenz/mod/dungeon/DungeonDeathCounter.kt97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/main/java/at/lorenz/mod/dungeon/DungeonDeathCounter.kt b/src/main/java/at/lorenz/mod/dungeon/DungeonDeathCounter.kt
new file mode 100644
index 000000000..156b641c4
--- /dev/null
+++ b/src/main/java/at/lorenz/mod/dungeon/DungeonDeathCounter.kt
@@ -0,0 +1,97 @@
+package at.lorenz.mod.dungeon
+
+import at.lorenz.mod.LorenzMod
+import at.lorenz.mod.events.DungeonEnterEvent
+import at.lorenz.mod.events.LorenzChatEvent
+import at.lorenz.mod.utils.GuiRender.renderString
+import at.lorenz.mod.utils.LorenzUtils
+import at.lorenz.mod.utils.LorenzUtils.matchRegex
+import net.minecraftforge.client.event.RenderGameOverlayEvent
+import net.minecraftforge.event.world.WorldEvent
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+class DungeonDeathCounter {
+
+ private var textToRender = ""
+ private var deaths = 0
+
+ private fun isDeathMessage(message: String): Boolean = when {
+ message.matchRegex("§c ☠ §r§7You were killed by (.*)§r§7 and became a ghost§r§7.") -> true
+ message.matchRegex("§c ☠ §r§7(.*) was killed by (.*) and became a ghost§r§7.") -> true
+
+ message.matchRegex("§c ☠ §r§7You were crushed and became a ghost§r§7.") -> true
+ message.matchRegex("§c ☠ §r§7§r(.*)§r§7 was crushed and became a ghost§r§7.") -> true
+
+ message.matchRegex("§c ☠ §r§7You died to a trap and became a ghost§r§7.") -> true
+ message.matchRegex("§c ☠ §r(.*)§r§7 died to a trap and became a ghost§r§7.") -> true
+
+ message.matchRegex("§c ☠ §r§7You burnt to death and became a ghost§r§7.") -> true
+ message.matchRegex("§c ☠ §r(.*)§r§7 burnt to death and became a ghost§r§7.") -> true
+
+ message.matchRegex("§c ☠ §r§7You died and became a ghost§r§7.") -> true
+ message.matchRegex("§c ☠ §r(.*)§r§7 died and became a ghost§r§7.") -> true
+
+ message.matchRegex("§c ☠ §r§7You suffocated and became a ghost§r§7.") -> true
+ message.matchRegex("§c ☠ §r§7§r(.*)§r§7 suffocated and became a ghost§r§7.") -> true
+
+ message.matchRegex("§c ☠ §r§7You died to a mob and became a ghost§r§7.") -> true
+ message.matchRegex("§c ☠ §r(.*)§7 died to a mob and became a ghost§r§7.") -> true
+
+ message.matchRegex("§c ☠ §r§7You fell into a deep hole and became a ghost§r§7.") -> true
+ message.matchRegex("§c ☠ §r(.*)§r§7 fell into a deep hole and became a ghost§r§7.") -> true
+
+ message.matchRegex("§c ☠ §r§(.*)§r§7 disconnected from the Dungeon and became a ghost§r§7.") -> true
+
+ message.matchRegex("§c ☠ §r§7(.*)§r§7 fell to their death with help from §r(.*)§r§7 and became a ghost§r§7.") -> true
+
+ else -> false
+ }
+
+ @SubscribeEvent(receiveCanceled = true)
+ fun onChatPacket(event: LorenzChatEvent) {
+ if (!isEnabled()) return
+
+ if (isDeathMessage(event.message)) {
+ deaths++
+ LorenzUtils.chat("§c§l$deaths. DEATH!")
+ update()
+ }
+ }
+
+ private fun update() {
+ if (deaths == 0) {
+ textToRender = ""
+ return
+ }
+
+ val color = when (deaths) {
+ 1, 2 -> "§e"
+ 3 -> "§c"
+ else -> "§4"
+ }
+ textToRender = color + "Deaths: $deaths"
+ }
+
+ @SubscribeEvent
+ fun onDungeonStart(event: DungeonEnterEvent) {
+ deaths = 0
+ update()
+ }
+
+ @SubscribeEvent
+ fun onWorldChange(event: WorldEvent.Load) {
+ deaths = 0
+ update()
+ }
+
+ @SubscribeEvent
+ fun renderOverlay(event: RenderGameOverlayEvent.Post) {
+ if (!isEnabled()) return
+
+ LorenzMod.feature.dungeon.deathCounterDisplay.renderString(DungeonMilestoneDisplay.color + textToRender)
+ }
+
+ private fun isEnabled(): Boolean {
+ return LorenzUtils.inDungeons && LorenzMod.feature.dungeon.deathCounter
+ }
+} \ No newline at end of file