@minecraft
    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

    isSolid: boolean

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

    This property can throw when used.

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

    isValid: boolean

    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: boolean

    Returns or sets whether this block has water on it.

    This property can throw when used.

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

    localizationKey: string

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

    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

      • Optionalamount: number

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

      • OptionalwithData: boolean

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

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

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

      • 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

      • blockName: string

        Block type identifier to match this API against.

      • Optionalstates: Record<string, boolean | number | string>

        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.