0

I don't think this has been asked, if it is, I'm sorry.

I've done some looking, and I can't figure out how to add tags to items. I've tried this: /give @p shield{display:{Name:'[{"text":"Custom Shield","italic":false,"color":"dark_red","bold":true}]',Lore:['[{"text":"Force Field","italic":false,"color":"#ff6600"}]','[{"text":"Saftey","italic":false,"color":"#ff6600"}]'],forcefield:1b}} 1 as well as /give @p shield{display:{Name:'[{"text":"Custom Shield","italic":false,"color":"dark_red","bold":true}]',Lore:['[{"text":"Force Field","italic":false,"color":"#ff6600"}]','[{"text":"Saftey","italic":false,"color":"#ff6600"}]'],tag:[forcefield]}} 1.

I'm not sure what I did wrong, but I also can't detect the tags. I've tried detection like this: execute as @a[scores={souls=1..},nbt={Inventory:[{Slot:-106b,id:"minecraft:shield",forcefield:1b}]}] run function kits:forcefieldenchant as well as like this:execute as @a[scores={souls=1..},nbt={Inventory:[{Slot:-106b,id:"minecraft:shield",tag:["forcefield"]}]}] run function kits:forcefieldenchant

I'm not sure where I went wrong, but any help would be very much appreciated. Thanks in advance!

2 Answers 2

0

In order for testing for NBT to work, the NBT you provide in the command has to match the NBT Minecraft stores for the player exactly, or the command will not work. The first command does not work because data tags for NBT need to go in a tag called tag and you set forceField:1b inside the display tag and test for it outside the display tag. Fixing those two errors produces the command:

/execute as @a[scores={souls=1..},nbt={Inventory:[{Slot:-106b,id:"minecraft:shield",tag:{display:{forcefield:1b}}}]}] run function kits:forcefieldenchant
0

The first thing that you should know is that custom tags on items are not the same as how tags are applied to items. Technically, there is no official tagging system for items, but the system allows you to add your own custom NBT to items, whereas everywhere else it is stripped.

The first thing we always do with any NBT problem is expand your data in your commands. We'll reference it in the troubleshooting:

{
    display:{
        Name:'[{"text":"Custom Shield","italic":false,"color":"dark_red","bold":true}]',
        Lore:[
            '[{"text":"Force Field","italic":false,"color":"#ff6600"}]',
            '[{"text":"Saftey","italic":false,"color":"#ff6600"}]'
        ],
        forcefield:1b
    }
}
{
    display:{
        Name:'[{"text":"Custom Shield","italic":false,"color":"dark_red","bold":true}]',
        Lore:[
            '[{"text":"Force Field","italic":false,"color":"#ff6600"}]',
            '[{"text":"Saftey","italic":false,"color":"#ff6600"}]'
        ],
        tag:[
            forcefield
        ]
    }
}
{
    Inventory:[
        {
            Slot:-106b,
            id:"minecraft:shield",
            forcefield:1b
        }
    ]
}
{
    Inventory:[
        {
            Slot:-106b,
            id:"minecraft:shield",
            tag:[
                "forcefield"
            ]
        }
    ]
}

The closest you were to the correct test is your test #4, and the problem is that the tag tag is incorrect. Look at the definition on the Minecraft Wiki:

tag: Additional information about the item, discussed more in the subsections of the item structure section. This tag is optional for most items. Unlike other entity or block NBT, this tag is never deserialized and can hold user defined tags that are not used by the game by standard.

In layman's terms, the tag compound is not an express route to your custom tags, it is just a similar name, and under it is all the item data, such as custom name, lore, and your tags.

Fixed NBT for the checks:

{
    Inventory:[
        {
            Slot:-106b,
            id:"minecraft:shield",
            tag:{
                display:{
                    forcefield:1b
                }
            }
        }
    ]
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.