in my map players get given certain maps via command blocks. This works fine but when I try to mimic this with the testfor command, it doesnt work.

I use /give @p minecraft:filled_map 1 2 to spawn the specific map

However, when I do /testfor @p {Inventory:[{id:minecraft:filled_map 1 2}]} it just says that I didnt match the required data structure

Is this a mishap on my part or is there another way to do this? Appreciate all help!


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.

  • I just tried this and it didnt work for some reason, I copied and pasted it right into the command block and it just says that I didnt match the required data structure. The map I have in my inventory is Map #2 Mar 27 '16 at 15:46
  • When testing for pre-existing NBT data, you must specify the name, value, and datatype correctly. In this case, the datatype was declared as an integer, when it instead must be declared as a short (Damage:2s).
    – Skylinerw
    Mar 27 '16 at 15:47
  • @B-DigidyDog Hold on, I'm working through some errors in my command structure
    – Unionhawk
    Mar 27 '16 at 15:47
  • @B-DigidyDog I have fixed and tested all errors that existed previously in my answer, and indicated another possible reason this could be failing that I discovered in my testing.
    – Unionhawk
    Mar 27 '16 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.