Skip to content

@minecraft/server


@minecraft/server / Block

Class: Block ​

Defined in: @minecraft/server/index.d.ts:3787

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.

Properties ​

dimension ​

readonly dimension: Dimension

Defined in: @minecraft/server/index.d.ts:3794

Remarks ​

Returns the dimension that the block is within.


isAir ​

readonly isAir: boolean

Defined in: @minecraft/server/index.d.ts:3806

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

Defined in: @minecraft/server/index.d.ts:3820

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


isValid ​

readonly isValid: boolean

Defined in: @minecraft/server/index.d.ts:3828

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.)


isWaterlogged ​

readonly isWaterlogged: boolean

Defined in: @minecraft/server/index.d.ts:3839

Remarks ​

Returns or sets whether this block has water on it.

Throws ​

This property can throw when used.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


localizationKey ​

readonly localizationKey: string

Defined in: @minecraft/server/index.d.ts:3851

Remarks ​

Key for the localization of this block's name used in .lang files.

Throws ​

This property can throw when used.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


location ​

readonly location: Vector3

Defined in: @minecraft/server/index.d.ts:3858

Remarks ​

Coordinates of the specified block.

Throws ​

This property can throw when used.


permutation ​

readonly permutation: BlockPermutation

Defined in: @minecraft/server/index.d.ts:3870

Remarks ​

Additional block configuration data that describes the block.

Throws ​

This property can throw when used.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


type ​

readonly type: BlockType

Defined in: @minecraft/server/index.d.ts:3881

Remarks ​

Gets the type of block.

Throws ​

This property can throw when used.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


typeId ​

readonly typeId: string

Defined in: @minecraft/server/index.d.ts:3894

Remarks ​

Identifier of the type of block for this block. Warning: Vanilla block names can be changed in future releases, try using 'Block.matches' instead for block comparison.

Throws ​

This property can throw when used.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


x ​

readonly x: number

Defined in: @minecraft/server/index.d.ts:3900

Remarks ​

X coordinate of the block.


y ​

readonly y: number

Defined in: @minecraft/server/index.d.ts:3906

Remarks ​

Y coordinate of the block.


z ​

readonly z: number

Defined in: @minecraft/server/index.d.ts:3912

Remarks ​

Z coordinate of the block.

Methods ​

above() ​

above(steps?): Block | undefined

Defined in: @minecraft/server/index.d.ts:3927

Parameters ​

steps? ​

number

Number of steps above to step before returning. Defaults to: 1

Returns ​

Block | undefined

Remarks ​

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

Throws ​

This function can throw errors.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


below() ​

below(steps?): Block | undefined

Defined in: @minecraft/server/index.d.ts:3942

Parameters ​

steps? ​

number

Number of steps below to step before returning. Defaults to: 1

Returns ​

Block | undefined

Remarks ​

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

Throws ​

This function can throw errors.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


bottomCenter() ​

bottomCenter(): Vector3

Defined in: @minecraft/server/index.d.ts:3949

Returns ​

Vector3

Remarks ​

Returns the Vector3 of the center of this block on the X and Z axis.


canBeDestroyedByLiquidSpread() ​

canBeDestroyedByLiquidSpread(liquidType): boolean

Defined in: @minecraft/server/index.d.ts:3967

Parameters ​

liquidType ​

Water

The type of liquid this function should be called for.

Returns ​

boolean

Whether this block is removed when touched by liquid.

Remarks ​

Returns whether this block is removed when touched by liquid.

Throws ​

This function can throw errors.

Error

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


canContainLiquid() ​

canContainLiquid(liquidType): boolean

Defined in: @minecraft/server/index.d.ts:3985

Parameters ​

liquidType ​

Water

The type of liquid this function should be called for.

Returns ​

boolean

Whether this block can have a liquid placed over it.

Remarks ​

Returns whether this block can have a liquid placed over it, i.e. be waterlogged.

Throws ​

This function can throw errors.

Error

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


center() ​

center(): Vector3

Defined in: @minecraft/server/index.d.ts:3992

Returns ​

Vector3

Remarks ​

Returns the Vector3 of the center of this block on the X, Y, and Z axis.


east() ​

east(steps?): Block | undefined

Defined in: @minecraft/server/index.d.ts:4007

Parameters ​

steps? ​

number

Number of steps to the east to step before returning. Defaults to: 1

Returns ​

Block | undefined

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): BlockComponentReturnType<T> | undefined

Defined in: @minecraft/server/index.d.ts:4029

Type Parameters ​

T ​

T extends string

Parameters ​

componentId ​

T

The identifier of the component (e.g., 'minecraft:inventory'). If no namespace prefix is specified, 'minecraft:' is assumed. Available component IDs are those in the BlockComponentTypes enum and custom component IDs registered with the BlockComponentRegistry.

Returns ​

BlockComponentReturnType<T> | undefined

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


getComponents() ​

getComponents(): BlockComponent[]

Defined in: @minecraft/server/index.d.ts:4041

Returns ​

BlockComponent[]

Remarks ​

Returns all scripting components that are present on this block.

Throws ​

This function can throw errors.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


getItemStack() ​

getItemStack(amount?, withData?): ItemStack | undefined

Defined in: @minecraft/server/index.d.ts:4065

Parameters ​

amount? ​

number

Number of instances of this block to place in the item stack. Defaults to: 1 Bounds: [1, 255]

withData? ​

boolean

