The bug
Book & Quills can be created through commands or command blocks (through the /give commands or as the inventory of a chest in a /setblock
command), however, not all book & quills that can be made in the game can be made through a command. A similar fix was previously done for signed, written books, and I'm looking for that fix to be applied to writable books / book & quills as well.
Specifically, previous bug MC-52919 (same title), fixed the written_book item so that it accepts tellraw formatted text, allowing newline characters ('\n') in the text of commands to be interpreted a line breaks in the text of the written book (a place where the user pressed enter). (1.12 has change how the text parser for command interprets \n inside quoted text, so now
n is needed, but otherwise the commands in the comments of MC-52919 work)
Unfortunately, this fix only was applied to the written_book item. The writable_book item, while supporting the same text features in game (as it is turning into the written_book item once signed), does not support the tellraw format in a command, and therefore it isn't possible to use a command to create a writable book that happens to have line breaks / new line characters in it's text, even though it is possible to make such an object in game with the standard book & quill interface.
Examples
This command works as expected:
/give @a written_book{title:"Test",author:"test",pages:["{text:\"Line 1\\nLine 2\"}"]}
It produces a written book with the following text on the first page:
Line 1 Line 2
This command does not work as expected:
/give @a writable_book{pages:["{text:\"Line 1\\nLine 2\"}"]}
This is expected to produce a book similar to the above, except not signed yet. Instead it produces a not signed book with the following text on page 1:
{text:"Line 1\nLine 2"}
As writable books and written books are similar objects in game (in fact writable books are turned into written books), I would expect that they would treat text similarly and both support newline characters in their text (as when creating the objects in game allows enter to be pressed to go to the start of the next line).
Linked issues
is duplicated by 2
Comments 7
Confirmed for 1.14
This is actually a pretty serious bug, since it prevents the player from setting any NBT strings which need to contain newlines without using an external tool to edit the world.
The only reason it doesn't come up very often is because most in-game text displaying things support JSON.
Workarounds are to use a sign or a loot table.
/setblock ~ ~ ~ oak_sign{Text1:'{"text":"","clickEvent":{"action":"run_command","value":"give @s writable_book{pages:[\\"line1\\nline2\\"]}"}}'}
{
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "minecraft:item",
"name": "minecraft:writable_book",
"functions": [
{
"function": "minecraft:set_nbt",
"tag": "{pages:[\"line1\nline2\"]}"
}
]
}
]
}
]
}
Since it seems like Mojang did not plan to fix this bug since 1.12 nor plans to do it in the future, I'd like to document a workaround for this for future players reading this bugreport.
To bypass this bug, the player can perform a sequence of commands to clone a multi-line book and quill from a chest and instantly add it to a player's inventory, without triggering the bug.
The commands are:
/summon item ~ ~10 ~ {PickupDelay:0,Tags:["temp"],Item:{id:"minecraft:writable_book",Count:1b,tag:{pages:["a"]}}}
/data modify entity @e[type=item,tag=temp,limit=1] Item set from block 0 100 0 Items[0]
/tp @e[type=item,tag=temp] @p
The first command will summon a vessel to hold the currently problematic NBT we are trying to use (that Mojang considers problematic for no reason, since it is perfectly valid NBT).
The second command looks for a chest at the coordinates 0 100 0 (can be changed to any coord), grabs the NBT from the book and quill on the chest, and puts it on the item that was summoned using the first command
The third command teleports the summoned item to the nearest player, making it instantly be picked up, which is similar behavior to a /give command.
I hope this helps someone. I would say I also hope Mojang fixes this bug but I know they won't. Have a nice day yall!
Can confirm as of 1.20.4 and 24w10a.
The commands in the bug description no longer work with the addition of components. Use the following commands instead:
/give @a written_book[minecraft:written_book_content={pages:["{text:\"Line 1\\nLine 2\"}"], title: "Test", author: "Test"}]
/give @a writable_book[minecraft:writable_book_content={pages:["{text:\"Line 1\\nLine 2\"}"]}]
Confirmed 1.13.1 for command give @s minecraft:writable_book{pages:["line1\nline2"]}