Minecraft – Can you tell if a specific item is dropped? What about its name

minecraft-bedrock-editionminecraft-commands

In Java Edition, I can test for a dropped item on the floor by using NBT:

/execute if entity @e[type=item,nbt={Item:{id:"minecraft:green_wool"}}]

But in Bedrock Edition, NBT is inaccessible from commands. Is there still a way to test for a dropped item on the ground?

What about testing for a named item drop?

This would allow you to run certain commands when a specific item is dropped, for example, if the player drops a compass they could be teleported to the spawn of your world, or have a message shown to them.

See also: Detecting items in the player's inventory


Browse more workarounds for getting/setting NBT in Bedrock Edition

Best Answer

Commands

/testfor @e[type=item,name="Ghast Tear"]

This command will activate when a ghast tear is dropped.

/kill @e[type=item,name="Lime Wool"]

This command runs when a Lime Wool is dropped.

/testfor @e[type=item,name="Spooky Pumpkin"]

If you name an item “Spooky Pumpkin” and drop it, this runs.

Notes

  • This is still compatible with the color formatting codes (§), so don’t worry!

  • If your item name does not contain spaces and consists only of the characters in the following line, you may type the name directly, without having to include the quotation marks:

    +-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz
    

    If your name contains a character not in this list, you will need to surround your name with quotation marks ", like in the above examples. To include a quotation mark as part of the name, escape them with a \:

    /testfor @e[type=item,name="some name with spaces and \"quotation marks\""]
    

Limitations

  • If you name an item “Ghast Tear”, the ghast tear command will run even if it were something else, like dirt.
  • This method requires the name of the item in the host's texture pack to always be the name matching the command block, meaning it won't work if the user has a special texture pack on that changes the name or their language is set to something else. You can solve this problem by:
    • Rename the item if possible
    • Change every language file the game has to make the name of the item the same across all languages, which will require you to include a resource pack in the world/world download
    • Have multiple checks for each possible language name
  • The entity count returned by a /testfor of this may not reflect the number of dropped items, because when two items with the same properties are dropped next to each other, they like to group up into a single entity representing a stack of one or more items.