Skip to content

@minecraft/server


@minecraft/server / ItemBookComponent

Class: ItemBookComponent ​

Defined in: @minecraft/server/index.d.ts:13418

When present on an item, this item is a book item. Can access and modify the contents of the book and sign it.

Extends ​

Properties ​

author? ​

readonly optional author?: string

Defined in: @minecraft/server/index.d.ts:13429

Remarks ​

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

Throws ​

This property can throw when used.

InvalidItemStackError


contents ​

readonly contents: (string | undefined)[]

Defined in: @minecraft/server/index.d.ts:13439

Remarks ​

The contents of pages in the book that are in string format. Entries not in string format will be undefined.

Throws ​

This property can throw when used.

InvalidItemStackError


isSigned ​

readonly isSigned: boolean

Defined in: @minecraft/server/index.d.ts:13448

Remarks ​

Determines whether the book has been signed or not.

Throws ​

This property can throw when used.

InvalidItemStackError


isValid ​

readonly isValid: boolean

Defined in: @minecraft/server/index.d.ts:6234

Remarks ​

Returns whether the component is valid. A component is considered valid if its owner is valid, in addition to any addition to any additional validation required by the component.

Inherited from ​

ItemComponent.isValid


pageCount ​

readonly pageCount: number

Defined in: @minecraft/server/index.d.ts:13457

Remarks ​

The amount of pages the book has.

Throws ​

This property can throw when used.

InvalidItemStackError


rawContents ​

readonly rawContents: (RawMessage | undefined)[]

Defined in: @minecraft/server/index.d.ts:13468

Remarks ​

The contents of pages in the book that are in RawMessage format. Entries not in RawMessage format will be undefined.

Throws ​

This property can throw when used.

InvalidItemStackError


title? ​

readonly optional title?: string

Defined in: @minecraft/server/index.d.ts:13477

Remarks ​

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

Throws ​

This property can throw when used.

InvalidItemStackError


typeId ​

readonly typeId: string

Defined in: @minecraft/server/index.d.ts:6240

Remarks ​

Identifier of the component.

Inherited from ​

ItemComponent.typeId


componentId ​

readonly static componentId: "minecraft:book" = 'minecraft:book'

Defined in: @minecraft/server/index.d.ts:13478

Methods ​

getPageContent() ​

getPageContent(pageIndex): string | undefined

Defined in: @minecraft/server/index.d.ts:13492

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.

Remarks ​

Gets the string format content of a page for a given index.

Throws ​

This function can throw errors.

InvalidItemStackError


getRawPageContent() ​

getRawPageContent(pageIndex): RawMessage | undefined

Defined in: @minecraft/server/index.d.ts:13508

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 RawMessage format, otherwise returns undefined.

Remarks ​

Gets the RawMessage format content of a page for a given index.

Throws ​

This function can throw errors.

InvalidItemStackError


insertPage() ​

insertPage(pageIndex, content): void

Defined in: @minecraft/server/index.d.ts:13533

Parameters ​

pageIndex ​

number

The index of the page.

content ​

string | RawMessage | (string | RawMessage)[]

The content to set for the page. Can be a single string or RawMessage or an array of strings and/or RawMessages

Returns ​

void

Remarks ​

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 RawMessage. Books have a maximum limit of 50 pages.

This function can't be called in restricted-execution mode.

Throws ​

This function can throw errors.

BookError

BookPageContentError

InvalidItemStackError


removePage() ​

removePage(pageIndex): void

Defined in: @minecraft/server/index.d.ts:13547

Parameters ​

pageIndex ​

number

The index of the page.

Returns ​

void

Remarks ​

Removes a page at a given index. Existing pages following this page will be moved backward to fill the empty space.

This function can't be called in restricted-execution mode.

Throws ​

This function can throw errors.

InvalidItemStackError


setContents() ​

setContents(contents): void

Defined in: @minecraft/server/index.d.ts:13570

Parameters ​

contents ​

(string | RawMessage | (string | RawMessage)[])[]

An array of each page's contents. Each page can be a single string or RawMessage or an array of strings and/or RawMessages.

Returns ​

void

Remarks ​

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 RawMessage. Books have a maximum limit of 50 pages.

This function can't be called in restricted-execution mode.

Throws ​

This function can throw errors.

BookError

BookPageContentError

InvalidItemStackError


setPageContent() ​

setPageContent(pageIndex, content): void

Defined in: @minecraft/server/index.d.ts:13596

Parameters ​

pageIndex ​

number

The index of the page.

content ​

string | RawMessage | (string | RawMessage)[]

The content to set for the page. Can be a single string or RawMessage or an array of strings and/or RawMessages

Returns ​

void

Remarks ​

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 RawMessage. Books have a maximum limit of 50 pages.

This function can't be called in restricted-execution mode.

Throws ​

This function can throw errors.

BookError

BookPageContentError

InvalidItemStackError


signBook() ​

signBook(title, author): void

Defined in: @minecraft/server/index.d.ts:13617

Parameters ​

title ​

string

The title to give the book.

author ​

string

The name of the book's author.

Returns ​

void

Remarks ​

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.

This function can't be called in restricted-execution mode.

Throws ​

This function can throw errors.

BookError

InvalidEntityError

InvalidItemStackError