@minecraft/server / BlockSignComponent
Class: BlockSignComponent ​
Defined in: @minecraft/server/index.d.ts:5616
Represents a block that can display text on it.
Examples ​
addSign.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.`);
}addTwoSidedSign.ts
import {
BlockPermutation,
BlockSignComponent,
SignSide,
DyeColor,
BlockComponentTypes,
DimensionLocation,
} from '@minecraft/server';
import { MinecraftBlockTypes } from '@minecraft/vanilla-data';
function addTwoSidedSign(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) {
const signBlock = targetLocation.dimension.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;
if (signComponent) {
signComponent.setText(`Party Sign!\nThis is green on the front.`);
signComponent.setText(`Party Sign!\nThis is red on the back.`, SignSide.Back);
signComponent.setTextDyeColor(DyeColor.Green);
signComponent.setTextDyeColor(DyeColor.Red, SignSide.Back);
// players cannot edit sign!
signComponent.setWaxed(true);
} else {
log('Could not find sign component.');
}
}updateSignText.ts
import { BlockSignComponent, BlockComponentTypes, DimensionLocation, RawMessage, RawText } from '@minecraft/server';
function updateSignText(targetLocation: DimensionLocation) {
const block = targetLocation.dimension.getBlock(targetLocation);
if (!block) {
console.warn('Could not find a block at specified location.');
return;
}
const sign = block.getComponent(BlockComponentTypes.Sign) as BlockSignComponent;
if (sign) {
// RawMessage
const helloWorldMessage: RawMessage = { text: 'Hello World' };
sign.setText(helloWorldMessage);
// RawText
const helloWorldText: RawText = { rawtext: [{ text: 'Hello World' }] };
sign.setText(helloWorldText);
// Regular string
sign.setText('Hello World');
} else {
console.warn('Could not find a sign component on the block.');
}
}addTranslatedSign.ts
import { world, BlockPermutation, BlockSignComponent, BlockComponentTypes, DimensionLocation } from '@minecraft/server';
import { MinecraftBlockTypes } from '@minecraft/vanilla-data';
function addTranslatedSign(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({ translate: 'item.skull.player.name', with: [players[0].name] });
}Extends ​
Properties ​
block ​
readonlyblock:Block
Defined in: @minecraft/server/index.d.ts:4377
Remarks ​
Block instance that this component pertains to.
Inherited from ​
isValid ​
readonlyisValid: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 ​
isWaxed ​
readonlyisWaxed:boolean
Defined in: @minecraft/server/index.d.ts:5626
Remarks ​
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 ​
readonlytypeId:string
Defined in: @minecraft/server/index.d.ts:6240
Remarks ​
Identifier of the component.
Inherited from ​
componentId ​
readonlystaticcomponentId:"minecraft:sign"='minecraft:sign'
Defined in: @minecraft/server/index.d.ts:5627
Methods ​
getRawText() ​
getRawText(
side?):RawText|undefined
Defined in: @minecraft/server/index.d.ts:5641
Parameters ​
side? ​
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 ​
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
Defined in: @minecraft/server/index.d.ts:5654
Parameters ​
side? ​
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 ​
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
Defined in: @minecraft/server/index.d.ts:5666
Parameters ​
side? ​
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 ​
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
Defined in: @minecraft/server/index.d.ts:5686
Parameters ​
message ​
string | RawMessage
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? ​
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.
This function can't be called in restricted-execution mode.
Throws ​
Throws if the provided message is greater than 512 characters in length.
setTextDyeColor() ​
setTextDyeColor(
color?,side?):void
Defined in: @minecraft/server/index.d.ts:5704
Parameters ​
color? ​
The dye color to apply to the sign or undefined to clear the dye on the sign. Defaults to: null
side? ​
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.
This function can't be called in restricted-execution mode.
Throws ​
This function can throw errors.
setWaxed() ​
setWaxed(
waxed):void
Defined in: @minecraft/server/index.d.ts:5713
Parameters ​
waxed ​
boolean
Returns ​
void
Remarks ​
Makes it so players cannot edit this sign.
This function can't be called in restricted-execution mode.
Throws ​
This function can throw errors.