diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
6 files changed, 100 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 738c3d513..db50a3c7e 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -379,6 +379,7 @@ class SkyHanniMod { loadModule(CompactBestiaryChatMessage()) loadModule(WatchdogHider()) loadModule(AccountUpgradeReminder()) + loadModule(PetExpTooltip()) init() diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java index 630ef9e70..00364cf17 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java @@ -24,6 +24,26 @@ public class MiscConfig { public boolean petDisplay = false; @Expose + @ConfigOption(name = "Pet Experience Tooltip", desc = "Show the currently active pet.") + @ConfigAccordionId(id = 0) + @Accordion + public PetExperienceToolTipConfig petExperienceToolTip = new PetExperienceToolTipConfig(); + + public static class PetExperienceToolTipConfig { + + @Expose + @ConfigOption(name = "Enabled", desc = "Show the full pet exp and the progress to level 100 (ignoring rarity) when hovering over an pet while pressing shift key.") + @ConfigEditorBoolean + public boolean petDisplay = true; + + @Expose + @ConfigOption(name = "Show Always", desc = "Show this info always, even if not pressing shift key.") + @ConfigEditorBoolean + public boolean showAlways = false; + + } + + @Expose public Position petDisplayPos = new Position(-330, -15, false, true); @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/PetExpTooltip.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/PetExpTooltip.kt new file mode 100644 index 000000000..c29387925 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/PetExpTooltip.kt @@ -0,0 +1,50 @@ +package at.hannibal2.skyhanni.features.misc + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.utils.ItemUtils +import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.indexOfFirst +import at.hannibal2.skyhanni.utils.LorenzUtils.round +import at.hannibal2.skyhanni.utils.NumberUtil +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getPetExp +import at.hannibal2.skyhanni.utils.StringUtils +import net.minecraftforge.event.entity.player.ItemTooltipEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class PetExpTooltip { + private val config get() = SkyHanniMod.feature.misc.petExperienceToolTip + + @SubscribeEvent + fun onItemTooltipLow(event: ItemTooltipEvent) { + if (!LorenzUtils.inSkyBlock) return + if (!config.petDisplay) return + if (!LorenzUtils.isShiftKeyDown() && !config.showAlways) return + + val itemStack = event.itemStack ?: return + val petExperience = itemStack.getPetExp()?.round(1) ?: return + val name = itemStack.name ?: return + + val index = event.toolTip.indexOfFirst( + "§5§o§7§eClick to summon!", + "§5§o§7§cClick to despawn!", + "§5§o§7§eRight-click to add this pet to", + ) ?: return + + val maxLevel = ItemUtils.maxPetLevel(name) + val maxXp = if (maxLevel == 200) 210255385 else 25353230L + + val percentage = petExperience / maxXp + val percentageFormat = LorenzUtils.formatPercentage(percentage) + + event.toolTip.add(index, " ") + if (percentage >= 1) { + event.toolTip.add(index, "§7Total experience: §e${NumberUtil.format(petExperience)}") + } else { + val progressBar = StringUtils.progressBar(percentage) + event.toolTip.add(index, "$progressBar §e${petExperience.addSeparators()}§6/§e${NumberUtil.format(maxXp)}") + event.toolTip.add(index, "§7Progress to Level $maxLevel: §e$percentageFormat") + } + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index 4641c566c..2186a6d19 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -474,4 +474,6 @@ object LorenzUtils { javaClass.getDeclaredField("modifiers").makeAccessible().set(this, modifiers and (Modifier.FINAL.inv())) return this } + + fun <T> List<T>.indexOfFirst(vararg args: T) = args.map { indexOf(it) }.firstOrNull { it != -1 } }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt index 77d291d84..385571c56 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt @@ -42,6 +42,8 @@ object SkyBlockItemModifierUtils { fun ItemStack.getDungeonStarCount() = getAttributeInt("upgrade_level") ?: getAttributeInt("dungeon_item_level") + fun ItemStack.getPetExp() = getPetInfo()?.get("exp")?.asDouble + fun ItemStack.getPetCandyUsed(): Int? { val data = cachedData if (data.petCandies == -1) { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt index b4d3d106a..d60a1c9ce 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt @@ -127,4 +127,29 @@ object StringUtils { fun optionalPlural(number: Int, singular: String, plural: String) = "$number " + if (number == 1) singular else plural + + fun progressBar(percentage: Double, steps: Int = 25): Any { + //'§5§o§2§l§m §l§m §l§m §l§m §l§m §l§m §l§m §l§m §l§m §l§m §f§l§m §l§m §l§m §l§m §l§m §l§m §l§m §l§m §l§m §l§m §l§m §l§m §l§m §l§m §l§m §r §e348,144.3§6/§e936k' + val prefix = "§5§o§2" + val step = "§l§m " + val missing = "§f" + val end = "§r" + + val builder = StringBuilder() + var inMissingArea = false + builder.append(prefix) + for (i in 0..steps) { + builder.append(step) + val toDouble = i.toDouble() + val stepPercentage = toDouble / steps + if (stepPercentage > percentage) { + if (!inMissingArea) { + builder.append(missing) + inMissingArea = true + } + } + } + builder.append(end) + return builder.toString() + } }
\ No newline at end of file |