how to testfor a player that selected an item?

how to testfor a player that selected an item? - From below of crop multiethnic team of professional basketball players gathering and putting hands together while standing on playground before game

How to use the scoreboard command to testfor for a player that selected a snowball, namely "Blast" in Minecraft 1.9?



Best Answer

The SelectedItem compound holds a copy of the player's currently-held item (minus the Slot tag). All item data that is not the root id, Damage, Count, or Slot, must be placed within a single tag compound.

/scoreboard players set @a OBJ 0
/scoreboard players set @a OBJ 1 {SelectedItem:{id:"minecraft:snowball",tag:{display:{Name:"Blast"}}}}

/say Players holding the item: @a[score_OBJ_min=1]

As of 1.9 you will want to use "tags" instead of scores when labeling the player, which is more efficient and does not require an objective:

/scoreboard players tag @a[tag=holding] remove holding
/scoreboard players tag @a add holding {SelectedItem:{id:"minecraft:snowball",tag:{display:{Name:"Blast"}}}}

/say Players holding the item: @a[tag=holding]



Pictures about "how to testfor a player that selected an item?"

how to testfor a player that selected an item? - Retro turntable playing vinyl disc in living room
how to testfor a player that selected an item? - Woman Playing Beach Volleyball
how to testfor a player that selected an item? - A Young Woman Sitting beside her Squash Racket





Minecraft Bedrock - Test For Items In Inventory (Mobile/Xbox/PS4/Windows 10/Switch)




Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: Andrea Piacquadio, Matthias Groeneveld, Rich Ortiz, Artem Podrez