From 045c39701411b5c9a5ffcbffb45ce34c09f1c2c6 Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Thu, 13 Jun 2024 20:14:16 +0200 Subject: Feature: Total Powder Cost in Perk Lore (#1460) Co-authored-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Co-authored-by: Empa <42304516+ItsEmpa@users.noreply.github.com> Co-authored-by: martimavocado <39881008+martimavocado@users.noreply.github.com> Co-authored-by: Thunderblade73 Co-authored-by: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Co-authored-by: martimavocado Co-authored-by: Cal Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../skyhanni/features/mining/PowderPerHotmPerk.kt | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/mining/PowderPerHotmPerk.kt (limited to 'src/main/java/at/hannibal2/skyhanni/features/mining') diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/PowderPerHotmPerk.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/PowderPerHotmPerk.kt new file mode 100644 index 000000000..4acf5f3ad --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/PowderPerHotmPerk.kt @@ -0,0 +1,90 @@ +package at.hannibal2.skyhanni.features.mining + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.HotmData +import at.hannibal2.skyhanni.events.LorenzToolTipEvent +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.round +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.NumberUtil.fractionOf +import at.hannibal2.skyhanni.utils.RegexUtils.matches +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import org.lwjgl.input.Keyboard + +@SkyHanniModule +object PowderPerHotmPerk { + + private val config get() = SkyHanniMod.feature.mining.hotm + + @SubscribeEvent + fun onTooltip(event: LorenzToolTipEvent) { + if (!isEnabled()) return + + val itemName = event.itemStack.displayName + val perk = HotmData.getPerkByNameOrNull(itemName.removeColor()) ?: return + + if (perk.getLevelUpCost() == null) return + + if (config.powderSpent) event.toolTip.add(2, handlePowderSpend(perk)) + if (config.powderFor10Levels) handlePowderFor10Levels(event, perk) + } + + private fun handlePowderFor10Levels(event: LorenzToolTipEvent, perk: HotmData) { + if (!Keyboard.KEY_LSHIFT.isKeyHeld()) return + + val indexOfCost = event.toolTip.indexOfFirst { HotmData.perkCostPattern.matches(it) } + + if (indexOfCost == -1) return + + val powderFor10Levels = + perk.calculateTotalCost(perk.activeLevel + 10) - perk.calculateTotalCost(perk.activeLevel) + + event.toolTip.add(indexOfCost + 2, "§7Powder for 10 levels: §e${powderFor10Levels.addSeparators()}") + } + + private fun handlePowderSpend(perk: HotmData): String { + val currentPowderSpend = perk.calculateTotalCost(perk.activeLevel) + val maxPowderNeeded = perk.totalCostMaxLevel + val percentage = (currentPowderSpend.fractionOf(maxPowderNeeded) * 100).round(2) + + return when (config.powderSpentDesign) { + PowderSpentDesign.NUMBER -> { + if (perk.activeLevel == perk.maxLevel) { + "§7Powder spent: §e${maxPowderNeeded.addSeparators()} §7(§aMax level§7)" + } else { + "§7Powder spent: §e${currentPowderSpend.addSeparators()}§7 / §e${maxPowderNeeded.addSeparators()}" + } + } + + PowderSpentDesign.PERCENTAGE -> { + if (perk.activeLevel == perk.maxLevel) { + "§7Powder spent: §e$percentage% §7(§aMax level§7)" + } else { + "§7Powder spent: §e$percentage%§7 of max" + } + } + + PowderSpentDesign.NUMBER_AND_PERCENTAGE -> { + if (perk.activeLevel == perk.maxLevel) { + "§7Powder spent: §e${maxPowderNeeded.addSeparators()} §7(§aMax level§7)" + } else { + "§7Powder spent: §e${currentPowderSpend.addSeparators()}§7/§e${maxPowderNeeded.addSeparators()}§7 (§e$percentage%§7)" + } + } + } + } + + enum class PowderSpentDesign(val str: String) { + NUMBER("Number"), + PERCENTAGE("Percentage"), + NUMBER_AND_PERCENTAGE("Number and Percentage"); + + override fun toString() = str + } + + private fun isEnabled() = LorenzUtils.inSkyBlock && HotmData.inInventory && + (config.powderSpent || config.powderFor10Levels) +} -- cgit