0

I am looking for the command to change the data in a written book that is in a chest, changing what is written on the page/s. I am trying to build a randomizer that will change a single-digit entry on each page, giving you a book with a random set of characters each time it is summoned. Any help would be greatly appreciated.

Current target/command that is working

/data modify block -183 64 201 Items[0].tag merge value {pages:['{"text":"1"}','{"text":"7"}','{"text":"1"}']}

What I still need is a way to only edit the data on a single page without changing the data on any of the other pages.

Edit.

I have gone through the linked question and it does not illustrate how to do what I am trying to do.

5
  • What have you tried so far? What ideas do you have to approach this problem? Have you looked through our large amount of Minecraft-related questions?
    – Joachim
    Mar 5, 2023 at 8:35
  • I managed to target the book with it in a chest. I can modify the data on the pages. However, I can not change one page without changing all of the pages. Mar 5, 2023 at 10:51
  • Thanks! Please edit in what you have tried, including any commands you used. That way, it's much easier to receive good and particular answers. Also, since you're using the 'addons' tag, please tell us which ones they are exactly.
    – Joachim
    Mar 5, 2023 at 11:20
  • 2
  • 2
    Even if that question's answers answer this one, the questions themselves seem nothing alike, and should IMH (and uninformed) O not be treated as such. VTLO.
    – Joachim
    Mar 6, 2023 at 7:50

1 Answer 1

1

/execute as @e[type=item,nbt={Item:{tag:{author:"randombook"}}},limit=1] run data modify entity @s pages[0].text set from entity @e[tag=randomizer,limit=1] <nbt path to random number>

for put a location to get the random number from an entity with the tag 'randomizer', using nbt path format. One way you could do this is by adding ,sort=random after the text limit=1 and having multiple entites with the tag 'randomizer' with different names or some other tag that supports integers and doesn't change, and specifying the path to said entity. Once you decide on how you want to do this I can help with the nbt path stuff if you want. I'm just not sure on the best way to do this part so I will leave it open ended

If you want to modify the text of a book in a chest to a random value: Note: work in progress, I have not included a source of randomness

/data modify block <x> <y> <z> Items.[{tag:{author:"randombook"}}].tag.pages[0] set from <source> (here's the tricky part, the source of randomness.)

To include a source of randomness for the book in chest option, there are a few things you could do. It is more complicated since I can't get the .text part at the end to work since it seems to be a string with NBT data inside. Seems to have stopped working for the first solution too? The best option I could think of right now is giving multiple armor stands (each possible combination on 1 page needs its own armor stand) a custom NBT tag such as random:'{"text:"<numbers here>"}' and remove the single quotes ' if they cause problems. If you could access NBT data from within those single quotes you could add multiple sections to the page for near unlimited randomness.

Anybody know how to access the NBT data inside 'single quotes?'

8
  • This sounds like a much better way to do it than what I have cobbled together. I was appending pages with a single unique character. I built a command block machine using an armor stand randomizer, this gives me random data of 30-50 characters depending on commands doubling up. Your method writes multiple characters to one page which means I could fit WAY more randomness! Can you run the command to edit the book in a chest as I do? I really appreciate the response btw! =D edit. Mar 6, 2023 at 5:25
  • @Redlegdaddy the command I gave only works for dropped items but I can add another version for items in a chest :) edit: will there be set coordinates for the chest or must it work in any inventory? Mar 6, 2023 at 5:39
  • Will be set coords for a chest! Would armor stands work for data points? I know you can assign tags and names to them =D. Mar 6, 2023 at 5:52
  • @Redlegdaddy any entity should work, and armor stands seem like a great choice because of their marker tag. Easier than using tags might just to be to make your own custom nbt tag. You can do this by literally just adding it to the armor stand's nbt data and minecraft will remember it Mar 6, 2023 at 6:01
  • 1
    @Redlegdaddy i posted a solution that kind of works, key word being kind of Mar 10, 2023 at 2:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .