#How to initialize an NBT tag?

54 messages · Page 1 of 1 (latest)

bright narwhal
#

So I have this server script (kill_count.js) that adds an nbt tag to an item, which is elsewhere called for a tooltip on the item. The issue is that due to the way it is set up, it is null before you kill an entity with it, which has been causing some crashes. I was trying to set up a startup script to give the sword the nbt tag and set it to 0 before even loading the world, but that doesn't seem to work.

main ruinBOT
#

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

west gladeBOT
#

Paste version of kill_count.js from @bright narwhal

silent lily
bright narwhal
#
    event.addAdvanced('simplyswords:slumbering_lichblade', (item, advanced, text)=>{
        const killCount = item.nbt.get('killCount')
        text.add(
            Text.of(killCount)
            .append(Text.of('/50'))
        )
    })
});```
#

I added "if(killCount == null) {killCount = 0}" before the text add but it still says null/50 in the tooltip pepethink

west gladeBOT
#

Paste version of message.txt from @bright narwhal

bright narwhal
#

It now crashes immediately whenever I hold the sword

silent lily
bright narwhal
silent lily
#

I wonder if it's the client scripts that caused the crash

bright narwhal
west gladeBOT
#

Paste version of message.txt from @bright narwhal

silent lily
bright narwhal
#

After reloading client scripts yes

#

It only crashes to main menu, not to launcher

silent lily
#

send the entire client script then

bright narwhal
#

Wait no I lied

#

It still crashes when I remove that

#

But it was working before...

bright narwhal
silent lily
#

Do you have any other scripts related to the swords?

bright narwhal
west gladeBOT
#

Paste version of unbreakable_weapons.js from @bright narwhal

silent lily
#

why do you set it to 0?

bright narwhal
#

It seemed to function to make it unbreakable

#

Is that not expected?

#

Ope no the crash was from the damage modification script I made based on your example script

#

I made a dumb error

silent lily
#

what error?

bright narwhal
#

Had a typo in the word 'addition'🤦

west gladeBOT
#

Paste version of damage_modification.js from @bright narwhal

bright narwhal
#

I thought it would but then the 5 and 2 are just getting added to the original attack damage, I can't seem to set it lower

silent lily
#

you can set it to minus number

#

like -1

bright narwhal
#

I see

#

And then the remove is not needed?

silent lily
#

oh, btw, the remove part syntax is not correct

bright narwhal
#

Can't do Ingredient.of for an array? Or what

silent lily
#
attributes.remove(Ingredient.of(['simplyswords:slumbering_lichblade', 'simplyswords:waking_lichblade']), 'minecraft:generic.attack_damage')
#

you need to put the array into Ingredient.of(...)

#

The [] cannot replace ()

#

And I just tested it, setting the maxDamage to 0 or -1 can cause the item to become unenchantable.

#

If you don't want that to happen, another method to make it unbreakable is to add this in server script

ItemEvents.firstLeftClicked("minecraft:diamond_sword", event => { //replace the "minecraft:diamond_sword" with the swords you want
    event.item.setDamageValue(0)
})
bright narwhal
#

In this case it is working for me to enchant it, at least with sharpness

silent lily
#

anvil enchantment would work, but enchant table would not

bright narwhal
#

I see

#

Thank you