aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNetheriteMiner <88792142+NetheriteMiner@users.noreply.github.com>2023-06-19 05:34:35 -0400
committerGitHub <noreply@github.com>2023-06-19 11:34:35 +0200
commitee7cd18b8c40d3fbb2825ff5c7178c22307d2698 (patch)
tree48179a8c611df58258b763910548b5a65548e119
parentb8e2d8cfc6ed0c5a3dfa0f36f1eb9c8b6ed028f8 (diff)
downloadskyhanni-ee7cd18b8c40d3fbb2825ff5c7178c22307d2698.tar.gz
skyhanni-ee7cd18b8c40d3fbb2825ff5c7178c22307d2698.tar.bz2
skyhanni-ee7cd18b8c40d3fbb2825ff5c7178c22307d2698.zip
Add more details to "Profile" and add "Stacking" to Rich Presence (#234)
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/Misc.java16
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt150
2 files changed, 148 insertions, 18 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java b/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java
index a5f37352d..ef99c5d90 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java
@@ -1,10 +1,10 @@
package at.hannibal2.skyhanni.config.features;
-import at.hannibal2.skyhanni.config.core.config.Position;
-import com.google.gson.annotations.Expose;
+import at.hannibal2.skyhanni.config.core.config.*;
+import com.google.gson.annotations.*;
import io.github.moulberry.moulconfig.annotations.*;
-import io.github.moulberry.moulconfig.observer.Property;
-import org.lwjgl.input.Keyboard;
+import io.github.moulberry.moulconfig.observer.*;
+import org.lwjgl.input.*;
import java.util.ArrayList;
import java.util.List;
@@ -269,7 +269,7 @@ public class Misc {
"Stats",
"Held Item",
"Skyblock Date",
- "Profile (Fruit)",
+ "Profile",
"Slayer",
"Custom",
"Dynamic",
@@ -288,7 +288,7 @@ public class Misc {
"Stats",
"Held Item",
"Skyblock Date",
- "Profile (Fruit)",
+ "Profile",
"Slayer",
"Custom",
"Dynamic",
@@ -303,7 +303,7 @@ public class Misc {
public Property<String> customText = Property.of("");
@Expose
- @ConfigOption(name = "Dynamic", desc = "\"Dynamic\" above shows your Crop Milestone or Slayer progress while doing those, but this if you're doing neither.")
+ @ConfigOption(name = "Dynamic", desc = "\"Dynamic\" above shows your Crop Milestone, Slayer progress, or Stacking enchantment when possible, but this if you're doing none of them.")
@ConfigEditorDropdown(values = {
"Nothing",
"Location",
@@ -312,7 +312,7 @@ public class Misc {
"Stats",
"Held Item",
"Skyblock Date",
- "Profile (Fruit)",
+ "Profile",
"Slayer",
"Custom",
"Crop Milestone",
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt
index 9cf02c07d..8bd590cf2 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt
@@ -16,8 +16,12 @@ import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.colorCodeToRarity
import at.hannibal2.skyhanni.utils.StringUtils.firstLetterUppercase
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
+import at.hannibal2.skyhanni.utils.TabListData.Companion.getTabList
import io.github.moulberry.notenoughupdates.miscfeatures.PetInfoOverlay.getCurrentPet
import io.github.moulberry.notenoughupdates.util.SkyBlockTime
+import net.minecraft.client.Minecraft
+import net.minecraft.item.ItemStack
+import net.minecraft.nbt.NBTTagCompound
import java.util.function.Supplier
import java.util.regex.Pattern
@@ -27,6 +31,49 @@ var lastKnownDisplayStrings: MutableMap<DiscordStatus, String> =
val purseRegex = Regex("""(?:Purse|Piggy): ([\d,]+)[\d.]*""")
val bitsRegex = Regex("""Bits: ([\d|,]+)[\d|.]*""")
+val stackingEnchants = mapOf(
+ "compact" to mapOf(
+ "levels" to listOf(0, 100, 500, 1500, 5000, 15000, 50000, 150000, 500000, 1000000),
+ "nbtNum" to "compact_blocks"
+ ),
+ "cultivating" to mapOf(
+ "levels" to listOf(
+ 0,
+ 1000,
+ 5000,
+ 25000,
+ 100000,
+ 300000,
+ 1500000,
+ 5000000,
+ 20000000,
+ 100000000
+ ), "nbtNum" to "farmed_cultivating"
+ ),
+ "expertise" to mapOf(
+ "levels" to listOf(0, 50, 100, 250, 500, 1000, 2500, 5500, 10000, 15000),
+ "nbtNum" to "expertise_kills"
+ ),
+ "hecatomb" to mapOf(
+ "levels" to listOf(0, 2, 5, 10, 20, 30, 40, 60, 80, 100),
+ "nbtNum" to "hecatomb_s_runs"
+ ),
+ "champion" to mapOf(
+ "levels" to listOf(
+ 0,
+ 50000,
+ 100000,
+ 250000,
+ 500000,
+ 1000000,
+ 1500000,
+ 2000000,
+ 2500000,
+ 3000000
+ ), "nbtNum" to "champion_combat_xp"
+ )
+) // nbtNum is the id of the enchantment in the nbt data
+
enum class DiscordStatus(private val displayMessageSupplier: Supplier<String>?) {
NONE(null),
@@ -54,7 +101,7 @@ enum class DiscordStatus(private val displayMessageSupplier: Supplier<String>?)
val scoreboard = ScoreboardData.sidebarLinesFormatted
// Matches coins amount in purse or piggy, with optional decimal points
val coins = scoreboard.firstOrNull { purseRegex.matches(it.removeColor()) }?.let {
- purseRegex.find(it.removeColor())?.groupValues?.get(1)
+ purseRegex.find(it.removeColor())?.groupValues?.get(1) ?: ""
}
if (coins == "1") {
lastKnownDisplayStrings[PURSE] = "1 Coin"
@@ -69,6 +116,7 @@ enum class DiscordStatus(private val displayMessageSupplier: Supplier<String>?)
val bits = scoreboard.firstOrNull { bitsRegex.matches(it.removeColor()) }?.let {
bitsRegex.find(it.removeColor())?.groupValues?.get(1)
}
+
when (bits) {
"1" -> "1 Bit"
null -> "0 Bits"
@@ -119,7 +167,36 @@ enum class DiscordStatus(private val displayMessageSupplier: Supplier<String>?)
}),
PROFILE({
- HypixelData.profileName.firstLetterUppercase()
+ val player = LorenzUtils.getPlayerName()
+
+ val tabData = getTabList()
+ val levelRegex = Regex("""\[(\d{1,3})] $player""")
+ var sbLevel = ""
+// SkyBlock Level: [999] on Lemon
+ for (line in tabData) {
+ if (line.contains(player)) {
+ val colorlessLine = line.removeColor()
+ sbLevel = levelRegex.find(colorlessLine)!!.groupValues[1]
+ break
+ }
+ }
+
+ var profile = "SkyBlock Level: [$sbLevel] on "
+
+ profile += (
+ if (HypixelData.ironman) "♲"
+ else if (HypixelData.bingo) "Ⓑ"
+ else if (HypixelData.stranded) "☀"
+ else ""
+ )
+
+ val fruit = HypixelData.profileName.firstLetterUppercase()
+ if (fruit == "") profile =
+ lastKnownDisplayStrings[PROFILE] ?: "SkyBlock Level: [$sbLevel]" // profile fruit has not loaded in yet
+ else profile += fruit
+
+ lastKnownDisplayStrings[PROFILE] = profile
+ profile
}),
SLAYER({
@@ -152,13 +229,11 @@ enum class DiscordStatus(private val displayMessageSupplier: Supplier<String>?)
AUTO({
val slayerResult = SLAYER.displayMessageSupplier!!.get()
- val milestoneResult = try {
- CROP_MILESTONES.displayMessageSupplier!!.get()
- } catch (e: Exception) {
- "Unable to get milestone"
- }
+ val stackingResult = STACKING.displayMessageSupplier!!.get()
+ val milestoneResult = CROP_MILESTONES.displayMessageSupplier!!.get()
if (slayerResult != "Planning to do a slayer quest") slayerResult
- else if (milestoneResult != "Unable to get milestone" && milestoneResult != "Unknown Item" && milestoneResult != "") milestoneResult
+ else if (milestoneResult != "Not farming!") milestoneResult
+ else if (stackingResult != "") stackingResult
else {
val statusNoAuto = DiscordStatus.values().toMutableList()
statusNoAuto.remove(AUTO)
@@ -176,9 +251,10 @@ enum class DiscordStatus(private val displayMessageSupplier: Supplier<String>?)
} ?: 100 // percentage to next milestone
if (tier != null) {
- lastKnownDisplayStrings[CROP_MILESTONES] = tier.let { "${crop.cropName}: Milestone $it ($progress)" }
+ "${crop.cropName}: Milestone $tier ($progress)"
+ } else {
+ "Not farming!"
}
- lastKnownDisplayStrings[CROP_MILESTONES] ?: ""
}),
PETS({
@@ -189,6 +265,60 @@ enum class DiscordStatus(private val displayMessageSupplier: Supplier<String>?)
"[Lvl $petLevel] ${colorCodeToRarity(colorCode)} $petName"
} ?: "No pet equipped"
+ }),
+
+ // Dynamic-only
+ STACKING({
+ // Logic for getting the currently held stacking enchant is from Skytils, except for getExtraAttributes() which they got from BiscuitDevelopment
+
+
+ fun getExtraAttributes(item: ItemStack?): NBTTagCompound? {
+ return if (item == null || !item.hasTagCompound()) {
+ null
+ } else item.getSubCompound("ExtraAttributes", false)
+ }
+
+ val extraAttributes = getExtraAttributes(Minecraft.getMinecraft().thePlayer.inventory.getCurrentItem())
+
+ fun getProgressPercent(amount: Int, levels: List<Int>): String {
+ var currentLevel = 0
+ var percent = ""
+ for (level in levels.indices) {
+ if (amount > levels[level]) {
+ currentLevel++
+ continue
+ }
+ percent = if (amount.toDouble() == 0.0) {
+ ""
+ } else {
+ LorenzUtils.formatPercentage((amount.toDouble() - levels[level - 1]) / (levels[level] - levels[level - 1]))
+ }
+ break
+ }
+ return percent
+ }
+
+ var stackingReturn = ""
+ if (extraAttributes != null) {
+ val enchantments = extraAttributes.getCompoundTag("enchantments")
+ var stackingEnchant = ""
+ for (enchant in stackingEnchants.keys) {
+ if (extraAttributes.hasKey(stackingEnchants[enchant]?.get("nbtNum").toString())) {
+ stackingEnchant = enchant
+ break
+ }
+ }
+ val levels = stackingEnchants[stackingEnchant]?.get("levels") as? List<Int> ?: listOf(0)
+ val level = enchantments.getInteger(stackingEnchant)
+ val amount = extraAttributes.getInteger(stackingEnchants[stackingEnchant]?.get("nbtNum").toString())
+ val stackingPercent = getProgressPercent(amount, levels)
+
+ stackingReturn =
+ if (stackingPercent == "" || amount == 0) "" // outdated info is useless for AUTO; empty strings are manually ignored
+ else "${stackingEnchant.firstLetterUppercase()} $level ($stackingPercent)" // Hecatomb 100: (55.55%)
+ }
+ stackingReturn
+
})
;