diff options
| author | HiZe_ <superhize@hotmail.com> | 2023-07-01 00:17:47 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-01 00:17:47 +0200 |
| commit | 95601fae4578561ce32391036bbdeaaa1cf0f762 (patch) | |
| tree | 0e3e0bf482a4e28040e37de1a104e2138e328e83 /src/main/java/at/hannibal2/skyhanni/features | |
| parent | e3a4eb852f81b6da8e43305ca9d557f61ee08d07 (diff) | |
| download | skyhanni-95601fae4578561ce32391036bbdeaaa1cf0f762.tar.gz skyhanni-95601fae4578561ce32391036bbdeaaa1cf0f762.tar.bz2 skyhanni-95601fae4578561ce32391036bbdeaaa1cf0f762.zip | |
Crux Talisman Progress Display (#263)
Co-authored-by: superhize <superhize@gmail.com>
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/rift/CruxTalismanDisplay.kt | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/CruxTalismanDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/CruxTalismanDisplay.kt new file mode 100644 index 000000000..9932c19c0 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/rift/CruxTalismanDisplay.kt @@ -0,0 +1,127 @@ +package at.hannibal2.skyhanni.features.rift + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.ConfigLoadEvent +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList +import at.hannibal2.skyhanni.utils.NumberUtil.roundToPrecision +import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +object CruxTalismanDisplay { + + private val config get() = SkyHanniMod.feature.rift.cruxTalisman + private val partialName = "CRUX_TALISMAN" + private var display = listOf<List<Any>>() + private val displayLine = mutableListOf<Crux>() + private val bonusesLine = mutableListOf<String>() + private val progressPattern = + ".*(?<tier>§[0-9a-z][IV1-4-]+)\\s+(?<name>§[0-9a-z]\\w+)§[0-9a-z]:\\s*(?<progress>§[0-9a-z](?:§[0-9a-z])?MAXED|(?:§[0-9a-z]\\d+§[0-9a-z]\\/§[0-9a-z]\\d+)).*".toPattern() + private var maxed = false + private var percentValue = 0.0 + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { + if (!isEnabled()) return + config.position.renderStringsAndItems( + display, + posLabel = "Crux Talisman Display" + ) + } + + private fun update() { + display = drawDisplay() + } + + private fun drawDisplay() = buildList { + var maxedKill = 0 + var percent = 0 + for (crux in displayLine) + if (crux.maxed) + maxedKill++ + if (maxedKill == 6) + maxed = true + + if (!config.compactWhenMaxed && maxed) maxed = false + + if (displayLine.isNotEmpty()) { + addAsSingletonList("§7Crux Talisman Progress: ${if (maxed) "§a§lMAXED!" else "§a$percentValue%"}") + if (!maxed) { + displayLine.forEach { + percent += if (config.compactWhenMaxed) { + if (!it.maxed) { + "(?<progress>\\d+)/\\d+".toRegex().find(it.progress.removeColor())?.groupValues?.get(1) + ?.toInt() ?: 0 + } else 100 + } else { + if (it.progress.contains("MAXED")) + 100 + else { + "(?<progress>\\d+)/\\d+".toRegex().find(it.progress.removeColor())?.groupValues?.get(1) + ?.toInt() ?: 0 + } + } + addAsSingletonList(" ${it.tier} ${it.name}: ${it.progress}") + } + } + } + percentValue = ((percent.toDouble() / 600) * 100).roundToPrecision(1) + if (bonusesLine.isNotEmpty() && config.showBonuses.get()) { + addAsSingletonList("§7Bonuses:") + bonusesLine.forEach { addAsSingletonList(" $it") } + } + } + + + @SubscribeEvent + fun onTick(event: LorenzTickEvent) { + if (!isEnabled()) return + if (!event.isMod(40)) return + if (!InventoryUtils.getItemsInOwnInventory().any { it.getInternalName().startsWith(partialName) }) return + + displayLine.clear() + bonusesLine.clear() + maxed = false + var bonusFound = false + val inventoryStack = InventoryUtils.getItemsInOwnInventory() + for (stack in inventoryStack) { + line@ for (line in stack.getLore()) { + progressPattern.matchMatcher(line) { + val tier = group("tier").replace("-", "0") + val name = group("name") + val progress = group("progress") + val crux = Crux(name, tier, progress, progress.contains("MAXED")) + displayLine.add(crux) + } + if (line.startsWith("§7Total Bonuses")) { + bonusFound = true + continue@line + } + if (bonusFound) { + if (line.isEmpty()) { + bonusFound = false + continue@line + } + bonusesLine.add(line) + } + } + } + update() + } + + @SubscribeEvent + fun onConfigLoad(event: ConfigLoadEvent) { + LorenzUtils.onToggle(config.showBonuses) { update() } + } + + data class Crux(val name: String, val tier: String, val progress: String, val maxed: Boolean) + + fun isEnabled() = RiftAPI.inRift() && config.enabled +}
\ No newline at end of file |
