aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHiZe_ <superhize@hotmail.com>2023-07-10 18:55:01 +0200
committerGitHub <noreply@github.com>2023-07-10 18:55:01 +0200
commitdabca502b84be62e1415e3af805810a7a94e333c (patch)
tree8ad6c506662a986b17883c32565f08429b92ec99 /src
parentd5b4500d684bca13ef02b133dfd62a02b26928e3 (diff)
downloadskyhanni-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')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt1
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java21
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/rift/LivingMetalSuitProgress.kt95
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt2
5 files changed, 120 insertions, 1 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index cc16baa95..29746e638 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
@@ -322,6 +322,7 @@ class SkyHanniMod {
loadModule(RiftLavaMazeParkour())
loadModule(HighlightMiningCommissionMobs())
loadModule(ShowMotesNpcSellPrice())
+ loadModule(LivingMetalSuitProgress())
init()
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java
index c88a89b3c..f164750e3 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java
@@ -403,6 +403,27 @@ public class RiftConfig {
}
@Expose
+ @ConfigOption(name = "Living Metal Suit Progress", desc = "")
+ @Accordion
+ public LivingMetalSuitProgress livingMetalSuitProgress = new LivingMetalSuitProgress();
+
+ public static class LivingMetalSuitProgress {
+
+ @Expose
+ @ConfigOption(name = "Enabled", desc = "Display progress Living Metal Suit")
+ @ConfigEditorBoolean
+ public boolean enabled = true;
+
+ @Expose
+ @ConfigOption(name = "Compact", desc = "Show a compacted version of the overlay when the set is maxed.")
+ @ConfigEditorBoolean
+ public boolean compactWhenMaxed = false;
+
+ @Expose
+ public Position position = new Position(100, 100);
+ }
+
+ @Expose
@ConfigOption(name = "Show Motes Price", desc = "Show the Motes NPC price in the item lore.")
@ConfigEditorBoolean
public boolean showMotesPrice = true;
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
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
index 57c7b3b84..8cf55b29c 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
@@ -59,7 +59,7 @@ object NumberUtil {
* @link https://stackoverflow.com/a/22186845
* @author jpdymond
*/
- fun Double.roundToPrecision(precision: Int): Double {
+ fun Double.roundToPrecision(precision: Int): Double { // TODO is this the same as LorenzUtils.round() ?
val scale = 10.0.pow(precision).toInt()
return (this * scale).roundToInt().toDouble() / scale
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt
index 0f306b295..4df582ca6 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt
@@ -130,6 +130,8 @@ object SkyBlockItemModifierUtils {
fun ItemStack.hasArtOfPiece() = getAttributeBoolean("artOfPeaceApplied")
+ fun ItemStack.getLivingMetalProgress() = getAttributeInt("lm_evo")
+
fun ItemStack.getEnchantments() = getExtraAttributes()?.takeIf { it.hasKey("enchantments") }?.run {
val enchantments = this.getCompoundTag("enchantments")
enchantments.keySet.associateWith { enchantments.getInteger(it) }