@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 ​
readonlydimension:Dimension
Defined in: @minecraft/server/index.d.ts:3794
Remarks ​
Returns the dimension that the block is within.
isAir ​
readonlyisAir: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.
LocationOutOfWorldBoundariesError
isLiquid ​
readonlyisLiquid: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.
LocationOutOfWorldBoundariesError
isValid ​
readonlyisValid: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 ​
readonlyisWaterlogged: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.
LocationOutOfWorldBoundariesError
localizationKey ​
readonlylocalizationKey: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.
LocationOutOfWorldBoundariesError
location ​
readonlylocation:Vector3
Defined in: @minecraft/server/index.d.ts:3858
Remarks ​
Coordinates of the specified block.
Throws ​
This property can throw when used.
permutation ​
readonlypermutation: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.
LocationOutOfWorldBoundariesError
type ​
readonlytype:BlockType
Defined in: @minecraft/server/index.d.ts:3881
Remarks ​
Gets the type of block.
Throws ​
This property can throw when used.
LocationOutOfWorldBoundariesError
typeId ​
readonlytypeId: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.
LocationOutOfWorldBoundariesError
x ​
readonlyx:number
Defined in: @minecraft/server/index.d.ts:3900
Remarks ​
X coordinate of the block.
y ​
readonlyy:number
Defined in: @minecraft/server/index.d.ts:3906
Remarks ​
Y coordinate of the block.
z ​
readonlyz: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.
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.
LocationOutOfWorldBoundariesError
bottomCenter() ​
bottomCenter():
Vector3
Defined in: @minecraft/server/index.d.ts:3949
Returns ​
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 ​
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
LocationOutOfWorldBoundariesError
canContainLiquid() ​
canContainLiquid(
liquidType):boolean
Defined in: @minecraft/server/index.d.ts:3985
Parameters ​
liquidType ​
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
LocationOutOfWorldBoundariesError
center() ​
center():
Vector3
Defined in: @minecraft/server/index.d.ts:3992
Returns ​
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.
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.
LocationOutOfWorldBoundariesError
getComponents() ​
getComponents():
BlockComponent[]
Defined in: @minecraft/server/index.d.ts:4041
Returns ​
Remarks ​
Returns all scripting components that are present on this block.
Throws ​
This function can throw errors.
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.
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
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.
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
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.
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.
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.
LocationOutOfWorldBoundariesError
Example ​
checkBlockTags.ts
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 ​
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
LocationOutOfWorldBoundariesError
liquidCanFlowFromDirection() ​
liquidCanFlowFromDirection(
liquidType,flowDirection):boolean
Defined in: @minecraft/server/index.d.ts:4211
Parameters ​
liquidType ​
The type of liquid this function should be called for.
flowDirection ​
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
LocationOutOfWorldBoundariesError
liquidSpreadCausesSpawn() ​
liquidSpreadCausesSpawn(
liquidType):boolean
Defined in: @minecraft/server/index.d.ts:4230
Parameters ​
liquidType ​
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
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.
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.
LocationOutOfWorldBoundariesError
offset() ​
offset(
offset):Block|undefined
Defined in: @minecraft/server/index.d.ts:4280
Parameters ​
offset ​
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.
LocationOutOfWorldBoundariesError
setPermutation() ​
setPermutation(
permutation):void
Defined in: @minecraft/server/index.d.ts:4297
Parameters ​
permutation ​
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.
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
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
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.
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.