I'm trying to make a kit pvp map in vanilla Minecraft, but I ran into a problem. I want specific people to get a certain effect. So I got a /testfor command:

/testfor @a{SelectedItemSlot:0,Inventory:[{Slot:0b,tag:{display:{Name:"Fire Wand"}}}]}

This command tests if any person has this specified item name in slot 0. It then turns on a comparator which activates the second command once it finds that person:

/execute @p ~ ~ ~ summon Fireball ~2 ~1 ~ {ExplosivePower:10,direction:[0.0,0.0,0.0]}

How can I specify this command to the person holding the named item?

1 Answer 1


You have to use a command to apply a label to the player based on their data rather than using /testfor. For example, /scoreboard can assign a label:

/scoreboard players tag @a[tag=HasItem] remove HasItem
/scoreboard players tag @a[tag=!HasItem] add HasItem {SelectedItemSlot:0,Inventory:[{Slot:0b,tag:{display:{Name:"Fire Wand"}}}]}

And you'd then target players based on their label. The correct tag for fireball damage is ExplosionPower:

/execute @a[tag=HasItem] ~ ~ ~ /summon Fireball ~2 ~1 ~ {ExplosionPower:10,direction:[0.0,0.0,0.0]}

If using 1.8, you will have to use a score instead. Objective to create:

/scoreboard objectives add HasItem dummy

Commands to run for labeling:

/scoreboard players set @a HasItem 0
/scoreboard players set @a HasItem 1 {SelectedItem:{tag:{display:{Name:"Fire Wand"}}}}

And for targeting, you'd use the score parameter:

/execute @a[score_HasItem_min=1] ~ ~ ~ /summon Fireball ~2 ~1 ~ {ExplosionPower:10,direction:[0.0,0.0,0.0]}

You may be interested in the SelectedItem compound, which holds a copy of the player's currently-held item. This way you do not need to specifically test each individual hotbar slot:

/scoreboard players tag @a[tag=!HasItem] add HasItem {SelectedItem:{tag:{display:{Name:"Fire Wand"}}}}
  • I really appreciate selected items compound command you suggested it will save me a lot of trouble! 😂😂
    – JP2K
    Mar 1, 2016 at 3:49
  • I tested it out now, but it says that the usage is incorrect, I can't have a tag after the /scoreboard players command! Help!!
    – JP2K
    Mar 1, 2016 at 14:32
  • @JP2K What version are you using? Scoreboard "tags" was added in 1.9. If you're using 1.8, you have to use a score instead. I'll update the answer to include a score.
    – Skylinerw
    Mar 1, 2016 at 14:39
  • Thank you very much, since I don't know if all of my commands still work in 1.9
    – JP2K
    Mar 1, 2016 at 17:05
  • I'll update you ones I found out if the commands still work
    – JP2K
    Mar 1, 2016 at 17:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .