Minecraft – Testfor a written book in 1.8 with custom name and writing

minecraft-commandsminecraft-java-edition

So I’m working on a map and need help with the Testfor command. I’ve looked around and tried out several different things and just messed around with the command without help, but I can’t get it to activate with the book in hand. Here’s the command I have set up, but it doesn’t work.

/testfor @a {SelectedItemSlot:8,Inventory:[{Slot:8b,id:minecraft:written_book,tag:{pages:["[\"\",{\"text\":\"Master, I have done as you told me, Minera will soon fall to your Undead Army. I still have not figured out how to obtain the sword, but you were right to check the bookshelf before attempting more drastic measures... (the note is torn)\"}]"],display:{Name:"Torn Note"}}}]}

Now here's a different version, but without a book (this one works perfectly).

/testfor @a {SelectedItemSlot:8,Inventory:[{Slot:8b,tag:{display:{Name:"Torn Note"}}}]}

My problem is that with a book the second command doesn’t light up and I really want to use a book for this part of my map.

Also I should say, the command for the book itself should be fine, I used a JSON Minecraft generator and it works fine with /give. I did edit the format slightly to try to get the testfor command to work, but it didn’t.

Best Answer

Better not be using the "pages" tag for testfor'ing books. pages uses JSON format, and there are many valid JSON formats for a book, and you couldn't detect them all. Use a custom NBT tag to detect a specific book, or instead just use the book name.