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}}}
Notice the difference between "a score of 0" and "no scores at all". If an entity doesn't have any scores at all, then it means that the entity is not present on any scoreboard. If the entity has a score of 0, then it means that the entity is present on the scoreboard with score 0.
You are testing for arrows that have a score of 0 on telar
. The Arrow that you expected to show up, doesn't have a score of 0, but simply isn't present on the scoreboard. For this reason, that Arrow is not detected with the testfor command. If you still want to test for arrows that don't have a score assigned yet, you should add 0 to all entities on each scoreboard every tick with the following command:
/scoreboard players add @e[type=arrow] telar 0
This command adds 0 to the score of all Arrows on the telar objective. If an Arrow isn't present on the scoreboard yet, then it is added to the scoreboard with value 0.
Best Answer
The
x
,y
, andz
parameters will normally default to the sender's coordinates when not specified (the sender in this case being a command block). By specifying these parameters, all you're doing is changing what the origin is, but nothing more than that. The command will select all item entities, but sorting based on distance starting from the modified origin (where the unspecifiedy
parameter becomes the command block's Y coordinate).You must use
/execute
to change the origin to that of the intended targets (while being able to modify that new origin with/execute
's syntax), and you must also include a selection limiter such asr
ordx/dy/dz
to prevent selecting all around the world.For example, the following will kill any item entities at the X and Z coordinate, replacing the Y coordinate with the item entity's Y value: