Printing Block Data to Chat

y1nny5/16/22 7:41 pm
5/17/2022 10:40 am
Hello all. I'm not sure if this is the right place to post this but I'm also not sure where else to, so sorry if I'm in the wrong place :)

I'm trying to print some block data to the chat with /tell, /say, or /tellraw, but I can't figure out how to get the data from one command to the other.

The exact scenario is that I have a lectern with a book on it, and I want to print whatever text is on the book's first page to the chat.

I can get the data with

/data get block ~1 ~ ~ Book.tag.pages[0]

but I can't figure out how to get the result to print out to the chat. Any help would be appreciated :(
Posted by avatar
Level 1 : New Miner

Create an account or sign in to comment.


05/17/2022 1:23 am
Level 17 : Journeyman Nerd
Kefaku avatar
You can get blockdata directly in the /tellraw command using a nbt component:

tellraw @a {"nbt":"Book.tag.pages[​0]", "block":"~1 ~ ~"}

If you want to add some text before or after the text, you can either use a second /tellraw like this:

tellraw @a {"text":"text from page 1:"}
tellraw @a {"nbt":"Book.tag.pages[​0]", "block":"~1 ~ ~"}

Or add them together like this:

tellraw @a [{"text":"text from page 1:\n"}, {"nbt":"Book.tag.pages[​0]", "block":"~1 ~ ~"}]

NOTE: If there is no lectern at the given location, the tellraw command will work and just return an empty string for that part.
NOTE #2: For some reason there is some weird char in front of the 0, if I copy and paste the commands. If that also happens to you, you'd have to remove that for the command to work.
05/17/2022 10:40 am
Level 1 : New Miner
y1nny avatar
thank you so much!
Planet Minecraft


© 2010 - 2022