diff options
author | inglettronald <inglettronald@gmail.com> | 2023-07-23 15:01:47 -0500 |
---|---|---|
committer | inglettronald <inglettronald@gmail.com> | 2023-07-23 15:01:47 -0500 |
commit | c36dd88ff83ff09d5941d6772b5eefff0cd10665 (patch) | |
tree | ff52d13bff786794bd1750095f09f28401b7a02c /src/main | |
parent | 5cac8361bad69bcd535b996940c70ac21762f67a (diff) | |
download | DulkirMod-Fabric-c36dd88ff83ff09d5941d6772b5eefff0cd10665.tar.gz DulkirMod-Fabric-c36dd88ff83ff09d5941d6772b5eefff0cd10665.tar.bz2 DulkirMod-Fabric-c36dd88ff83ff09d5941d6772b5eefff0cd10665.zip |
Add HUD elements for HP/Mana/Defenses/Stacks/Speed
Diffstat (limited to 'src/main')
10 files changed, 198 insertions, 18 deletions
diff --git a/src/main/kotlin/com/dulkirfabric/Registrations.kt b/src/main/kotlin/com/dulkirfabric/Registrations.kt index 04eb9d8..fdace3c 100644 --- a/src/main/kotlin/com/dulkirfabric/Registrations.kt +++ b/src/main/kotlin/com/dulkirfabric/Registrations.kt @@ -9,6 +9,9 @@ import com.dulkirfabric.events.chat.OverlayReceivedEvent import com.dulkirfabric.features.* import com.dulkirfabric.features.chat.AbiPhoneDND import com.dulkirfabric.features.chat.BridgeBotFormatter +import com.dulkirfabric.hud.ActionBarHudReplacements +import com.dulkirfabric.hud.SpeedOverlay +import com.dulkirfabric.util.ActionBarUtil import com.dulkirfabric.util.TablistUtils import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientEntityEvents @@ -69,6 +72,9 @@ object Registrations { EVENT_BUS.subscribe(CooldownDisplays) EVENT_BUS.subscribe(ArachneFeatures) EVENT_BUS.subscribe(BridgeBotFormatter) + EVENT_BUS.subscribe(SpeedOverlay) + EVENT_BUS.subscribe(ActionBarUtil) + EVENT_BUS.subscribe(ActionBarHudReplacements) } fun registerEvents() { @@ -79,8 +85,14 @@ object Registrations { tickCount++ } ClientReceiveMessageEvents.ALLOW_GAME.register { message, overlay -> - if (overlay) !OverlayReceivedEvent(message.toString()).post() - else !ChatReceivedEvent(message).post() + if (!overlay) + return@register !ChatReceivedEvent(message).post() + return@register true + } + ClientReceiveMessageEvents.MODIFY_GAME.register { message, overlay -> + if (overlay) + return@register OverlayReceivedEvent(message).post() + return@register message } ClientSendMessageEvents.MODIFY_COMMAND.register { command -> @@ -110,5 +122,6 @@ object Registrations { HudRenderCallback.EVENT.register { context, delta -> HudRenderEvent(context, delta).post() } + } }
\ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt b/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt index e8dc743..a095c23 100644 --- a/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt +++ b/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt @@ -125,6 +125,12 @@ class DulkirConfig { general.addEntry( entryBuilder.mkToggle(Text.literal("Arachne Boss Spawn Timer"), configOptions::arachneSpawnTimer) ) + general.addEntry( + entryBuilder.mkToggle(Text.literal("Convert Action Bar to HUD elements"), configOptions::hudifyActionBar, tooltip = Text.literal("This converts Mana/Health/Def/Stacks as HUD elements")) + ) + general.addEntry( + entryBuilder.mkToggle(Text.literal("Include EHP in def HUD element"), configOptions::showEHP, tooltip = Text.literal("Must have Action Bar HUD elements Enabled")) + ) val shortcuts = builder.getOrCreateCategory(Text.literal("Shortcuts")) shortcuts.addEntry( @@ -268,6 +274,8 @@ class DulkirConfig { var bridgeBotName: String = "Dilkur", var bridgeNameColor: Int = Formatting.GOLD.colorValue!!, val positions: MutableMap<String, HudElement.Positioning> = mutableMapOf(), + var hudifyActionBar: Boolean = true, + var showEHP: Boolean = false ) @Serializable @@ -297,9 +305,8 @@ class DulkirConfig { ): HudElement { val element = HudElement( configOptions.positions.getOrPut( - id, - { HudElement.Positioning(defaultPosition.x(), defaultPosition.y(), 1F) } - ), + id + ) { HudElement.Positioning(defaultPosition.x(), defaultPosition.y(), 1F) }, id, label, width, height, ) diff --git a/src/main/kotlin/com/dulkirfabric/events/base/ModifyTextEvent.kt b/src/main/kotlin/com/dulkirfabric/events/base/ModifyTextEvent.kt new file mode 100644 index 0000000..9432886 --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/events/base/ModifyTextEvent.kt @@ -0,0 +1,15 @@ +package com.dulkirfabric.events.base + +import com.dulkirfabric.DulkirModFabric +import net.minecraft.text.Text + +abstract class ModifyTextEvent(original: Text) { + private var returnValue: Text = original + + fun setReturnValue(new: Text) { + returnValue = new + } + fun post(): Text { + return DulkirModFabric.EVENT_BUS.post(this).returnValue + } +}
\ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/events/chat/OverlayReceivedEvent.kt b/src/main/kotlin/com/dulkirfabric/events/chat/OverlayReceivedEvent.kt index 1e27260..9ce5b1f 100644 --- a/src/main/kotlin/com/dulkirfabric/events/chat/OverlayReceivedEvent.kt +++ b/src/main/kotlin/com/dulkirfabric/events/chat/OverlayReceivedEvent.kt @@ -1,5 +1,6 @@ package com.dulkirfabric.events.chat -import com.dulkirfabric.events.base.CancellableEvent +import com.dulkirfabric.events.base.ModifyTextEvent +import net.minecraft.text.Text -data class OverlayReceivedEvent(val message: String): CancellableEvent() +data class OverlayReceivedEvent(val message: Text): ModifyTextEvent(message) diff --git a/src/main/kotlin/com/dulkirfabric/features/ArachneFeatures.kt b/src/main/kotlin/com/dulkirfabric/features/ArachneFeatures.kt index 695e610..f573736 100644 --- a/src/main/kotlin/com/dulkirfabric/features/ArachneFeatures.kt +++ b/src/main/kotlin/com/dulkirfabric/features/ArachneFeatures.kt @@ -37,7 +37,7 @@ object ArachneFeatures { private var bigboy: Boolean = false @EventHandler fun onRenderWorldLast(event: WorldRenderLastEvent) { - if (TablistUtils.area != "Spider's Den") return + if (TablistUtils.persistentInfo.area != "Spider's Den") return if (!DulkirConfig.configOptions.arachneKeeperWaypoints) return keeperWaypoints.forEach { WorldRenderUtils.renderWaypoint(it.name, event.context, it.pos) @@ -47,7 +47,7 @@ object ArachneFeatures { @EventHandler fun onChat(event: ChatReceivedEvent) { if (!DulkirConfig.configOptions.arachneSpawnTimer) return - if (TablistUtils.area != "Spider's Den") return + if (TablistUtils.persistentInfo.area != "Spider's Den") return val str = event.message.unformattedString.trim() if (str matches spawnRegex) { bigboy = false @@ -67,7 +67,7 @@ object ArachneFeatures { @EventHandler fun onWorldRenderLast(event: WorldRenderLastEvent) { if (!DulkirConfig.configOptions.arachneSpawnTimer) return - if (TablistUtils.area != "Spider's Den") return + if (TablistUtils.persistentInfo.area != "Spider's Den") return if (spawnmillis <=startmillis) return var time: Int = if (bigboy) { diff --git a/src/main/kotlin/com/dulkirfabric/features/EffigyDisplay.kt b/src/main/kotlin/com/dulkirfabric/features/EffigyDisplay.kt index 257a200..b795b91 100644 --- a/src/main/kotlin/com/dulkirfabric/features/EffigyDisplay.kt +++ b/src/main/kotlin/com/dulkirfabric/features/EffigyDisplay.kt @@ -40,7 +40,7 @@ object EffigyDisplay { fun checkEffigies(event: LongUpdateEvent) { if (!DulkirConfig.configOptions.inactiveEffigyDisplay) return if (!Utils.isInSkyblock()) return - if (TablistUtils.area != "The Rift") { + if (TablistUtils.persistentInfo.area != "The Rift") { effigyWaypoints.forEach { it.render = false } return } diff --git a/src/main/kotlin/com/dulkirfabric/hud/ActionBarHudReplacements.kt b/src/main/kotlin/com/dulkirfabric/hud/ActionBarHudReplacements.kt new file mode 100644 index 0000000..8bacec0 --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/hud/ActionBarHudReplacements.kt @@ -0,0 +1,47 @@ +package com.dulkirfabric.hud + +import com.dulkirfabric.DulkirModFabric +import com.dulkirfabric.config.DulkirConfig +import com.dulkirfabric.events.HudRenderEvent +import com.dulkirfabric.util.ActionBarUtil +import com.dulkirfabric.util.Utils +import meteordevelopment.orbit.EventHandler +import moe.nea.jarvis.api.Point +import net.minecraft.text.Text + +object ActionBarHudReplacements { + private val hpHud = DulkirConfig.hudElement("hpHud", Text.literal("Health"), 50, 11, Point(0.21, 0.21)) + private val defHud = DulkirConfig.hudElement("defHud", Text.literal("Def"), 50, 25, Point(0.22, 0.22)) + private val stackHud = DulkirConfig.hudElement("stackHud", Text.literal("Stacks"), 50, 11, Point(0.22, 0.22)) + private val manaHud = DulkirConfig.hudElement("manaHud", Text.literal("Mana"), 50, 11, Point(0.23, 0.23)) + + @EventHandler + fun onHudRender(event: HudRenderEvent) { + if (!Utils.isInSkyblock()) return + if (!DulkirConfig.configOptions.hudifyActionBar) return + val context = event.context + val matrices = context.matrices + matrices.push() + hpHud.applyTransformations(matrices) + context.drawText(DulkirModFabric.mc.textRenderer, Text.literal(ActionBarUtil.healthStr),0, 1, -1, true) + matrices.pop() + + matrices.push() + defHud.applyTransformations(matrices) + context.drawText(DulkirModFabric.mc.textRenderer, Text.literal(ActionBarUtil.defStr),0, 1, -1, true) + if (DulkirConfig.configOptions.showEHP) { + context.drawText(DulkirModFabric.mc.textRenderer, Text.literal(ActionBarUtil.ehp), 0, 1 + 12, -1, true) + } + matrices.pop() + + matrices.push() + stackHud.applyTransformations(matrices) + context.drawText(DulkirModFabric.mc.textRenderer, Text.literal(ActionBarUtil.stacks),0, 1, -1, true) + matrices.pop() + + matrices.push() + manaHud.applyTransformations(matrices) + context.drawText(DulkirModFabric.mc.textRenderer, Text.literal(ActionBarUtil.mana),0, 1, -1, true) + matrices.pop() + } +}
\ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/hud/SpeedOverlay.kt b/src/main/kotlin/com/dulkirfabric/hud/SpeedOverlay.kt new file mode 100644 index 0000000..eaee06c --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/hud/SpeedOverlay.kt @@ -0,0 +1,23 @@ +package com.dulkirfabric.hud + +import com.dulkirfabric.DulkirModFabric.mc +import com.dulkirfabric.config.DulkirConfig +import com.dulkirfabric.events.HudRenderEvent +import com.dulkirfabric.util.TablistUtils +import meteordevelopment.orbit.EventHandler +import moe.nea.jarvis.api.Point +import net.minecraft.text.Text + +object SpeedOverlay { + private val speedHud = DulkirConfig.hudElement("SpeedHud", Text.literal("Speed"), 24 + 4, 11, Point(0.2, 0.2)) + + @EventHandler + fun onHudRender(event: HudRenderEvent) { + val context = event.context + val matrices = context.matrices + matrices.push() + speedHud.applyTransformations(matrices) + context.drawText(mc.textRenderer, Text.literal(TablistUtils.persistentInfo.speed),0, 1, -1, true) + matrices.pop() + } +}
\ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/util/ActionBarUtil.kt b/src/main/kotlin/com/dulkirfabric/util/ActionBarUtil.kt new file mode 100644 index 0000000..4970ba8 --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/util/ActionBarUtil.kt @@ -0,0 +1,60 @@ +package com.dulkirfabric.util + +import com.dulkirfabric.config.DulkirConfig +import com.dulkirfabric.events.LongUpdateEvent +import com.dulkirfabric.events.chat.OverlayReceivedEvent +import com.dulkirfabric.util.ScoreBoardUtils.formattedString +import meteordevelopment.orbit.EventHandler +import net.minecraft.text.Text +import java.text.NumberFormat + +object ActionBarUtil { + + private val splitRegex = " {2,}".toRegex() + var healthStr = "" + var defStr = "" + var mana = "" + var ehp = "§2?" + var stacks = "" + private val healthRegex = "([0-9,]+)/([0-9,]+)❤".toRegex() + private var healthInt = 0 + private val defRegex = "([0-9,]+)❈ Defense".toRegex() + private var defInt = 0 + + @EventHandler + fun onRenderActionBar(event: OverlayReceivedEvent) { + if (!Utils.isInSkyblock()) return + if (!DulkirConfig.configOptions.hudifyActionBar) return + val sb = StringBuilder() + var stackFlag = false + event.message.formattedString().split(splitRegex).forEach { + healthRegex.matchEntire(TextUtils.stripColorCodes(it)) ?.let { result -> + healthInt = result.groupValues[1].replace(",", "").toInt() + healthStr = it + return@forEach + } + defRegex.matchEntire(TextUtils.stripColorCodes(it)) ?.let { result -> + defInt = result.groupValues[1].replace(",", "").toInt() + defStr = it.replace(" Defense", "") + return@forEach + } + if (it.contains('ᝐ')) { + stackFlag = true + stacks = it + return@forEach + } + if (it.contains('✎')) { + mana = it + return@forEach + } + sb.append(it) + } + if (!stackFlag) stacks = "" + event.setReturnValue(Text.literal(sb.toString())) + } + + @EventHandler + fun onLongUpdate(event: LongUpdateEvent) { + ehp = "§2${NumberFormat.getInstance().format((healthInt * (1 + (defInt / 100f))).toInt())}" + } +}
\ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/util/TablistUtils.kt b/src/main/kotlin/com/dulkirfabric/util/TablistUtils.kt index a0999f6..821c1c5 100644 --- a/src/main/kotlin/com/dulkirfabric/util/TablistUtils.kt +++ b/src/main/kotlin/com/dulkirfabric/util/TablistUtils.kt @@ -8,21 +8,35 @@ import net.minecraft.client.network.PlayerListEntry object TablistUtils { var tablist: List<PlayerListEntry>? = null private val areaPattern = "Area: (.+)".toRegex() - var area: String = "" + private val speedPattern = "^Speed: (.+)".toRegex() + data class PersistentInfo( + var area: String = "", + var speed: String = "" + ) + + var persistentInfo: PersistentInfo = PersistentInfo() @EventHandler fun onLongUpdate(event: LongUpdateEvent) { if (mc.player == null) return tablist = mc.inGameHud.playerListHud.collectPlayerEntries() - area = updateArea() + updatePersistentData() } - private fun updateArea(): String { - if (tablist == null) return "" + private fun updatePersistentData() { + if (tablist == null) return tablist!!.forEach { - val match = areaPattern.find(it.displayName?.string ?: return@forEach) ?: return@forEach - return match.groupValues[1] + areaPattern.find(it.displayName?.string ?: return@forEach) ?.let { result -> + persistentInfo.area = result.groupValues[1] + return@forEach + } + + speedPattern.matchEntire(it.displayName?.string?.trim() ?: return@forEach) ?.let { result -> + persistentInfo.speed = result.groupValues[1] + return@forEach + } + } - return "" + } }
\ No newline at end of file |