Minecraft Blogs / Tutorial

Getting Custom Books

  • 15,547 views, 3 today
  • 10
  • 7
  • 12
TheJared802's Avatar TheJared802
Level 43 : Master Nerd
29
Hi! Today I'm gonna show you how to give yourself a book written by another player. This can be very helpful especially for map makers.

The command used is /give (obviously). What we want to do is start with
/give @p written_book 1 0

This is where the data tags come in. We now need to use the data tags 'title', 'author', and 'pages'. The title data tag is the name of the book. The author is who the book is by, and the pages is obviously the pages. If you put it all together, it should look something like this:

/give @p written_book 1 0 {title:"TITLE",author:"AUTHOR",pages:PAGES}

The pages tag is a little more difficult. what we want to do is combine all of the pages into one value. To do this, we will need to use square brackets. Inside the square brackets, we will label each page with its page number. For Example,
{pages:[1:"Page 1 text",2:"Page 2 text"]}
You can go on for as many pages as you would like.

Now, you should have something like this:

/give @p written_book 1 0 {title:"How to be awesome",author:"Mr. Awesome",pages:[1:"In order to be awesome, you must follow these steps.",2:"To be awesome, you must first..."]}

These are the very basics for how the command will be structured. We will now get into more advanced customizations, such as colored text and functionalities.

To add color, we simply use the color tag.
The possible colors include the following:
gold
red
dark_red
yellow
dark_purple
light_purple
aqua
dark_aqua
gray
dark_gray
black
white
green
dark_green
blue
dark_blue

To add a color, we need to turn the generic text (within quotes) to a data tag. To do this, we use a method from /tellraw:
{pages:[1:"{text:\"hi\"}"]}

As you can see, the value of "text" is within quotes. But you may notice that before the quotes, there are backslashes. This is meant to avoid confusion between the inside and outside quotes. Let me explain.

If we put
{pages:[1:"{text:"hi"}"]}
then the computer will see only the '{text:' as the text for the book, and the rest will be seen as part of the data tag.
hi"}" is not a data tag, so the computer will be confused. This is all because of the quotation marks. So, what we do to fix this is we put a \ before the quotes that are inside the quotes. This allows us to 'escape' the confusion between quotation marks.

This may seem confusing right now, but you'll get it eventually.

Now, we add the color tag.
{pages:[1:"{text:\"hi\",color:blue}"]}

There are may other true/false tags that you can use to add effects to your text. These incude the following:
italic
bold
underlined
strikethough
obfuscated

clickEvent is another data tag that is used when you want your text to be clickable. There are two tags within clickEvent. These are known as "action" and "value." "action" says what happens when the sign is clicked. "value" is the value of which is executed through the action. You will understand better in a moment.

There are 3 actions for books:
run_command
open_url
change_page

run_command does as expected; it makes the player run a command.
open_url prompts the player to open a website url.
change_page turns that page to whatever the value is.

If we want to use run_command, we type this:
/give @p written_book 1 0 {
title:"hi",
author:"Bob",
pages:[
1:"{
text:\"hi\",
color:blue,
clickEvent:{
action:run_command,
value:\"COMMANDHERE\"
}
}"
]
}

Just replace COMMANDHERE with the command you wish to use.
open_url works much differently. The value, rather than being a command, is instead a url! (What an unexpected twist!)
/give @p written_book 1 0 {
title:"hi",
author:"Bob",
pages:[
1:"{
text:\"hi\",
color:blue,
clickEvent:{
action:open_url,
value:\"www.planetminecraft.com/blog/how-to-give-yourself-a-book-written-by-another-player/\"
}
}"
]
}

When the player clicks the text, they will be prompted to open their browser.

The last action for books is change_page. As you would expect, change_page changes the page in the book. The value determins which page the pages will be turned to. For example, if you wanted it to change to page 2, value would be 2, page 3 and value would be 3, and so on. An example of this is as follows:

/give @p written_book 1 0 {
title:"hi",
author:"Bob",
pages:[
1:"{
text:\"Click to turn to page 5.\",
color:blue,
clickEvent:{
action:change_page,
value:5
}
}"
]
}

Please note that the most previous example is not valid and will not work as expected. In order to turn to page 5, you must first define that there are at least 5 pages. Otherwise, clicking the text will have no effect. Most would assume that you merely need to add a 5:" " to the pages selection. They are not entirely correct. If you put...

/give @p written_book 1 0 {
title:"hi",
author:"Bob",
pages:[
1:"{
text:\"Click to turn to page 5.\",
color:blue,
clickEvent:{
action:change_page,
value:5
}
}",
5:" "
]
}
... then the computer would add only 1 page, creating a total of only 2 pages. The truth is, you need to define all of the pages up until that point, like as follows:

/give @p written_book 1 0 {
title:"hi",
author:"Bob",
pages:[
1:"{
text:\"Click to turn to page 5.\",
color:blue,
clickEvent:{
action:change_page,
value:5
}
}",
2:" ",
3:" ",
4:" ",
5:" "
]
}

