Edit

ItemBookComponent Class

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:

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:

isSigned

read-only isSigned: boolean;

Determines whether the book has been signed or not.

Type: boolean

Notes:

pageCount

read-only pageCount: number;

The amount of pages the book has.

Type: number

Notes:

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:

title

read-only title?: string;

The title of the book if it is signed, otherwise undefined.

Type: string

Notes:

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:

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:

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

Notes:

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.

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

Notes:

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

Notes:

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:

Constants

componentId

static read-only componentId = "minecraft:book";

Type: string