Minecraft – How to search for a specific item with attributes

minecraft-commandsminecraft-java-edition

I want to test if a player has the following item:

minecraft:bow 1 0 {display:{Name:Bow I},ench:[{id:48,lvl:1}]}

A bow with a name of "Bow 1" and has a Power I enchantment.

I know this command works with normal items:

/testfor @p {Inventory:[{id:"minecraft:bow"}]}

I don't know how to add the attributes. Is it possible to search for a specific item name? For example, test to see if I have the item "Bow I" in my inventory?

Best Answer

You have to nest additional data tags in tag compound:

/testfor @p {Inventory:[{id:"minecraft:bow",tag:{display:{Name:"Bow I"},ench:[{id:48,lvl:1}]}}]}

Learn more about item format here.