Class: ItemBookComponent
componentBeta
当此组件存在于物品上时,表示该物品为书本物品。可以访问和 修改书本的内容并对其进行签名。
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?
readonlyoptionalauthor?: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.
contents
readonlycontents: (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.
isSigned
readonlyisSigned:boolean
Beta
Remarks
判断书本是否已被签名。
Determines whether the book has been signed or not.
Throws
This property can throw when used.
isValid
readonlyisValid: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
pageCount
readonlypageCount:number
Beta
Remarks
书本拥有的页数。
The amount of pages the book has.
Throws
This property can throw when used.
rawContents
readonlyrawContents: (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.
title?
readonlyoptionaltitle?:string
Beta
Remarks
若书本已签名,则为书本的标题;否则为 undefined。
The title of the book if it is signed, otherwise undefined.
Throws
This property can throw when used.
typeId
readonlytypeId:string
Beta
Remarks
组件的标识符。
Identifier of the component.
Inherited from
componentId
readonlystaticcomponentId:"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.
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.
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
在指定索引处插入一页。若索引大于当前书本大小,则会创建空 白页面。 页面对于字符串以及 RawMessage 的 JSON 表示均有最多 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.
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.
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
设置书本各页的内容。原有页面将被清除。 页面对于字符串以及 RawMessage 的 JSON 表示均有最多 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.
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
设置或创建指定页面的内容。若索引大于当前书本大小,则会创 建空白页面。 页面对于字符串以及 RawMessage 的 JSON 表示均有最多 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.
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.
