Minecraft Commands - Detecting an item on the ground with a custom tag

Solution 1:

When an item is on the ground, it is an item entity. The data for this entity doesn't store specific information about the item itself, but rather has a tag for the item's data. The data for the item itself is stored under the tag 'Item:{}'.

As for your example, it would work, as the tag is stored on the item correctly. However, you forgot that, when testing for the item entity on the ground, the item entity has an 'Item' data tag that is used to store the data about the item itself. To test for this, you can simply modify the 'nbt={}' tag to account for this, so it would look like:

/execute as @e[type=item,nbt={Item:{tag:{spark:1b}}}] run say test

For the information on the item itself, it goes inside the 'Item' data tag. So, if you wanted to test for a specific item with a specific amount of that item, and with a specific NBT on that item, you could use:

/execute as @e[type=item,nbt={Item:{id:"minecraft:<itemName>",Count:<NumberOfItems>b,tag:{<NBT data of the item>}}}] run say test

Be sure to include the 'b' after the count for the number of items

If you don't want to check for a specific one of these, just leave them out of the 'Item' tag, like I have done with the first command.