diff options
| author | HiZe_ <superhize@hotmail.com> | 2023-07-10 18:55:01 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-10 18:55:01 +0200 |
| commit | dabca502b84be62e1415e3af805810a7a94e333c (patch) | |
| tree | 8ad6c506662a986b17883c32565f08429b92ec99 /src/main/java/at/hannibal2/skyhanni/features | |
| parent | d5b4500d684bca13ef02b133dfd62a02b26928e3 (diff) | |
| download | skyhanni-dabca502b84be62e1415e3af805810a7a94e333c.tar.gz skyhanni-dabca502b84be62e1415e3af805810a7a94e333c.tar.bz2 skyhanni-dabca502b84be62e1415e3af805810a7a94e333c.zip | |
Living Metal Suit Progress (#292)
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/LivingMetalSuitProgress.kt | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/LivingMetalSuitProgress.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/LivingMetalSuitProgress.kt new file mode 100644 index 000000000..b6758a923 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/rift/LivingMetalSuitProgress.kt @@ -0,0 +1,95 @@ +package at.hannibal2.skyhanni.features.rift + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.utils.InventoryUtils +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.SkyBlockItemModifierUtils.getLivingMetalProgress +import net.minecraft.item.ItemStack +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class LivingMetalSuitProgress { + + private val config get() = SkyHanniMod.feature.rift.livingMetalSuitProgress + private var display = emptyList<List<Any>>() + private var progressMap = mapOf<ItemStack, Double?>() + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { + if (!isEnabled()) return + config.position.renderStringsAndItems( + display, + posLabel = "Living Metal Armor Progress" + ) + } + + private fun update() { + display = drawDisplay() + } + + fun drawDisplay(): List<List<Any>> = buildList { + val piecesMaxed = progressMap.values.filterNotNull().count { it >= 1 } + val isMaxed = piecesMaxed == 4 + + if (progressMap.isEmpty()) return@buildList + + val totalProgress = progressMap.values.map { it ?: 1.0 }.average().roundToPrecision(1) + val formatPercentage = LorenzUtils.formatPercentage(totalProgress) + addAsSingletonList("§7Living Metal Suit Progress: ${if (isMaxed) "§a§lMAXED!" else "§a$formatPercentage"}") + + if (config.compactWhenMaxed && isMaxed) return@buildList + + for ((stack, progress) in progressMap.entries.reversed()) { + add(buildList { + add(" §7- ") + add(stack) + add("${stack.displayName}: ") + add(progress?.let { + drawProgressBar(progress) + " §b${LorenzUtils.formatPercentage(progress)}" + } ?: "§cStart upgrading it!") + }) + } + } + + @SubscribeEvent + fun onTick(event: LorenzTickEvent) { + if (!isEnabled()) return + if (!event.isMod(20)) return + val old = progressMap + progressMap = buildMap { + for (armor in InventoryUtils.getArmor().filterNotNull()) { + put(armor, armor.getLivingMetalProgress()?.toDouble()?.let { + it.coerceAtMost(100.0) / 100 + }) + } + } + if (old != progressMap) { + update() + } + } + + private fun drawProgressBar(percentage: Double): String { + val progressBarLength = 20 + val filledLength = (percentage * progressBarLength).toInt() + + val green = "§a" + val grey = "§7" + val reset = "§f" + + val progressBar = StringBuilder() + progressBar.append(green) + repeat(filledLength) { progressBar.append("|") } + + progressBar.append(grey) + repeat(progressBarLength - filledLength) { progressBar.append("|") } + + progressBar.append(reset) + return progressBar.toString() + } + + fun isEnabled() = RiftAPI.inRift() && config.enabled +}
\ No newline at end of file |
