2

I am working on a command block contraption on my server that involves armor giving you certain potion effects.

/execute if entity @p[nbt={Inventory[{Slot:100b,id:"minecraft:leather_boots",tag:{display:{Name:"{\"text\":\"Frog Boots\"}"}}}]}] run effect give @s jump_boost 1 1 true

However, it only works if the boots are named in an anvil. How would I write the command if I wanted to test if the player was wearing boots named "Frog Boots" in bold and green text?

2 Answers 2

3

The NBT syntax for testing for an item with a certain name is exactly the same as the NBT syntax for giving a player an item with that name. Thus, if you give a player boots using the command:

/give <player> leather_boots{display:{Name:"{\"text\":\"Frog Boots\",\"color\":\"green\",\"bold\":true}"}}

(per my answer to Colored item names in Minecraft?), you check if the player is wearing those boots using the command:

/execute if entity @p[nbt={Inventory:[{Slot:100b,id:"minecraft:leather_boots",tag:{display:{Name:"{\"text\":\"Frog Boots\",\"color\":\"green\",\"bold\":true}"}}}]}] run ...

You can figure out the exact NBT name of an item by selecting it, and running the command:

/data get entity @s SelectedItem.tag.display.Name
2
  • I don’t know how to use the items data, and use it in an execute command. I’ve tried /execute if entity @p[nbt={Inventory:[{Slot:100b,id:"minecraft:leather_boots",tag:{Display:{Name:"{\"text\":\"Frog Boots\",\"color\":\"green\",\"bold\":true}"}}}]}] but it doesn’t seem to work May 6, 2020 at 16:37
  • Try using the second command listed by @pppery but with @a instead of @p because @p only checks the nearest player relative to the command block (or the player typing the command) also @a is compatible with more than one player using the item.
    – Firestryke
    Jun 3, 2020 at 19:19
2

Answer from the OP, posted in the question body:


I found out you can test if the player is wearing dyed armor, so I’m doing that instead.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .