Skip to main content

Class: Block

Represents a block in a dimension. A block represents a unique X, Y, and Z within a dimension and get/sets the state of the block at that location. This type was significantly updated in version 1.17.10.21.

Constructors

new Block()

private new Block(): Block

Returns

Block

Properties

dimension

readonly dimension: Dimension

Remarks

Returns the dimension that the block is within.


isAir

readonly isAir: boolean

Remarks

Returns true if this block is an air block (i.e., empty space).

Throws

This property can throw when used.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


isLiquid

readonly isLiquid: boolean

Remarks

Returns true if this block is a liquid block - (e.g., a water block and a lava block are liquid, while an air block and a stone block are not. Water logged blocks are not liquid blocks).

Throws

This property can throw when used.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


isSolid

Beta

readonly isSolid: boolean

Remarks

Returns true if this block is solid and impassible - (e.g., a cobblestone block and a diamond block are solid, while a ladder block and a fence block are not).

Throws

This property can throw when used.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


isWaterlogged

Beta

readonly isWaterlogged: boolean

Remarks

Returns or sets whether this block has a liquid on it.

Throws

This property can throw when used.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


location

readonly location: Vector3

Remarks

Coordinates of the specified block.

Throws

This property can throw when used.


permutation

readonly permutation: BlockPermutation

Remarks

Additional block configuration data that describes the block.

Throws

This property can throw when used.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


type

Beta

readonly type: BlockType

Remarks

Gets the type of block.

Throws

This property can throw when used.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


typeId

Beta

readonly typeId: string

Remarks

Identifier of the type of block for this block.

Throws

This property can throw when used.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


x

readonly x: number

Remarks

X coordinate of the block.


y

readonly y: number

Remarks

Y coordinate of the block.


z

readonly z: number

Remarks

Z coordinate of the block.

Methods

above()

above(steps?): Block

Parameters

ParameterTypeDescription
steps?numberNumber of steps above to step before returning.

Returns

Block

Remarks

Returns the Block above this block (positive in the Y direction).

Throws

This function can throw errors.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


below()

below(steps?): Block

Parameters

ParameterTypeDescription
steps?numberNumber of steps below to step before returning.

Returns

Block

Remarks

Returns the Block below this block (negative in the Y direction).

Throws

This function can throw errors.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


bottomCenter()

bottomCenter(): Vector3

Returns

Vector3

Remarks

Returns the @minecraft/server.Location of the center of this block on the X and Z axis.


canPlace()

Beta

canPlace(blockToPlace, faceToPlaceOn?): boolean

Parameters

ParameterTypeDescription
blockToPlacestring | BlockPermutation | BlockTypeBlock type or block permutation to check placement for.
faceToPlaceOn?DirectionOptional specific face of this block to check placement
against.

Returns

boolean

Returns true if the block type or permutation can be placed on this block, else false.

Remarks

Checks to see whether it is valid to place the specified block type or block permutation, on a specified face on this block

Throws

This function can throw errors.

Error

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


center()

center(): Vector3

Returns

Vector3

Remarks

Returns the @minecraft/server.Location of the center of this block on the X, Y, and Z axis.


east()

east(steps?): Block

Parameters

ParameterTypeDescription
steps?numberNumber of steps to the east to step before returning.

Returns

Block

Remarks

Returns the Block to the east of this block (positive in the X direction).

Throws

This function can throw errors.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


getComponent()

getComponent<T>(componentId): BlockComponentTypeMap[T]

Type parameters

Type parameter
T extends keyof BlockComponentTypeMap

Parameters

ParameterTypeDescription
componentIdTThe identifier of the component (e.g.,
'minecraft:inventory'). If no namespace prefix is specified,
'minecraft:' is assumed. Available component IDs can be
found as part of the BlockComponentTypes enum.

Returns

BlockComponentTypeMap[T]

Returns the component if it exists on the block, otherwise undefined.

Remarks

Gets a component (that represents additional capabilities) for a block - for example, an inventory component of a chest block.

Throws

This function can throw errors.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


getItemStack()

getItemStack(amount?, withData?): ItemStack

Parameters

ParameterTypeDescription
amount?numberNumber of instances of this block to place in the item
stack.
withData?booleanWhether additional data facets of the item stack are
included.

Returns

ItemStack

An itemStack with the specified amount of items and data. Returns undefined if block type is incompatible.

