Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Extends
When present on an item, this item is a book item. Can access and modify the contents of the book and sign it.
Properties
author
read-only author?: string;
The name of the author of the book if it is signed, otherwise undefined.
Type: string
Notes:
- This property can throw errors when used.
- Throws InvalidItemStackError
contents
read-only contents: (string | undefined)[];
The contents of pages in the book that are in string format. Entries not in string format will be undefined.
Type: (string | undefined)[]
Notes:
- This property can throw errors when used.
- Throws InvalidItemStackError
isSigned
read-only isSigned: boolean;
Determines whether the book has been signed or not.
Type: boolean
Notes:
- This property can throw errors when used.
- Throws InvalidItemStackError
pageCount
read-only pageCount: number;
The amount of pages the book has.
Type: number
Notes:
- This property can throw errors when used.
- Throws InvalidItemStackError
rawContents
read-only rawContents: (RawMessage | undefined)[];
The contents of pages in the book that are in @minecraft/server.RawMessage format. Entries not in @minecraft/server.RawMessage format will be undefined.
Type: (RawMessage | undefined)[]
Notes:
- This property can throw errors when used.
- Throws InvalidItemStackError
title
read-only title?: string;
The title of the book if it is signed, otherwise undefined.
Type: string
Notes:
- This property can throw errors when used.
- Throws InvalidItemStackError
Methods
getPageContent
getPageContent(pageIndex: number): string | undefined
Gets the string format content of a page for a given index.
Parameters
pageIndex: number
The index of the page.
Returns string | undefined - The content of the page if a valid index is provided and it is in string format, otherwise returns undefined.
Notes:
- This function can throw errors.
- Throws InvalidItemStackError
getRawPageContent
getRawPageContent(pageIndex: number): RawMessage | undefined
Gets the @minecraft/server.RawMessage format content of a page for a given index.
Parameters
pageIndex: number
The index of the page.
Returns RawMessage | undefined - The content of the page if a valid index is provided and it is in @minecraft/server.RawMessage format, otherwise returns undefined.
Notes:
- This function can throw errors.
- Throws InvalidItemStackError
insertPage
insertPage(pageIndex: number, content: (RawMessage | string)[] | RawMessage | string): void
Inserts a page at a given index. Empty pages will be created if the index is greater than the current book size.
Pages have a maximum limit of 256 characters for strings as well as the JSON representation of a @minecraft/server.RawMessage.
Books have a maximum limit of 50 pages.
Parameters
pageIndex: number
The index of the page.
content: (RawMessage | string)[] | RawMessage | string
The content to set for the page. Can be a single string or @minecraft/server.RawMessage or an array of strings and/or @minecraft/server.RawMessages
Notes:
- This function can't be called in restricted-execution mode.
- This function can throw errors.
removePage
removePage(pageIndex: number): void
Removes a page at a given index. Existing pages following this page will be moved backward to fill the empty space.
Parameters
pageIndex: number
The index of the page.
Notes:
- This function can't be called in restricted-execution mode.
- This function can throw errors.
- Throws InvalidItemStackError
setContents
setContents(contents: ((RawMessage | string)[] | RawMessage | string)[]): void
Sets the contents of the book's pages. Pre-existing pages will be cleared.
Pages have a maximum limit of 256 characters for strings as well as the JSON representation of a @minecraft/server.RawMessage.
Books have a maximum limit of 50 pages.
Parameters
contents: ((RawMessage | string)[] | RawMessage | string)[]
An array of each page's contents. Each page can be a single string or @minecraft/server.RawMessage or an array of strings and/or @minecraft/server.RawMessages.
Notes:
- This function can't be called in restricted-execution mode.
- This function can throw errors.
setPageContent
setPageContent(pageIndex: number, content: (RawMessage | string)[] | RawMessage | string): void
Sets or creates the content of a specific page. Empty pages will be created if the index is greater than the current book size.
Pages have a maximum limit of 256 characters for strings as well as the JSON representation of a @minecraft/server.RawMessage.
Books have a maximum limit of 50 pages.
Parameters
pageIndex: number
The index of the page.
content: (RawMessage | string)[] | RawMessage | string
The content to set for the page. Can be a single string or @minecraft/server.RawMessage or an array of strings and/or @minecraft/server.RawMessages
Notes:
- This function can't be called in restricted-execution mode.
- This function can throw errors.
signBook
signBook(title: string, author: string): void
Signs a book giving it a title and author name. Once signed players can no longer directly edit the book.
Titles have a maximum character limit of 16.
Parameters
title: string
The title to give the book.
author: string
The name of the book's author.
Notes:
- This function can't be called in restricted-execution mode.
- This function can throw errors.
Constants
componentId
static read-only componentId = "minecraft:book";
Type: string