diff options
| author | J10a1n15 <45315647+j10a1n15@users.noreply.github.com> | 2024-06-13 20:14:16 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-13 20:14:16 +0200 |
| commit | 045c39701411b5c9a5ffcbffb45ce34c09f1c2c6 (patch) | |
| tree | d32d2be8fbea11ef307891a8778b57e8b4d69789 /src/main/java/at/hannibal2/skyhanni/features/mining | |
| parent | 9eee8c80ee5877ca627c8b545936bf37454fa17e (diff) | |
| download | skyhanni-045c39701411b5c9a5ffcbffb45ce34c09f1c2c6.tar.gz skyhanni-045c39701411b5c9a5ffcbffb45ce34c09f1c2c6.tar.bz2 skyhanni-045c39701411b5c9a5ffcbffb45ce34c09f1c2c6.zip | |
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 <gaidermarkus@gmail.com>
Co-authored-by: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com>
Co-authored-by: martimavocado <martim.cavaco@tutanota.com>
Co-authored-by: Cal <cwolfson58@gmail.com>
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/mining')
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/mining/PowderPerHotmPerk.kt | 90 |
1 files changed, 90 insertions, 0 deletions
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) +} |