Whether additional data facets of the item stack are included. Defaults to: false

Returns ​

ItemStack | undefined

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


getLightLevel() ​

getLightLevel(): number

Defined in: @minecraft/server/index.d.ts:4081

Returns ​

number

The brightness level on the block.

Remarks ​

Returns the total brightness level of light shining on a certain block.

This function can't be called in restricted-execution mode.

Throws ​

This function can throw errors.

minecraftcommon.InvalidArgumentError

LocationInUnloadedChunkError


getRedstonePower() ​

getRedstonePower(): number | undefined

Defined in: @minecraft/server/index.d.ts:4095

Returns ​

number | undefined

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


getSkyLightLevel() ​

getSkyLightLevel(): number

Defined in: @minecraft/server/index.d.ts:4111

Returns ​

number

The brightness level on the block.

Remarks ​

Returns the brightness level of light shining from the sky on a certain block.

This function can't be called in restricted-execution mode.

Throws ​

This function can throw errors.

minecraftcommon.InvalidArgumentError

LocationInUnloadedChunkError


getTags() ​

getTags(): string[]

Defined in: @minecraft/server/index.d.ts:4124

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


hasComponent() ​

hasComponent(componentId): boolean

Defined in: @minecraft/server/index.d.ts:4140

Parameters ​

componentId ​

string

The identifier of the component (e.g., 'minecraft:inventory') to retrieve. If no namespace prefix is specified, 'minecraft:' is assumed.

Returns ​

boolean

Remarks ​

Returns true if the specified component is present on this block.

Throws ​

This function can throw errors.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


hasTag() ​

hasTag(tag): boolean

Defined in: @minecraft/server/index.d.ts:4173

Parameters ​

tag ​

string

Tag 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 ​

checkBlockTags.ts

typescript
import { DimensionLocation } from '@minecraft/server';

function checkBlockTags(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) {
  // Fetch the block
  const block = targetLocation.dimension.getBlock(targetLocation);

  // check that the block is loaded
  if (block) {
    log(`Block is dirt: ${block.hasTag('dirt')}`);
    log(`Block is wood: ${block.hasTag('wood')}`);
    log(`Block is stone: ${block.hasTag('stone')}`);
  }
}

isLiquidBlocking() ​

isLiquidBlocking(liquidType): boolean

Defined in: @minecraft/server/index.d.ts:4190

Parameters ​

liquidType ​

Water

The type of liquid this function should be called for.

Returns ​

boolean

Whether this block stops liquid from flowing.

Remarks ​

Returns whether this block stops liquid from flowing.

Throws ​

This function can throw errors.

Error

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


liquidCanFlowFromDirection() ​

liquidCanFlowFromDirection(liquidType, flowDirection): boolean

Defined in: @minecraft/server/index.d.ts:4211

Parameters ​

liquidType ​

Water

The type of liquid this function should be called for.

flowDirection ​

Direction

Returns ​

boolean

Whether liquid can flow into the block from the provided direction, or flow out from the provided direction when liquid is placed into it with a bucket

Remarks ​

Returns whether liquid can flow into the block from the provided direction, or flow out from the provided direction when liquid is placed into it with a bucket.

Throws ​

This function can throw errors.

Error

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


liquidSpreadCausesSpawn() ​

liquidSpreadCausesSpawn(liquidType): boolean

Defined in: @minecraft/server/index.d.ts:4230

Parameters ​

liquidType ​

Water

The type of liquid this function should be called for.

Returns ​

boolean

Whether this block is removed and spawns its item when touched by liquid.

Remarks ​

Returns whether this block is removed and spawns its item when touched by liquid.

Throws ​

This function can throw errors.

Error

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


matches() ​

matches(blockName, states?): boolean

Defined in: @minecraft/server/index.d.ts:4247

Parameters ​

blockName ​

string

Block 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 | undefined

Defined in: @minecraft/server/index.d.ts:4262

Parameters ​

steps? ​

number

Number of steps to the north to step before returning. Defaults to: 1

Returns ​

Block | undefined

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 | undefined

Defined in: @minecraft/server/index.d.ts:4280

Parameters ​

offset ​

Vector3

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

Returns ​

Block | undefined

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

Defined in: @minecraft/server/index.d.ts:4297

Parameters ​

permutation ​

BlockPermutation

Permutation 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 restricted-execution mode.

Throws ​

This function can throw errors.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


setType() ​

setType(blockType): void

Defined in: @minecraft/server/index.d.ts:4315

Parameters ​

blockType ​

string | BlockType

Identifier 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 restricted-execution mode.

Throws ​

This function can throw errors.

Error

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


setWaterlogged() ​

setWaterlogged(isWaterlogged): void

Defined in: @minecraft/server/index.d.ts:4333

Parameters ​

isWaterlogged ​

boolean

true 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 restricted-execution mode.

Throws ​

This function can throw errors.

Error

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


south() ​

south(steps?): Block | undefined

Defined in: @minecraft/server/index.d.ts:4348

Parameters ​

steps? ​

number

Number of steps to the south to step before returning. Defaults to: 1

Returns ​

Block | undefined

Remarks ​

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

Throws ​

This function can throw errors.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


west() ​

west(steps?): Block | undefined

Defined in: @minecraft/server/index.d.ts:4363

Parameters ​

steps? ​

number

Number of steps to the west to step before returning. Defaults to: 1

Returns ​

Block | undefined

Remarks ​

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

Throws ​

This function can throw errors.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError