Execute as player wearing tagged armor [duplicate]
Solution 1:
To detect the player wearing the armor, we'll want to test for the tag in the actual slot itself. Adding the Slot
criteria to the nbt selector, we can test for the tag specifically in that one slot.
/execute as @a[nbt={Inventory:[{Slot:102b,tag:{Tags:["TagName"]}}]}] run say hi
The inventory IDs are:
103 : Head / Helmet
102 : Chest / Chestplate
101 : Legs / Leggings
100 : Feet / Boots
You can find the rest of the slot IDs here: https://minecraft.gamepedia.com/Inventory
Solution 2:
Scoreboard tags that you may give to an item entity with /tag
will disappear once the item is picked up, you can use custom NBT tags though.
You can give yourself a tagged iron helmet with this command:
/give @s minecraft:iron_helmet{customTag:1}
You can use this command to execute as every player who has an item with customTag:1
in the head slot:
/execute as @a[nbt={Inventory:[{Slot:103b,tag:{customTag:1}}]}] run say hi
You have to use a different number for the slot depending on what slot the item is supposed to be in. You can figure out the ID by first clearing your inventory and placing an item in that slot. Then run /data get entity @s Inventory
and you will get all the information about that slot and the item.
The armor slot IDs are 100b
for boots, 101b
for leggings, 102b
for elytras or chestplates, and 103b
for helmets or mobheads.