aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/util/item/NbtItemData.kt
blob: f7f259d7a39f086f30ebfe791b6f38bd80141cfe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package moe.nea.firmament.util.item

import net.minecraft.component.DataComponentTypes
import net.minecraft.component.type.LoreComponent
import net.minecraft.item.ItemStack
import net.minecraft.text.Text

var ItemStack.loreAccordingToNbt
    get() = get(DataComponentTypes.LORE)?.lines ?: listOf()
    set(value) {
        set(DataComponentTypes.LORE, LoreComponent(value))
    }

var ItemStack.displayNameAccordingToNbt: Text
    get() = get(DataComponentTypes.CUSTOM_NAME) ?: get(DataComponentTypes.ITEM_NAME) ?: item.name
    set(value) {
        set(DataComponentTypes.CUSTOM_NAME, value)
    }

fun ItemStack.setCustomName(text: Text) {
    set(DataComponentTypes.CUSTOM_NAME, text)
}