aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/util')
-rw-r--r--src/main/kotlin/util/SkyblockId.kt14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/main/kotlin/util/SkyblockId.kt b/src/main/kotlin/util/SkyblockId.kt
index 03b8bf4..2a0c477 100644
--- a/src/main/kotlin/util/SkyblockId.kt
+++ b/src/main/kotlin/util/SkyblockId.kt
@@ -33,6 +33,7 @@ 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.loreAccordingToNbt
/**
* A SkyBlock item id, as used by the NEU repo.
@@ -204,6 +205,19 @@ fun ItemStack.setSkyBlockId(skyblockId: SkyblockId): ItemStack {
return this
}
+private val STORED_REGEX = "Stored: ($SHORT_NUMBER_FORMAT)/.+".toPattern()
+private val AMOUNT_REGEX = "(?:Offer amount|Amount|Order amount): ($SHORT_NUMBER_FORMAT)x".toPattern()
+fun ItemStack.getLogicalStackSize(): Long {
+ return loreAccordingToNbt.firstNotNullOfOrNull {
+ val string = it.unformattedString
+ STORED_REGEX.useMatch(string) {
+ parseShortNumber(group(1)).toLong()
+ } ?: AMOUNT_REGEX.useMatch(string) {
+ parseShortNumber(group(1)).toLong()
+ }
+ } ?: count.toLong()
+}
+
val ItemStack.skyBlockId: SkyblockId?
get() {
return when (val id = extraAttributes.getString("id").getOrNull()) {