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"}}}}
You need to specify the radius:
execute @e[name=TestCatch] ~ ~ ~ testfor @e[type=Item,r=5] {Item:{tag:{display:{Name:"Pokeball"}}}}
this will test if there is a Pokeball
item within 5 blocks of TestCatch
Best Answer
The main problem with your command is that you have an extra set of square brackets after
SelectedItem
; that is,...SelectedItem:[{id:"mi...
should really be...SelectedItem:{id:"mi...
A square bracket
[
tells Minecraft that the specified tag is a list (for exampleArmorItems:[{},{},{},{}]
), where as a curly bracket{
tells Minecraft that the specified tag is a single item (with attributes).I'm assuming that you should also use an
at @s
to tell Minecraft to run at the player's coordinates and specify the block you want to fill. This turns out as