The SelectedItem
tag is a compound, which surrounds data in curly brackets. You've declared it as a string instead with the remainder of the item data at the root of the player entity data.
You need to place the item data inside, along with the id
tag. As well, the item format dictates that all data that is not the root id
, Damage
, Slot
, or Count
, must be placed within a single tag
compound.
On top of that, be aware that most extra item data will not be auto-corrected for datatypes. You've declared the enchantment's id
and lvl
tags tags as integers, but when the enchantments are obtained through normal means these tags will be shorts. You would end up needing multiple commands to check for the varied datatypes if you do not declare it as a short as well (which is done by appending a whole numerical value with an "s").
Revised /give
command:
/give @p minecraft:fire_charge 1 0 {display:{Name:"Fireball"},ench:[{id:60s,lvl:10s}]}
Resulting /testfor
command (if not for example, I recommend not relying on /testfor
and instead use multi-target friendly methods such as adding labels with /scoreboard
):
/testfor @a {SelectedItem:{id:"minecraft:fire_charge",tag:{display:{Name:"Fireball"},ench:[{id:60s,lvl:10s}]}}}
To make detection easier, you can use custom item data instead of trying to detect every single tag on the item. This way you can change the actual data for balancing purposes without having to go back to fix all commands relying on that data.
For example, the following adds a "specialFireCharge" byte tag with a value of 1 to the item:
/give @p minecraft:fire_charge 1 0 {specialFireCharge:1b,display:{Name:"Fireball"},ench:[{id:60s,lvl:10s}]}
And the following would be what you'd use to label the player as a result:
/scoreboard players tag @a[tag=HoldingCharge] remove HoldingCharge
/scoreboard players tag @a[tag=!HoldingCharge] add HoldingCharge {SelectedItem:{tag:{specialFireCharge:1b}}}
You are missing an opening bracket for the item compound.
{Item: id:"m
should be {Item:{id:"m
Your damage value is testing for an integer and needs to test for a short so it needs to be followed by an s.
Damage:8
should be Damage:8s
For a final command of:
scoreboard players set @e[type=Item] S 1 {Item:{id:"minecraft:wool",Damage:8s,Count:1b,tag:{display:{Name:"South"}}}}
Also, just to note it, you can give the item a scoreboard tag which will allow you to target the item without having to create a scoreboard objective. It will use the same dataTag from above.
Here is the command:
scoreboard players tag @e[type=Item] add S {Item:{id:"minecraft:wool",Damage:8s,Count:1b,tag:{display:{Name:"South"}}}}
To target the item, you can use the tag argument in the target selector within another command. An example command to kill the item:
/kill @e[tag=S]
Best Answer
An example code:
run initialy:
/scoreboard objectives add damage dummy
run repeatedly:
/execute as @a store result score @s damage run data get entity @s SelectedItem.tag.Damage
this stores for each player the damage of the item in his hand in the scoreboard
damage
.