-1

I want to detect an item on the ground with a custom tag (e.g. spark:1b). I run this command:

/give @p blaze_rod{spark:1b} 1

Then I throw it on the ground and run this command:

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

But nothing happens. How do I detect items (on the ground) with custom tags?

  • 1
    Does this work when you an existing NBT tag, like CustomName? My guess would be no, since I don't think items can say anything. Also, are you sure the custom tag still exists on the item when you throw it? Again, my guess would be that it doesn't. – MBraedley Apr 26 '19 at 18:26
  • The first one should work ("say" isn't something limited to certain entities), second one not. I'm pretty sure you can't just put anything into NBT. – Fabian Röling Apr 26 '19 at 20:22
  • 1
    @FabianRöling You can, those are called custom tags, and you can set either a numerical value (spark:3), or a bool value (spark:1b). Both are detectable using the nbt selector. – Roqubot Apr 26 '19 at 21:10
  • The b stands for byte, not bool, it stores 8 bits. There are no actual boolean values stored in Minecraft NBT, although some values may have their range limited to be between 0 and 1. – MBraedley Apr 27 '19 at 14:33
2

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.

  • Thank you! I didn't consider that entities might have a separate data tag for item data. – Roqubot Apr 26 '19 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.