From 08a857ae8d599fcc9206420cc14c164289ce1297 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Tue, 12 Jul 2022 00:36:02 +0200 Subject: add dungeon milestone display --- src/main/java/at/lorenz/mod/LorenzMod.java | 2 + src/main/java/at/lorenz/mod/config/Features.java | 26 ++++-- .../at/lorenz/mod/dungeon/DungeonChatFilter.kt | 2 - .../lorenz/mod/dungeon/DungeonMilestoneDisplay.kt | 97 ++++++++++++++++++++++ src/main/java/at/lorenz/mod/test/LorenzTest.kt | 3 - 5 files changed, 119 insertions(+), 11 deletions(-) create mode 100644 src/main/java/at/lorenz/mod/dungeon/DungeonMilestoneDisplay.kt (limited to 'src/main') diff --git a/src/main/java/at/lorenz/mod/LorenzMod.java b/src/main/java/at/lorenz/mod/LorenzMod.java index 4d70626e5..d19737a4e 100644 --- a/src/main/java/at/lorenz/mod/LorenzMod.java +++ b/src/main/java/at/lorenz/mod/LorenzMod.java @@ -9,6 +9,7 @@ import at.lorenz.mod.config.Features; import at.lorenz.mod.dungeon.DungeonChatFilter; import at.lorenz.mod.dungeon.DungeonData; import at.lorenz.mod.dungeon.DungeonHighlightClickedBlocks; +import at.lorenz.mod.dungeon.DungeonMilestoneDisplay; import at.lorenz.mod.dungeon.damageindicator.DungeonBossDamageIndicator; import at.lorenz.mod.items.HideNotClickableItems; import at.lorenz.mod.items.abilitycooldown.ItemAbilityCooldown; @@ -66,6 +67,7 @@ public class LorenzMod { MinecraftForge.EVENT_BUS.register(new ExpBottleOnGroundHider()); MinecraftForge.EVENT_BUS.register(new DungeonBossDamageIndicator()); MinecraftForge.EVENT_BUS.register(new ItemAbilityCooldown()); + MinecraftForge.EVENT_BUS.register(new DungeonMilestoneDisplay()); Commands.init(); diff --git a/src/main/java/at/lorenz/mod/config/Features.java b/src/main/java/at/lorenz/mod/config/Features.java index e70c8203d..cf386accc 100644 --- a/src/main/java/at/lorenz/mod/config/Features.java +++ b/src/main/java/at/lorenz/mod/config/Features.java @@ -35,6 +35,11 @@ public class Features { editOverlay(activeConfigCategory, 200, 16, debug.testPos); return; } + + if (runnableId.equals("dungeonMilestoneDisplay")) { + editOverlay(activeConfigCategory, 200, 16, dungeon.milestoneDisplayPos); + return; + } } @Expose @@ -121,21 +126,30 @@ public class Features { @ConfigOption(name = "Boss Damage Indicator", desc = "Shows the missing health of a boss in the dungeon and the cooldown time until the boss becomes attackable.") @ConfigEditorBoolean public boolean bossDamageIndicator = false; - } - public static class Items { + @Expose + @ConfigOption(name = "Milestone Display", desc = "Shows the current milestone inside Dungeons.") + @ConfigEditorBoolean + public boolean showMilestoneDisplay = false; @Expose - @ConfigOption(name = "Item Number as Stack", desc = "") - @ConfigEditorAccordion(id = 2) - public boolean filterTypes = false; + @ConfigOption(name = "Milestone Display Position", desc = "") + @ConfigEditorButton(runnableId = "dungeonMilestoneDisplay", buttonText = "Edit") + public Position milestoneDisplayPos = new Position(10, 10, false, true); + } + + public static class Items { @Expose @ConfigOption(name = "Not Clickable Items", desc = "Hide items that are not clickable in " + "the current inventory: ah, bz, accessory bag, etc") @ConfigEditorBoolean - @ConfigAccordionId(id = 2) public boolean hideNotClickableItems = false; + @Expose + @ConfigOption(name = "Item Number as Stack", desc = "") + @ConfigEditorAccordion(id = 2) + public boolean filterTypes = false; + @Expose @ConfigOption(name = "Master Star Number", desc = "Shows the Tier of the Master Star.") @ConfigEditorBoolean diff --git a/src/main/java/at/lorenz/mod/dungeon/DungeonChatFilter.kt b/src/main/java/at/lorenz/mod/dungeon/DungeonChatFilter.kt index 9452e5f60..bdf0addb4 100644 --- a/src/main/java/at/lorenz/mod/dungeon/DungeonChatFilter.kt +++ b/src/main/java/at/lorenz/mod/dungeon/DungeonChatFilter.kt @@ -40,8 +40,6 @@ class DungeonChatFilter { isPuzzle(message) -> "puzzle" isBoss(message) -> "boss" isEnd(message) -> "end" - //TODO add -// DungeonMilestoneDisplay.isMilestoneMessage(message) -> "milestone" else -> "" } diff --git a/src/main/java/at/lorenz/mod/dungeon/DungeonMilestoneDisplay.kt b/src/main/java/at/lorenz/mod/dungeon/DungeonMilestoneDisplay.kt new file mode 100644 index 000000000..cad3ff56f --- /dev/null +++ b/src/main/java/at/lorenz/mod/dungeon/DungeonMilestoneDisplay.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.misc.CurrentPetDisplay +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 +import kotlin.concurrent.fixedRateTimer + +class DungeonMilestoneDisplay { + + + companion object { + private var textToRender = "" + var color = "" + var currentMilestone = 0 + var timeReached = 0L + + fun isMilestoneMessage(message: String): Boolean = when { + message.matchRegex("§e§l(.*) Milestone §r§e.§r§7: You have dealt §r§c(.*)§r§7 Total Damage so far! §r§a(.*)") -> true + message.matchRegex("§e§lArcher Milestone §r§e.§r§7: You have dealt §r§c(.*)§r§7 Ranged Damage so far! §r§a(.*)") -> true + message.matchRegex("§e§lHealer Milestone §r§e.§r§7: You have healed §r§a(.*)§r§7 Damage so far! §r§a(.*)") -> true + message.matchRegex("§e§lTank Milestone §r§e.§r§7: You have tanked and dealt §r§c(.*)§r§7 Total Damage so far! §r§a(.*)s") -> true + + else -> false + } + } + + init { + fixedRateTimer(name = "dungeon-milestone-display", period = 200) { + if (!isEnabled()) return@fixedRateTimer + checkVisibility() + } + } + + private fun checkVisibility() { + if (currentMilestone >= 3) { + if (System.currentTimeMillis() > timeReached + 3_000) + if (textToRender != "") { + textToRender = textToRender.substring(1) + } + } + } + + @SubscribeEvent(receiveCanceled = true) + fun onChatPacket(event: LorenzChatEvent) { + if (!isEnabled()) return + + if (isMilestoneMessage(event.message)) { + event.blockedReason = "dungeon_milestone" + currentMilestone++ + update() + } + } + + private fun update() { + if (currentMilestone > 3) return + if (currentMilestone == 3) { + timeReached = System.currentTimeMillis() + } + + color = when (currentMilestone) { + 0, 1 -> "§c" + 2 -> "§e" + else -> "§a" + } + textToRender = "Current Milestone: $currentMilestone" + } + + @SubscribeEvent + fun onWorldChange(event: WorldEvent.Load) { + textToRender = "" + currentMilestone = 0 + } + + @SubscribeEvent + fun onDungeonStart(event: DungeonEnterEvent) { + currentMilestone = 0 + update() + } + + @SubscribeEvent + fun renderOverlay(event: RenderGameOverlayEvent.Post) { + if (!isEnabled()) return + + LorenzMod.feature.dungeon.milestoneDisplayPos.renderString(color + textToRender) + } + + private fun isEnabled(): Boolean { + return LorenzUtils.inDungeons && LorenzMod.feature.dungeon.showMilestoneDisplay + } +} \ No newline at end of file diff --git a/src/main/java/at/lorenz/mod/test/LorenzTest.kt b/src/main/java/at/lorenz/mod/test/LorenzTest.kt index de33f3419..480317608 100644 --- a/src/main/java/at/lorenz/mod/test/LorenzTest.kt +++ b/src/main/java/at/lorenz/mod/test/LorenzTest.kt @@ -2,10 +2,7 @@ package at.lorenz.mod.test import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import at.lorenz.mod.LorenzMod -import at.lorenz.mod.utils.GuiRender.renderString -import net.minecraft.client.Minecraft import net.minecraftforge.client.event.RenderGameOverlayEvent -import net.minecraftforge.fml.common.gameevent.TickEvent class LorenzTest { @SubscribeEvent -- cgit