2

Printing Block Data to Chat

y1nny 5/16/22 7:41 pm
214
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
y1nny
Level 1 : New Miner
0

  Have something to say?

JoinSign in

2

Kefaku
05/17/2022 1:23 am
Level 45 : Master Nerd
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.
2
y1nny
05/17/2022 10:40 am
Level 1 : New Miner
thank you so much!
2

Welcome