@minecraft/server
    Preparing search index...

    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.

    Index

    Properties

    dimension: Dimension

    Returns the dimension that the block is within.

    isAir: boolean

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

    This property can throw when used.

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

    isLiquid: boolean

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

    This property can throw when used.

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

    isWaterlogged: boolean

    Returns or sets whether this block has water on it.

    This property can throw when used.

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

    location: Vector3

    Coordinates of the specified block.

    This property can throw when used.

    permutation: BlockPermutation

    Additional block configuration data that describes the block.

    This property can throw when used.

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

    type: BlockType

    Gets the type of block.

    This property can throw when used.

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

    typeId: string

    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.

    This property can throw when used.

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

    x: number

    X coordinate of the block.

    y: number

    Y coordinate of the block.

    z: number

    Z coordinate of the block.

    Methods

    • Parameters

      • Optionalsteps: number

        Number of steps above to step before returning.

      Returns undefined | Block

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

    • Parameters

      • Optionalsteps: number

        Number of steps below to step before returning.

      Returns undefined | Block

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

    • Returns Vector3

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

    • Parameters

      • liquidType: Water

        The type of liquid this function should be called for.

      Returns boolean

      Whether this block is removed when touched by liquid.

      Returns whether this block is removed when touched by liquid.

      This function can throw errors.

      Error

      LocationInUnloadedChunkError

      LocationOutOfWorldBoundariesError

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

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

      This function can throw errors.

      Error

      LocationInUnloadedChunkError

      LocationOutOfWorldBoundariesError

    • Returns Vector3

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

    • Parameters

      • Optionalsteps: number

        Number of steps to the east to step before returning.

      Returns undefined | Block

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

    • Type Parameters

      • 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 can be found as part of the BlockComponentTypes enum.

      Returns undefined | BlockComponentReturnType<T>

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

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

    • Parameters

      • Optionalamount: number

        Number of instances of this block to place in the item stack.

      • OptionalwithData: boolean

        Whether additional data facets of the item stack are included.

      Returns undefined | ItemStack

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

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

    • Returns undefined | number

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

      Returns the net redstone power of this block.

    • Parameters

      • tag: string

        Tag to check for.

      Returns boolean

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

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

      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")}`);
      }
      }
    • Parameters

      • liquidType: Water

        The type of liquid this function should be called for.

      Returns boolean

      Whether this block stops liquid from flowing.

      Returns whether this block stops liquid from flowing.

      This function can throw errors.

      Error

      LocationInUnloadedChunkError

      LocationOutOfWorldBoundariesError

    • Returns boolean

      True if this block object is still working and valid.

      This function is deprecated and will be removed in 2.0.0.

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

    • 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

      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.

      This function can throw errors.

      Error

      LocationInUnloadedChunkError

      LocationOutOfWorldBoundariesError

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

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

      This function can throw errors.

      Error

      LocationInUnloadedChunkError

      LocationOutOfWorldBoundariesError

    • Parameters

      • blockName: string

        Block type identifier to match this API against.

      • Optionalstates: 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.

      Tests whether this block matches a specific criteria.

    • Parameters

      • Optionalsteps: number

        Number of steps to the north to step before returning.

      Returns undefined | Block

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

    • Parameters

      • offset: Vector3

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

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

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

    • Parameters

      • blockType: string | BlockType

        Identifier of the type of block to apply - for example, minecraft:powered_repeater.

      Returns void

      Sets the type of block.

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

      This function can throw errors.

      Error

      LocationInUnloadedChunkError

      LocationOutOfWorldBoundariesError

    • Parameters

      • isWaterlogged: boolean

        true if the block should have water within it.

      Returns void

      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.

      This function can throw errors.

      Error

      LocationInUnloadedChunkError

      LocationOutOfWorldBoundariesError

    • Parameters

      • Optionalsteps: number

        Number of steps to the south to step before returning.

      Returns undefined | Block

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

    • Parameters

      • Optionalsteps: number

        Number of steps to the west to step before returning.

      Returns undefined | Block

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