aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/dulkirfabric/util
diff options
context:
space:
mode:
authoringlettronald <inglettronald@gmail.com>2023-07-23 15:01:47 -0500
committeringlettronald <inglettronald@gmail.com>2023-07-23 15:01:47 -0500
commitc36dd88ff83ff09d5941d6772b5eefff0cd10665 (patch)
treeff52d13bff786794bd1750095f09f28401b7a02c /src/main/kotlin/com/dulkirfabric/util
parent5cac8361bad69bcd535b996940c70ac21762f67a (diff)
downloadDulkirMod-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/kotlin/com/dulkirfabric/util')
-rw-r--r--src/main/kotlin/com/dulkirfabric/util/ActionBarUtil.kt60
-rw-r--r--src/main/kotlin/com/dulkirfabric/util/TablistUtils.kt28
2 files changed, 81 insertions, 7 deletions
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