Let's look at your data tag here carefully.
{
Item:
[
id:"minecraft:written_book",
Slot:0b,
Damage:0s,
Count:1b
}
]
}
In this expanded form, you can immediately see that something is odd about your parentheses. There is a closing curly bracket without a partner. You'll have to add {
before id
(which is the first tag inside the item tag). Generally, when something is wrong, expanding the command over multiple lines and indenting properly at every layer is a good idea to catch these type of errors.
Secondly, the tag containing the item tags for chests is called Items
, plural (cf. the wiki).
In total, the data tag needs to be
{
Items:
[
{
id:"minecraft:written_book",
Slot:0b,
Damage:0s,
Count:1b
}
]
}
Or compacted for easy copy and paste:
{Items:[{id:"minecraft:written_book",Slot:0b,Damage:0s,Count:1b}]}
The number that we're interested in is the 2 in the /give
command. This is the data value for the map. This corresponds to the Damage:
field of the NBT tag. Damage is a short, so you must use 2s
to indicate a damage value of 2. So the proper NBT tag for the item is {id:minecraft:filled_map,Damage:2s}
. Therefore, the final command becomes as follows:
/testfor @p {Inventory:[{id:"minecraft:filled_map",Damage:2s}]}
That said, /give @p filled_map 1 2
doesn't necessarily work in the way you would expect: the damage value 2 will only apply if it has already been created. Otherwise, it'll give the player a map with value 0, then 1. Use F3+H to verify the actual data value of the map that you have. This won't be a problem after the map has been generated.
Best Answer
The command is structured correctly.
Most commands are processed equal to the number of targets obtained by the selector first, which is the case for
/testfor
. Every single arrow in the world has its NBT data checked one at a time.However, the output of the command block only shows the result of the last iteration. While an arrow could have been found during the process, the last arrow found may not match.
You should use a comparator to check the actual success of the command, or run the command yourself in the chat and scroll through the return messages until you find one that's a success.
But in general,
/testfor
is not helpful and you should not be using it in this situation. It will not allow you to target which arrow was found. You've already run into the case of there being arrows that don't match, so any subsequent commands will be targeting them.Use
/scoreboard
instead, to either assign a score pre-1.9 or a "tag" in 1.9:And you'd then be able to target those specific arrows by selecting the "in" label: