#Add a nbt tag for a item

10 messages · Page 1 of 1 (latest)

tribal knoll
#

Can someone help me add the 'owner' and 'color' tags to the item?

    if (event.item && event.item.id === 'hardium:id_card') {
        if (!event.item.nbt && event.player && event.player.isCrouching()) {
            let data = event.item.getNBTData();
            let ownerName = event.player.name.text;

            event.player.swingArm(event.hand);

            data.tag.owner = ownerName;
            data.tag.color = '#4287f5';

            event.item.setNBTData(data);
            event.player.playSound('ui.cartography_table.take_result');
            event.player.setStatusMessage("§7Check§r");
        }        
    }
});```
digital boughBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

hot swift
#

do /kjs hand and post the nbt tag in here

tulip swift
#

To get nbt it would be event.item.nbt Not .nbtData and then Ou can do event.item.nbt = {owner: "name", color: "#359261"}

tribal knoll
tribal knoll
tulip swift
#

Yes, in that case you need to do something more logic

#

It it already has nbt you can do event.item.nbt.owner = "name" tho this will Break If the Item doesn't have nbt yet

#

So you need to Check that with event.item.nbt == null

#

There's also .mergeNbt() which allows you to supply a new nbt as the First Argument and the nbt will be combined, this also only works if nbt exist already aswell