It is worth noting that whenever you leave a page blank (even if you put a few spaces), the computer will automatically put "null" in the page to represent that it is empty. If you wish for a truly blank page, you must add '\n'. \n means "new" in most programming languages, in this case meaning "new line." However, in order to use \n, you must translate the raw text into data tag form, whether or not you will be adding colored text. For example:

/give @p written_book 1 0 {
title:"hi",
author:"Bob",
pages:[
1:"{
text:\"Click to turn to page 5.\",
color:blue,
clickEvent:{
action:change_page,
value:5
}
}",
2:"",                         <<< this page states "null"
3:" ",                        <<< this page states "null"
4:"\n",                      <<< this page states "\n"
5:"{text:\" \n \"}"       <<< this page is truly blank :D
]
}

There is also such this as hoverEvent, but I will not cover this now. I do plan on adding it to this tutorial within the next few days, so please check back within the next few days.

A note to all readers:
Sometimes you may want to have different colored text on the same page. In this case, you can put multiple text tags within square brackets. For example:
1:"[{text:\"This is blue, \",color:blue},{text:\"but this is red.\",color:red}]"


Thanks for reading! I hope this helps all you map makers and random people who like stuff like this. If you enjoyed, please remember to leave a diamond. If you have any questions or concerns, please feel free to leave a comment. Thanks!
Tags

1 Update Logs

Update #1 : by TheJared802 05/12/2015 12:33:30 amMay 12th, 2015

Added coloring tutorial
Added true/false tags tutorial
Added clickEvent tutorial

Create an account or sign in to comment.

1
07/27/2016 1:05 am
Level 1 : New Miner
dalatorabvon21
dalatorabvon21's Avatar
So, I wrote a whole long text for this book page (gibberish) and I wanted it to run multiple commands. The way it is now though, it just pastes the rest of the command onto the page and doesn't do anything... Any assistance would be appreciated.

/give @p written_book 1 0 {title:"Virtuous Tome",author:"Bardel",color:blue,pages:[1:"{text:"Aer feroli nymbos sefer et al ebon et varuus septus nex ep vite nomine valunn", color:blue,clickEvent:{action:run_command,value:\"scoreboard players tag @p add cleverGirl\"}}"]}
1
08/12/2016 2:55 pm
Level 43 : Master Nerd
TheJared802
TheJared802's Avatar
I apologize for the late response, I have been very busy lately.

The commands within json are not like commands in a command block, you need to put the forward slash '/' with it.
One other note, because the json is already within quotations, you should put backslashes before the quotations after 'text', to escape the first quotes avoid scope issues. Surprisingly, it worked in-game for me anyway, but I would still do it just to be safe.
Your final command should look like this:

/give @p written_book 1 0 {title:"Virtuous
Tome",author:"Bardel",color:blue,pages:[1:"{text:\"Aer feroli nymbos
sefer et al ebon et varuus septus nex ep vite nomine valunn\",
color:blue,clickEvent:{action:run_command,value:\"/scoreboard players tag
@p add cleverGirl\"}}"]}
1
05/28/2016 7:19 am
Level 1 : New Crafter
Rensiee
Rensiee's Avatar
Thank you so much! Now my map is almost done! thanks for your help!
But one thing, it says only: Hello, nothing more, but i wrote a whole text!
1
05/29/2016 1:09 am
Level 43 : Master Nerd
TheJared802
TheJared802's Avatar
No problem! But you made it unclear whether you're having a problem that you'd like help with or if you're just mentioning that you added to my example.
1
06/05/2016 1:59 pm
Level 1 : New Explorer
Tenzenmaster
Tenzenmaster's Avatar
I think what Rensiee meant was that they wrote something like this, "Hello, how are you today?" but only the first word came out like this, "Hello," I am having the same problem. You know what's going on?
1
06/06/2016 1:40 am
Level 43 : Master Nerd
TheJared802
TheJared802's Avatar
Hm, I tried what you said but have been unable to recreate the problem, perhaps either of you could post the command you're using..?
1
08/03/2017 8:43 pm
Level 1 : New Miner
Nate_Dog987
Nate_Dog987's Avatar
I know this is an old post, but I'm having the same issue that Rensiee and Tenzenmaster were having. This is the line of code I'm putting in the command block:

give @p written_book 1 0 {title:"Diary Entry 1",author:"You",pages:["This place seems unfamiliar, perhaps I should explore the area."]}

Should be simple right? But the text in the book only reads the word "This". Any help would be appreciated, thanks.
1
05/14/2015 9:15 pm
Level 4 : Apprentice Explorer
DogStar13
DogStar13's Avatar
The whole command I tried to write can't fit on the line...
1
05/15/2015 6:37 pm
Level 43 : Master Nerd
TheJared802
TheJared802's Avatar
If it gets too long, you will have to use a command block.
1
05/16/2015 1:41 am
Level 4 : Apprentice Explorer
DogStar13
DogStar13's Avatar
Do command blocks have limits?
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome