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"}}}}
As of 1.9, armor is now an attribute, named generic.armor
.
When the AttributeModifiers
tag is specified on an item, any default modifiers are ignored, which includes the generic.armor
modifier for armor (and generic.armorToughness
for diamond armor as well).
You will need to re-specify those modifiers. You may also want to use the new Slot
string tag for modifiers, which allows you to specify exactly which armor slot the modifier applies in (with values "head", "chest", "legs", "feet", "mainhand", and "offhand").
/give @p chainmail_helmet 1 0 {display:{Name:"Archer Helmet",Lore:["You feel somewhat faster, and resistant to ranged damage"]},AttributeModifiers:[{AttributeName:"generic.movementSpeed",Name:"generic.movementSpeed",Slot:"head",Amount:0.10,Operation:0,UUIDMost:24682,UUIDLeast:195471},{AttributeName:"generic.armor",Name:"armor",Slot:"head",Amount:2.0,Operation:0,UUIDMost:1,UUIDLeast:1}],ench:[{id:0,lvl:2},{id:4,lvl:2}],Unbreakable:1}
Best Answer
I assume by "a snowball named "Lightning"" you mean that the item is named "Lightning" (like if you renamed it with an anvil).
Unfortunately, this information does not pass over to the thrown snowball entity (the item name doesn't become the entity name, for example), so what you want is a bit more complicated to achieve.
You should create a new objective to keep track of when a player throws a snowball:
Then, on a clock, run the following commands in this order:
This should tag all players holding the snowball renamed to "Lightning" with
HoldingLightning
. If that player then has aThrownSnowball
score of at least one (meaning they've thrown a snowball in this tick, as this score resets at the end of the commands), they give the closest snowball theLightningBall
tag. You can then use@e[type=Snowball,tag=LightningBall]
to run thesummon
command as often as you want (you can put the summon command on a separate, slower clock).