Jump to content

Recommended Posts

Posted

So... I'm not sure I'm doing this the right way, as I have to look at someones else code as I'm not sure how written books work exactly.

 

But when trying this out almost everything works, with the detail that the content of the different pages isn't showing complete.

 

		ItemStack writtenBook = new ItemStack(Items.WRITTEN_BOOK,1,0);

	NBTTagList bookPages = new NBTTagList();

	bookPages.appendTag(new NBTTagString("Page one text"));
	bookPages.appendTag(new NBTTagString("Page two text"));

	writtenBook.setTagInfo("title", new NBTTagString("Test Book"));
	writtenBook.setTagInfo("author", new NBTTagString("American"));
	writtenBook.setTagInfo("pages", bookPages);

	EntityItem theItemEntity = new EntityItem(worldIn, playerIn.posX, playerIn.posY, playerIn.posZ, writtenBook);

	worldIn.spawnEntityInWorld(theItemEntity);

 

Each page shows "Page" as the text and not the complete line "Page one text" and "Page two text"

Posted

Each tag in the

"pages"

list must be the JSON representation of an

ITextComponent

. For a

TextComponentString

, you can simply wrap the contents in quotation marks (e.g.

new NBTTagString("\"Page one text\"")

).

 

If you want anything more complex than plain text, I suggest you create the

ITextComponent

for each page and then use

ITextComponent.Serializer#componentToJson

to serialise them.

  • Like 1

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.