diff options
author | nea <nea@nea.moe> | 2023-07-11 21:01:58 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-07-11 21:01:58 +0200 |
commit | 4d93f475aadc42c4bf83c3a0749af41659235c71 (patch) | |
tree | c8e01710defe66e06c50fa962c72fdac66a35a1f /src/main/kotlin/moe/nea/firmament/util/item | |
parent | 4444fcca44d9a53c8162d69e0e9f19fd214c2f54 (diff) | |
download | firmament-4d93f475aadc42c4bf83c3a0749af41659235c71.tar.gz firmament-4d93f475aadc42c4bf83c3a0749af41659235c71.tar.bz2 firmament-4d93f475aadc42c4bf83c3a0749af41659235c71.zip |
Bulk commit
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/util/item')
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/util/item/NbtItemData.kt | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/util/item/NbtItemData.kt b/src/main/kotlin/moe/nea/firmament/util/item/NbtItemData.kt new file mode 100644 index 0000000..2e721d8 --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/util/item/NbtItemData.kt @@ -0,0 +1,18 @@ +package moe.nea.firmament.util.item + +import net.minecraft.item.ItemStack +import net.minecraft.nbt.NbtElement +import net.minecraft.nbt.NbtString +import net.minecraft.text.Text + +val ItemStack.loreAccordingToNbt + get() = getOrCreateSubNbt(ItemStack.DISPLAY_KEY).getList(ItemStack.LORE_KEY, NbtElement.STRING_TYPE.toInt()) + .map { Text.Serializer.fromJson((it as NbtString).asString()) } + +val ItemStack.displayNameAccordingToNbt + get() = getOrCreateSubNbt(ItemStack.DISPLAY_KEY).let { + if (it.contains(ItemStack.NAME_KEY, NbtElement.STRING_TYPE.toInt())) + Text.Serializer.fromJson(it.getString(ItemStack.NAME_KEY)) + else + null + } |