Minecraft – How to do testfor with different maps

minecraft-commandsminecraft-java-edition

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!

Best Answer

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.