Minecraft – Problem with /execute at specific items

minecraft-commandsminecraft-java-edition

After messing around a bit I made this command, designed to say “Doot” whenever I drop an iron ingot (I intend to make it do other things later on).
However, something isn't working as supposed (it's snapshot by the way, so new command standards).

/execute at @e[type=item,nbt={Item:{id:"iron_ingot",Count:1,tag:{display:{Name:"{\"text\":\"Doot\"}"}}}}] run say doot

I know the items tags are working because this command works flawlessly:

/summon item ~ ~-3 ~ {Item:{id:"iron_ingot",Count:1,tag:{display:{Name:"{\"text\":\"Doot\"}"}}}}

So my problem is with /execute. It doesn't give any error logs nor any results. I believe the problem is with the @e[type=item,nbt=<-Here

Is the problem solvable or is the command invalid? Or should I just use scoreboard? (Never got around learning that.)

Best Answer

Minecraft will auto-fix some things for you when setting data, but when testing data you need to test for the NBT exactly as it exists.

You'll need to specify the namespace of IDs (minecraft:iron_ingot) and the correct data type of numbers (Count is a byte). The following command should work:

/execute at @e[type=item,nbt={Item:{id:"minecraft:iron_ingot",Count:1b,tag:{display:{Name:"{\"text\":\"Doot\"}"}}}}] run say doot

A good way to check the NBT data that something has is with /data get:

/data get entity @e[type=item,limit=1,sort=nearest]