Remarks

Creates a prototype item stack based on this block that can be used with Container/ContainerSlot APIs.

Throws

This function can throw errors.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


getRedstonePower()

Beta

getRedstonePower(): number

Returns

number

Returns undefined if redstone power is not applicable to this block.

Remarks

Returns the net redstone power of this block.

Throws

This function can throw errors.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


getTags()

getTags(): string[]

Returns

string[]

The list of tags that the block has.

Remarks

Returns a set of tags for a block.

Throws

This function can throw errors.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


hasTag()

hasTag(tag): boolean

Parameters

ParameterTypeDescription
tagstringTag to check for.

Returns

boolean

Returns true if the permutation of this block has the tag, else false.

Remarks

Checks to see if the permutation of this block has a specific tag.

Throws

This function can throw errors.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError

Example

import { world } from "@minecraft/server";

// Fetch the block
const block = world.getDimension("overworld").getBlock({ x: 1, y: 2, z: 3 });

console.log(`Block is dirt: ${block.hasTag("dirt")}`);
console.log(`Block is wood: ${block.hasTag("wood")}`);
console.log(`Block is stone: ${block.hasTag("stone")}`);

isValid()

isValid(): boolean

Returns

boolean

True if this block object is still working and valid.

Remarks

Returns true if this reference to a block is still valid (for example, if the block is unloaded, references to that block will no longer be valid.)


matches()

Beta

matches(blockName, states?): boolean

Parameters

ParameterTypeDescription
blockNamestringBlock type identifier to match this API against.
states?Record<string, string | number | boolean>Optional set of block states to test this block against.

Returns

boolean

Returns true if the block matches the specified criteria.

Remarks

Tests whether this block matches a specific criteria.

Throws

This function can throw errors.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


north()

north(steps?): Block

Parameters

ParameterTypeDescription
steps?numberNumber of steps to the north to step before returning.

Returns

Block

Remarks

Returns the Block to the north of this block (negative in the Z direction).

Throws

This function can throw errors.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


offset()

offset(offset): Block

Parameters

ParameterTypeDescription
offsetVector3The offset vector. For example, an offset of 0, 1, 0 will
return the block above the current block.

Returns

Block

Block at the specified offset, or undefined if that block could not be retrieved (for example, the block and its relative chunk is not loaded yet.)

Remarks

Returns a block at an offset relative vector to this block.

Throws

This function can throw errors.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


setPermutation()

setPermutation(permutation): void

Parameters

ParameterTypeDescription
permutationBlockPermutationPermutation that contains a set of property states for the
Block.

Returns

void

Remarks

Sets the block in the dimension to the state of the permutation.

This function can't be called in read-only mode.

Throws

This function can throw errors.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


setType()

Beta

setType(blockType): void

Parameters

ParameterTypeDescription
blockTypestring | BlockTypeIdentifier of the type of block to apply - for example,
minecraft:powered_repeater.

Returns

void

Remarks

Sets the type of block.

This function can't be called in read-only mode.

Throws

This function can throw errors.

Error

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


setWaterlogged()

Beta

setWaterlogged(isWaterlogged): void

Parameters

ParameterTypeDescription
isWaterloggedbooleantrue if the block should have water within it.

Returns

void

Remarks

Sets whether this block has a water logged state - for example, whether stairs are submerged within water.

This function can't be called in read-only mode.

Throws

This function can throw errors.

Error

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


south()

south(steps?): Block

Parameters

ParameterTypeDescription
steps?numberNumber of steps to the south to step before returning.

Returns

Block

Remarks

Returns the Block to the south of this block (positive in the Z direction).

Throws

This function can throw errors.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


trySetPermutation()

Beta

trySetPermutation(permutation): boolean

Parameters

ParameterTypeDescription
permutationBlockPermutationPermutation that contains a set of property states for the
Block.

Returns

boolean

Returns true if the block permutation data was successfully set, else false.

Remarks

Tries to set the block in the dimension to the state of the permutation by first checking if the placement is valid.

This function can't be called in read-only mode.

Throws

This function can throw errors.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


west()

west(steps?): Block

Parameters

ParameterTypeDescription
steps?numberNumber of steps to the west to step before returning.

Returns

Block

Remarks

Returns the Block to the west of this block (negative in the X direction).

Throws

This function can throw errors.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError