diff options
author | Linnea Gräf <nea@nea.moe> | 2024-11-27 16:06:52 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-11-27 16:06:52 +0100 |
commit | c41488139136c213fd5d799523da5f318a0014a2 (patch) | |
tree | 7ac8ab40bf7e8bd289c6c081f9d65c3f4749aed1 /src/main/kotlin/util | |
parent | ee0526ac67e093f77d17747d9316765b2db272a2 (diff) | |
download | Firmament-c41488139136c213fd5d799523da5f318a0014a2.tar.gz Firmament-c41488139136c213fd5d799523da5f318a0014a2.tar.bz2 Firmament-c41488139136c213fd5d799523da5f318a0014a2.zip |
feat: Add item type function
Diffstat (limited to 'src/main/kotlin/util')
-rw-r--r-- | src/main/kotlin/util/skyblock/AbilityUtils.kt | 1 | ||||
-rw-r--r-- | src/main/kotlin/util/skyblock/ItemType.kt | 40 |
2 files changed, 31 insertions, 10 deletions
diff --git a/src/main/kotlin/util/skyblock/AbilityUtils.kt b/src/main/kotlin/util/skyblock/AbilityUtils.kt index 0f0adbe..0d7d2b7 100644 --- a/src/main/kotlin/util/skyblock/AbilityUtils.kt +++ b/src/main/kotlin/util/skyblock/AbilityUtils.kt @@ -131,6 +131,7 @@ object AbilityUtils { return abilities } + // TODO: memoize fun getAbilities(itemStack: ItemStack): List<ItemAbility> { return getAbilities(itemStack.loreAccordingToNbt) } diff --git a/src/main/kotlin/util/skyblock/ItemType.kt b/src/main/kotlin/util/skyblock/ItemType.kt index 7d53c0d..b031b69 100644 --- a/src/main/kotlin/util/skyblock/ItemType.kt +++ b/src/main/kotlin/util/skyblock/ItemType.kt @@ -1,21 +1,41 @@ package moe.nea.firmament.util.skyblock -import kotlin.properties.ReadOnlyProperty -import kotlin.reflect.KProperty +import net.minecraft.item.ItemStack +import moe.nea.firmament.util.directLiteralStringContent +import moe.nea.firmament.util.mc.loreAccordingToNbt +import moe.nea.firmament.util.petData -class ItemType(val name: String) { +@JvmInline +value class ItemType private constructor(val name: String) { companion object { - private val generated = object : ReadOnlyProperty<Any?, ItemType> { - override fun getValue(thisRef: Any?, property: KProperty<*>): ItemType { - return ItemType.ofName(property.name) - } - } - fun ofName(name: String): ItemType { return ItemType(name) } - val SWORD by generated + fun fromItemStack(itemStack: ItemStack): ItemType? { + if (itemStack.petData != null) + return PET + val typeText = + itemStack.loreAccordingToNbt.lastOrNull() + ?.siblings?.find { + !it.style.isObfuscated && !it.directLiteralStringContent.isNullOrBlank() + }?.directLiteralStringContent + if (typeText != null) { + val type = typeText.substringAfter(' ', missingDelimiterValue = "").trim() + if (type.isEmpty()) return null + return ofName(type) + } + return null + } + + val SWORD = ofName("SWORD") + val DRILL = ofName("DRILL") + val PICKAXE = ofName("PICKAXE") + + /** + * This one is not really official (it never shows up in game). + */ + val PET = ofName("PET") } } |