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.

Hierarchy

  • Block

Constructors

  • Returns Block

Properties

dimension: Dimension

Remarks

Returns the dimension that the block is within.

isWaterlogged: boolean

Remarks

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

This property can't be edited in read-only mode.

location: Vector3

Remarks

Coordinates of the specified block.

Throws

This property can throw when used.

permutation: BlockPermutation

Remarks

Additional block configuration data that describes the block.

Throws

This property can throw when used.

type: BlockType

Remarks

Gets the type of block.

Throws

This property can throw when used.

typeId: string

Remarks

Identifier of the type of block for this block.

Throws

This property can throw when used.

x: number

Remarks

X coordinate of the block.

y: number

Remarks

Y coordinate of the block.

z: number

Remarks

Z coordinate of the block.

Methods

  • Beta

    Parameters

    • blockToPlace: BlockPermutation | BlockType

      Block type or block permutation to check placement for.

    • Optional faceToPlaceOn: Direction

      Optional 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

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

    Throws

    This function can throw errors.

  • Beta

    Parameters

    • componentName: string

      Identifier of the component. If a namespace is not specified, minecraft: is assumed.

    Returns undefined | BlockComponent

    Returns the component object if it is present on the particular block.

    Remarks

    Gets additional configuration properties (a component) for specific capabilities of particular blocks - for example, an inventory component of a chest block.

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

    Throws

    This function can throw errors.

  • Beta

    Parameters

    • Optional amount: number

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

    • Optional withData: boolean

      Whether additional data facets of the item stack are included.

    Returns ItemStack

    Remarks

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

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

  • Beta

    Returns undefined | number

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

    Remarks

    Returns the net redstone power of this block.

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

    Throws

    This function can throw errors.

  • Beta

    Returns string[]

    The list of tags that the block has.

    Remarks

    Returns a set of tags for a block.

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

    Throws

    This function can throw errors.

  • Beta

    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.

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

    Throws

    This function can throw errors.

    Example

    check_block_tags.js

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

    Returns boolean

    Remarks

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

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

    Throws

    This function can throw errors.

  • Beta

    Returns boolean

    Remarks

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

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

    Throws

    This function can throw errors.

  • Beta

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

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

    Throws

    This function can throw errors.

  • 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 read-only mode.

    Throws

    This function can throw errors.

  • Beta

    Parameters

    • blockType: 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 read-only mode.

    Throws

    This function can throw errors.

  • Beta

    Parameters

    • permutation: BlockPermutation

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