Minecraft Java Edition – How to Test for a Dropped Item Using Minecraft Commands

minecraft-commandsminecraft-java-edition

I know this question is like Execute or Testfor a named dropped Item?, but I couldn't fit the answer there to my needs. So, I'm working on a spear in my one-command creation. It is a stick renamed spear. So I want to be able to testfor when it is dropped, so it would be like "throwing" it.

Thanks.

Best Answer

You want this command:

/testfor @e[type=Item] {Item:{tag:{display:{Name:"spear"}}}}

Or, if you have more items named "spear" use this:

/testfor @e[type=Item] {Item:{id:minecraft:stick,tag:{display:{Name:"spear"}}}}

Now just hook this on a Redstone clock/Put it into a Repeat Command block and you're done!


If you have only 1 command following this, use tags and the /execute command:

/scoreboard players tag @e[type=Item] add IsSpear {Item:{tag:{display:{Name:spear}}}}

And instead of the /testfor command use /execute:

/execute @e[type=Item,tag=IsSpear] ~ ~ ~ /yourcommand