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

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)
}