aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/util/SkyblockId.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-09-17 23:15:41 +0200
committerLinnea Gräf <nea@nea.moe>2025-09-17 23:15:41 +0200
commit2b02a861a6f9a39c766dd4be18f30abefa2d9aec (patch)
tree16ac5250cea13bc45390616ce0b7f3cd1d6346a0 /src/main/kotlin/util/SkyblockId.kt
parent21817efdfe62135704571908b9f72ed3ace4bdf1 (diff)
downloadFirmament-2b02a861a6f9a39c766dd4be18f30abefa2d9aec.tar.gz
Firmament-2b02a861a6f9a39c766dd4be18f30abefa2d9aec.tar.bz2
Firmament-2b02a861a6f9a39c766dd4be18f30abefa2d9aec.zip
feat: add skyblock ids into bazaar
Diffstat (limited to 'src/main/kotlin/util/SkyblockId.kt')
-rw-r--r--src/main/kotlin/util/SkyblockId.kt30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/main/kotlin/util/SkyblockId.kt b/src/main/kotlin/util/SkyblockId.kt
index 07d4c30..43a9084 100644
--- a/src/main/kotlin/util/SkyblockId.kt
+++ b/src/main/kotlin/util/SkyblockId.kt
@@ -29,11 +29,14 @@ import net.minecraft.util.Identifier
import moe.nea.firmament.repo.ExpLadders
import moe.nea.firmament.repo.ExpensiveItemCacheApi
import moe.nea.firmament.repo.ItemCache.asItemStack
+import moe.nea.firmament.repo.ItemNameLookup
import moe.nea.firmament.repo.RepoManager
import moe.nea.firmament.repo.set
import moe.nea.firmament.util.collections.WeakCache
import moe.nea.firmament.util.json.DashlessUUIDSerializer
+import moe.nea.firmament.util.mc.displayNameAccordingToNbt
import moe.nea.firmament.util.mc.loreAccordingToNbt
+import moe.nea.firmament.util.skyblock.isBazaarUi
/**
* A SkyBlock item id, as used by the NEU repo.
@@ -142,7 +145,7 @@ fun ItemStack.modifyExtraAttributes(block: (NbtCompound) -> Unit) {
set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(baseNbt))
}
-val ItemStack.skyblockUUIDString: String?
+val ItemStack.skyBlockUUIDString: String?
get() = extraAttributes.getString("uuid").getOrNull()?.takeIf { it.isNotBlank() }
private val timestampFormat = //"10/11/21 3:39 PM"
@@ -170,7 +173,7 @@ val ItemStack.timestamp
}
val ItemStack.skyblockUUID: UUID?
- get() = skyblockUUIDString?.let { UUID.fromString(it) }
+ get() = skyBlockUUIDString?.let { UUID.fromString(it) }
private val petDataCache = WeakCache.memoize<ItemStack, Optional<HypixelPetInfo>>("PetInfo") {
val jsonString = it.extraAttributes.getString("petInfo")
@@ -219,16 +222,31 @@ fun ItemStack.getLogicalStackSize(): Long {
} ?: AMOUNT_REGEX.useMatch(string) {
parseShortNumber(group(1)).toLong()
} ?: COMPOST_REGEX.useMatch(string) {
- parseShortNumber(group(1)).toLong()
- }
+ parseShortNumber(group(1)).toLong()
+ }
} ?: count.toLong()
}
+val ItemStack.rawSkyBlockId: String? get() = extraAttributes.getString("id").getOrNull()
+
+fun ItemStack.guessContextualSkyBlockId(): SkyblockId? {
+ if (MC.screen?.isBazaarUi() == true) {
+ val name = displayNameAccordingToNbt.unformattedString
+ .replaceFirst("SELL ", "")
+ .replaceFirst("BUY ", "")
+ if (item == Items.ENCHANTED_BOOK) {
+ return RepoManager.enchantedBookCache.byName[name]
+ }
+ return ItemNameLookup.guessItemByName(name, false)
+ }
+ return null
+}
+
val ItemStack.skyBlockId: SkyblockId?
get() {
- return when (val id = extraAttributes.getString("id").getOrNull()) {
+ return when (val id = rawSkyBlockId) {
"", null -> {
- null
+ guessContextualSkyBlockId()
}
"PET" -> {