How can I test for a chest with items?

I am trying to test for a coal block in slot 1 of a chest.

Here is a command that I tried:

/testforblock -673 57 -195 chest 2 {Items:[{id:"minecraft:coal_block",Damage:0s,Slot:1b,Count:1b}]}

However, this command returns an error: Syntax error: Unexpected "{": at "1 chest 2>>{<<Items:[{id


NBT

You cannot read tile data or NBT data besides for basic damage values (i.e. prismarine:0 = Rough Prismarine, prismarine:1 = Dark Prismarine)

(See this post, if anyone hasn't seen this enough.)

Different Approach

From what I can see you are looking for 1 coal block in slot 1. Make a chest with a coal block in slot 1 and then use the testforblocks command, as this command allows to compare more data (i.e. items in droppers, chests etc.).

/testforblocks <Sx> <Sy> <Sz> <Sx> <Sy> <Sz> <Dx> <Dy> <Dz>

Command Broken Down

  • <Sx> <Sy> <Sz> = Source X, Source Y, Source Z - In this case the block the coal chest is in, this is our first corner of the testforblocks region
  • <Sx> <Sy> <Sz> = Source X, Source Y, Source Z - In this case the same block position we used before. This would be the second corner as this command's intent was to compare a set of blocks with 2 corners, but we will only be comparing one block for this instance
  • <Dx> <Dy> <Dz> = Destination X, Destination Y, Destination Z - Our destination spot. This will be the other spot that will be compared with our last set of coordinates. Notice there is only one corner specified here, this should always be the negative-most corner as whenever one corner is specified in Minecraft commands it always goes the positive direction. In this case you put the chest that would be normally empty, which you want to see if has a coal block in it.

Notes

  • Don't forget hoppers exist! This could be an easier approach for certain circumstances.
  • Remember the chests have to be EXACTLY the same. This means if you have a glass pane in slot 27, both chests have to have this same glass pane in the same spot.

This should work, please tell me if it doesn't.