Minecraft – /testforblock items in chest not working

minecraft-commandsminecraft-java-edition

I'm trying to test for a written book in a chest but I keep getting the error message: Block at -1489,64,-1510 did not have the required NBT keys. I know there is a glitch were you have to fill in every NBT tag but please don't say it is the glitch because I filled in every tag. My command is below and I'm playing in 1.8.8, please help me!

/testforblock -1489 64 -1510 minecraft:chest -1 {Items:[{id:"minecraft:written_book",Slot:0b,Damage:0s,Count:1b}]}

Best Answer

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}]}