For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /server/classes/ItemBookComponent.md.

Class: ItemBookComponent

component

Beta

当此组件存在于物品上时,表示该物品为书本物品。可以访问和 修改书本的内容并对其进行签名。

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

Beta

Remarks

若书本已签名,则为书本作者的名字;否则为 undefined。

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)[]

Beta

Remarks

书本中以字符串格式存储的各页内容。非字符串格式的条目将为 undefined。

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

Beta

Remarks

判断书本是否已被签名。

Determines whether the book has been signed or not.

Throws

This property can throw when used.

InvalidItemStackError


isValid

readonly isValid: boolean

Beta

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

Beta

Remarks

书本拥有的页数。

The amount of pages the book has.

Throws

This property can throw when used.

InvalidItemStackError


rawContents

readonly rawContents: (RawMessage | undefined)[]

Beta

Remarks

书本中以 RawMessage 格式存储的各页内容。非 RawMessage 格式的条目将为 undefined。

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

Beta

Remarks

若书本已签名,则为书本的标题;否则为 undefined。

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

Throws

This property can throw when used.

InvalidItemStackError


typeId

readonly typeId: string

Beta

Remarks

组件的标识符。

Identifier of the component.

Inherited from

ItemComponent.typeId


componentId

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

Beta

Methods

getPageContent()

getPageContent(pageIndex): string | undefined

Beta

Parameters

pageIndex

number

页面的索引。

The index of the page.

Returns

string | undefined

若提供的索引有效且该页为字符串格式,则返回该页内容;否则 返回 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

Beta

Parameters

pageIndex

number

页面的索引。

The index of the page.

Returns

RawMessage | undefined

若提供的索引有效且该页为 RawMessage 格式,则返回该 页内容;否则返回 undefined。

The content of the page if a valid index is provided and it is in RawMessage format, otherwise returns undefined.

Remarks

获取指定索引处页面的 RawMessage 格式内容。

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

Throws

This function can throw errors.

InvalidItemStackError


insertPage()

insertPage(pageIndex, content): void

World Mutation Beta

Parameters

pageIndex

number

页面的索引。

The index of the page.

content

string | RawMessage | (string | RawMessage)[]

要为该页设置的内容。可以是单个字符串或 RawMessage, 或字符串和/或 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

在指定索引处插入一页。若索引大于当前书本大小,则会创建空 白页面。 页面对于字符串以及 RawMessageJSON 表示均有最多 256 个字符的限制。书本最多有 50 页的限制。

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.

Throws

This function can throw errors.

BookError

BookPageContentError

InvalidItemStackError


removePage()

removePage(pageIndex): void

World Mutation Beta

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.

Throws

This function can throw errors.

InvalidItemStackError


setContents()

setContents(contents): void

World Mutation Beta

Parameters

contents

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

由各页内容组成的数组。每一页可以是单个字符串或 RawMessage,或字符串和/或 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

设置书本各页的内容。原有页面将被清除。 页面对于字符串以及 RawMessageJSON 表示均有最多 256 个字符的限制。书本最多有 50 页的限制。

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.

Throws

This function can throw errors.

BookError

BookPageContentError

InvalidItemStackError


setPageContent()

setPageContent(pageIndex, content): void

World Mutation Beta

Parameters

pageIndex

number

页面的索引。

The index of the page.

content

string | RawMessage | (string | RawMessage)[]

要为该页设置的内容。可以是单个字符串或 RawMessage, 或字符串和/或 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

设置或创建指定页面的内容。若索引大于当前书本大小,则会创 建空白页面。 页面对于字符串以及 RawMessageJSON 表示均有最多 256 个字符的限制。书本最多有 50 页的限制。

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.

Throws

This function can throw errors.

BookError

BookPageContentError

InvalidItemStackError


signBook()

signBook(title, author): void

World Mutation Beta

Parameters

title

string

要赋予书本的标题。

The title to give the book.

author

string

书本作者的名字。

The name of the book's author.

Returns

void

Remarks

为书本签名,赋予其标题和作者名。一旦签名,玩家便无法再直 接编辑该书本。 标题最多有 16 个字符的限制。

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.

Throws

This function can throw errors.

BookError

InvalidEntityError

InvalidItemStackError

同领域相关