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/BlockSignComponent.md.

Class: BlockSignComponent

block component

Beta

表示可以在上面显示文字的方块。

Examples

addSign.ts
addTwoSidedSign.ts
updateSignText.ts
addTranslatedSign.ts
import { world, BlockPermutation, BlockSignComponent, BlockComponentTypes, DimensionLocation } from '@minecraft/server';
import { MinecraftBlockTypes } from '@minecraft/vanilla-data';

function addSign(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) {
  const players = world.getPlayers();

  const dim = players[0].dimension;

  const signBlock = dim.getBlock(targetLocation);

  if (!signBlock) {
    log('Could not find a block at specified location.');
    return -1;
  }
  const signPerm = BlockPermutation.resolve(MinecraftBlockTypes.StandingSign, { ground_sign_direction: 8 });

  signBlock.setPermutation(signPerm);

  const signComponent = signBlock.getComponent(BlockComponentTypes.Sign) as BlockSignComponent;

  signComponent?.setText(`Basic sign!\nThis is green on the front.`);
}

Extends

Properties

block

readonly block: Block

Beta

Remarks

此组件所属的方块。

Block instance that this component pertains to.

Inherited from

BlockComponent.block


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

BlockComponent.isValid


isWaxed

readonly isWaxed: boolean

Beta

Remarks

玩家是否可以编辑告示牌。如果告示牌被使用过蜂巢或调用了 setWaxed,则会发生这种情况。

Whether or not players can edit the sign. This happens if a sign has had a honeycomb used on it or setWaxed was called on the sign.

Throws

This property can throw when used.


typeId

readonly typeId: string

Beta

Remarks

组件的标识符。

Identifier of the component.

Inherited from

BlockComponent.typeId


componentId

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

Beta

Methods

getRawText()

getRawText(side?): RawText | undefined

Beta

Parameters

side?

SignSide

要读取消息的告示牌面。如果未提供,则将返回告示牌正面的消息。 默认为:0

The side of the sign to read the message from. If not provided, this will return the message from the front side of the sign. Defaults to: 0

Returns

RawText | undefined

Remarks

如果使用 RawMessage 或 RawText 对象调用了 setText,则返回告示牌的 RawText,否则返回 undefined

Returns the RawText of the sign if setText was called with a RawMessage or a RawText object, otherwise returns undefined.

Throws

This function can throw errors.


getText()

getText(side?): string | undefined

Beta

Parameters

side?

SignSide

要读取消息的告示牌面。如果未提供,则将返回告示牌正面的消息。 默认为:0

The side of the sign to read the message from. If not provided, this will return the message from the front side of the sign. Defaults to: 0

Returns

string | undefined

Remarks

如果使用字符串调用了 setText,则返回告示牌的文本,否则返回 undefined

Returns the text of the sign if setText was called with a string, otherwise returns undefined.

Throws

This function can throw errors.


getTextDyeColor()

getTextDyeColor(side?): DyeColor | undefined

Beta

Parameters

side?

SignSide

要读取染料的告示牌面。如果未提供,则将返回告示牌正面的染料。 默认为:0

The side of the sign to read the dye from. If not provided, this will return the dye on the front side of the sign. Defaults to: 0

Returns

DyeColor | undefined

Remarks

获取文字上的染料,如果告示牌未被染色,则返回 undefined

Gets the dye that is on the text or undefined if the sign has not been dyed.

Throws

This function can throw errors.


setText()

setText(message, side?): void

World Mutation Beta

Parameters

message

string | RawMessage

要在告示牌上设置的消息。如果设置为字符串,则调用 getText 来读取该字符串。如果设置为 RawMessage,则调用 getRawText 将返回 RawText。

The message to set on the sign. If set to a string, then call getText to read that string. If set to a RawMessage, then calling getRawText will return a RawText.

side?

SignSide

消息将被设置到的告示牌面。如果未提供,消息将设置在告示牌的正面。 默认为:0

The side of the sign the message will be set on. If not provided, the message will be set on the front side of the sign. Defaults to: 0

Returns

void

Remarks

设置告示牌组件的文本。

Sets the text of the sign component.

Throws

如果提供的消息长度超过 512 个字符,则抛出错误。

Throws if the provided message is greater than 512 characters in length.


setTextDyeColor()

setTextDyeColor(color?, side?): void

World Mutation Beta

Parameters

color?

DyeColor

要应用于告示牌的染料颜色,或 undefined 以清除告示牌上的染料。 默认为:null

The dye color to apply to the sign or undefined to clear the dye on the sign. Defaults to: null

side?

SignSide

颜色将被设置到的告示牌面。如果未提供,颜色将设置在告示牌的正面。 默认为:0

The side of the sign the color will be set on. If not provided, the color will be set on the front side of the sign. Defaults to: 0

Returns

void

Remarks

设置文字的染料颜色。

Sets the dye color of the text.

Throws

This function can throw errors.


setWaxed()

setWaxed(waxed): void

World Mutation Beta

Parameters

waxed

boolean

Returns

void

Remarks

使玩家无法编辑此告示牌。

Makes it so players cannot edit this sign.

Throws

This function can throw errors.

同领域相关