How to make an armor that gives you potion effects?
-
I'm confused about the tag part of the command, I don't know what tag my item has. The item has been renamed.
This is the command I'm using:
execute as @a if entity @s [nbt={Inventory:[{Slot:102b,id:"minecraft:leather_tunic", tag:{Tags:["**I do not know what the tag is**"], display:{Name:"{\"text\":\"Stealth Chestplate\"}"}}}]}] run effect give @s minecraft:invisibility 1 1
-
Using the stuff I found https://gaming.stackexchange.com/questions/226838/how-can-i-detect-if-a-player-is-wearing-a-specific-piece-of-armour , I figured out how to do this.
First, you need the item with the appropriate tag.
give @s chainmail_chestplate{tag:{Tags:[sneaky]}}
How tags work in datapacks is they allow commands to locate and isolate items from other items. Datapacks cannot add new content, only modify to make it appear to be differing from it's parent item. All your other NBT data (renaming, lore, enchantments, etc) still work with tags. They are just more reliable when it comes to locating where an item is and who has it.
Now that you have the item with the appropriate tag, we can now detect and execute.
execute as @e[nbt={Inventory:[{id:"minecraft:chainmail_chestplate", tag:{Tags:[sneaky]}, Slot: 102b}]}] run **The effect command with desired effect**
I used the
@e
target selector so you can use this item on zombies, skeletons, etc. But if this is a player-only item you should change the selector to@a
.