Class in @minecraft/server
A block at a place in the world.
import { Block } from '@minecraft/server';Example
Section titled “Example”import { world, type Block } from '@minecraft/server';
function describe(block: Block): string { const { x, y, z } = block.location; return `${block.typeId} at ${x}, ${y}, ${z}`;}
world.afterEvents.playerBreakBlock.subscribe((event) => { event.player.sendMessage(`You broke the block where ${describe(event.block)} now is.`);});import { world } from '@minecraft/server';
function describe(block) { const { x, y, z } = block.location; return `${block.typeId} at ${x}, ${y}, ${z}`;}
world.afterEvents.playerBreakBlock.subscribe((event) => { event.player.sendMessage(`You broke the block where ${describe(event.block)} now is.`);});Properties
Section titled “Properties”typeId
Section titled “typeId”read-only
readonly typeId: string;Its identifier, as minecraft:stone.
read-only
readonly type: { readonly id: string };permutation
Section titled “permutation”read-only
readonly permutation: BlockPermutation;Its type and states, read from the world when first wanted.
location
Section titled “location”read-only
readonly location: Vector3;read-only
readonly x: number;read-only
readonly y: number;read-only
readonly z: number;dimension
Section titled “dimension”read-only
readonly dimension: Dimension;read-only
readonly isAir: boolean;isLiquid
Section titled “isLiquid”read-only
readonly isLiquid: boolean;Whether it’s water or lava.
localizationKey
Section titled “localizationKey”read-only
readonly localizationKey: string;The block’s name key in the language files, as tile.stone.name.
isValid
Section titled “isValid”read-only
readonly isValid: boolean;False once its chunk isn’t loaded.
isWaterlogged
Section titled “isWaterlogged”read-only
readonly isWaterlogged: boolean;Whether it’s waterlogged.
Methods
Section titled “Methods”setType
Section titled “setType”setType(blockType: string | { id: string }): void;Sets the block to a type’s default state.
blockTypestring | { id: string }
setPermutation
Section titled “setPermutation”setPermutation(permutation: BlockPermutation): void;permutationBlockPermutation
matches
Section titled “matches”matches(blockName: string, states?: Record<string, boolean | number | string>): boolean;Whether it’s this block, with these states if given.
blockNamestringstatesoptionalRecord<string, boolean | number | string>
booleanoffset
Section titled “offset”offset(offset: Vector3): Block | undefined;The block this far away, or undefined if its chunk isn’t loaded.
offsetVector3
Block | undefinedabove(steps?: number): Block | undefined;The block steps up, 1 by default.
stepsoptionalnumber
Block | undefinedbelow(steps?: number): Block | undefined;stepsoptionalnumber
Block | undefinednorth(steps?: number): Block | undefined;Towards -z.
stepsoptionalnumber
Block | undefinedsouth(steps?: number): Block | undefined;Towards +z.
stepsoptionalnumber
Block | undefinedeast(steps?: number): Block | undefined;Towards +x.
stepsoptionalnumber
Block | undefinedwest(steps?: number): Block | undefined;Towards -x.
stepsoptionalnumber
Block | undefinedcenter
Section titled “center”center(): Vector3;The middle of the block.
Vector3bottomCenter
Section titled “bottomCenter”bottomCenter(): Vector3;The middle of the block’s bottom face.
Vector3setWaterlogged
Section titled “setWaterlogged”setWaterlogged(isWaterlogged: boolean): void;Waterlogs the block, or drains it.
isWaterloggedboolean
getComponent
Section titled “getComponent”getComponent<T extends string>(componentId: T): BlockComponentReturnType<T> | undefined;A block component by name; undefined if absent (Basalt backs none yet).
componentIdT
BlockComponentReturnType<T> | undefinedgetComponents
Section titled “getComponents”getComponents(): BlockComponent[];Every component on the block.
BlockComponent[]hasComponent
Section titled “hasComponent”hasComponent(componentId: string): boolean;Whether it has the component.
componentIdstring
booleangetTags
Section titled “getTags”getTags(): string[];The block type’s tags, as minecraft:dirt.
string[]hasTag
Section titled “hasTag”hasTag(tag: string): boolean;Whether it has this block tag.
tagstring
booleangetItemStack
Section titled “getItemStack”getItemStack(amount?: number, withData?: boolean): ItemStack | undefined;An item stack of the block, if it has one.
amountoptionalnumberwithDataoptionalboolean
ItemStack | undefinedgetRedstonePower
Section titled “getRedstonePower”getRedstonePower(): number | undefined;Its redstone power, or undefined if it isn’t a redstone component.
number | undefinedgetDynamicProperty
Section titled “getDynamicProperty”getDynamicProperty(identifier: string): boolean | number | string | Vector3 | undefined;A dynamic property kept in the block’s NBT. It’s saved with the world, moves with a piston, and goes when the block is broken or replaced. Air keeps nothing.
identifierstring
boolean | number | string | Vector3 | undefinedsetDynamicProperty
Section titled “setDynamicProperty”setDynamicProperty(identifier: string, value?: boolean | number | string | Vector3): void;Sets a property on the block, or removes it with undefined.
identifierstringvalueoptionalboolean | number | string | Vector3
setDynamicProperties
Section titled “setDynamicProperties”setDynamicProperties(values: Record<string, boolean | number | string | Vector3>): void;valuesRecord<string, boolean | number | string | Vector3>
getDynamicPropertyIds
Section titled “getDynamicPropertyIds”getDynamicPropertyIds(): string[];string[]getDynamicPropertyTotalByteCount
Section titled “getDynamicPropertyTotalByteCount”getDynamicPropertyTotalByteCount(): number;numberclearDynamicProperties
Section titled “clearDynamicProperties”clearDynamicProperties(): void;getLightLevel
Section titled “getLightLevel”getLightLevel(): number;The light reaching it.
numbergetSkyLightLevel
Section titled “getSkyLightLevel”getSkyLightLevel(): number;The skylight reaching it.
numbergetParts
Section titled “getParts”getParts(): Block[] | undefined;The sub-blocks of a multi-block, or undefined.
Block[] | undefinedcanContainLiquid
Section titled “canContainLiquid”canContainLiquid(liquidType: LiquidType): boolean;Whether the block can hold this liquid.
liquidTypeLiquidType
booleancanBeDestroyedByLiquidSpread
Section titled “canBeDestroyedByLiquidSpread”canBeDestroyedByLiquidSpread(liquidType: LiquidType): boolean;Whether spreading liquid would break it.
liquidTypeLiquidType
booleanisLiquidBlocking
Section titled “isLiquidBlocking”isLiquidBlocking(liquidType: LiquidType): boolean;Whether it stops this liquid.
liquidTypeLiquidType
booleanliquidCanFlowFromDirection
Section titled “liquidCanFlowFromDirection”liquidCanFlowFromDirection(liquidType: LiquidType, flowDirection: Direction): boolean;Whether liquid may flow in from a direction.
liquidTypeLiquidTypeflowDirectionDirection
booleanliquidSpreadCausesSpawn
Section titled “liquidSpreadCausesSpawn”liquidSpreadCausesSpawn(liquidType: LiquidType): boolean;Whether liquid spreading onto it spawns the block’s drop.
liquidTypeLiquidType
booleanUsed by
Section titled “Used by”Entity.getBlockStandingOn, Entity.getAllBlocksStandingOn, Dimension.getBlock, Dimension.getBlockAbove, Dimension.getBlockBelow, Dimension.getTopmostBlock, PlayerBreakBlockBeforeEvent.block, PlayerBreakBlockAfterEvent.block, PlayerPlaceBlockBeforeEvent.block, PlayerPlaceBlockAfterEvent.block, PlayerInteractWithBlockAfterEvent.block, BlockExplodeAfterEvent.block, ExplosionBeforeEvent.getImpactedBlocks, ExplosionBeforeEvent.setImpactedBlocks, ExplosionAfterEvent.getImpactedBlocks, BlockHitInformation.block, ButtonPushAfterEvent.block, LeverActionAfterEvent.block, PistonActivateAfterEvent.block, PressurePlatePushAfterEvent.block, PressurePlatePopAfterEvent.block, TargetBlockHitAfterEvent.block, TripWireTripAfterEvent.block, BlockComponent.block and 9 more