Class BlockPermutation

Contains the combination of type BlockType and properties (also sometimes called block state) which describe a block (but does not belong to a specific Block).

Hierarchy

  • BlockPermutation

Constructors

Properties

type: BlockType

Remarks

The BlockType that the permutation has.

Methods

  • Beta

    Returns BlockPermutation

    A copy of the permutation.

    Remarks

    Creates a copy of this permutation.

  • Beta

    Returns Record<string, string | number | boolean>

    Returns the list of all of the block states that the permutation has.

    Remarks

    Returns all available block states associated with this block.

  • Beta

    Parameters

    • Optional amount: number

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

    Returns ItemStack

    Remarks

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

  • Beta

    Parameters

    • stateName: string

      Name of the block state who's value is to be returned.

    Returns undefined | string | number | boolean

    Returns the state if the permutation has it, else undefined.

    Remarks

    Gets a state for the permutation.

  • Beta

    Returns string[]

    Remarks

    Creates a copy of the permutation.

  • Beta

    Parameters

    • tag: string

    Returns boolean

    Returns true if the permutation has the tag, else false.

    Remarks

    Checks to see if the permutation has a specific tag.

    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 });
    const blockPerm = block.getPermutation();

    console.log(`Block is dirt: ${blockPerm.hasTag("dirt")}`);
    console.log(`Block is wood: ${blockPerm.hasTag("wood")}`);
    console.log(`Block is stone: ${blockPerm.hasTag("stone")}`);
  • Parameters

    • blockName: string

      An optional set of states to compare against.

    • Optional states: Record<string, string | number | boolean>

    Returns boolean

    Remarks

    Returns a boolean whether a specified permutation matches this permutation. If states is not specified, matches checks against the set of types more broadly.

  • Beta

    Parameters

    • name: string

      Identifier of the block property.

    • value: string | number | boolean

      Value of the block property.

    Returns BlockPermutation

    Remarks

    Returns a derived BlockPermutation with a specific property set.

    Throws

    This function can throw errors.

  • Parameters

    • blockName: string

      Identifier of the block to check.

    • Optional states: Record<string, string | number | boolean>

    Returns BlockPermutation

    Remarks

    Given a type identifier and an optional set of properties, will return a BlockPermutation object that is usable in other block APIs (e.g., block.setPermutation)

    Throws

    This function can throw errors.

    Example

    addBlockColorCube.ts

      const allColorNames: string[] = [
    "white",
    "orange",
    "magenta",
    "light_blue",
    "yellow",
    "lime",
    "pink",
    "gray",
    "silver",
    "cyan",
    "purple",
    "blue",
    "brown",
    "green",
    "red",
    "black",
    ];

    const cubeDim = 7;

    let colorIndex = 0;

    for (let x = 0; x <= cubeDim; x++) {
    for (let y = 0; y <= cubeDim; y++) {
    for (let z = 0; z <= cubeDim; z++) {
    colorIndex++;
    overworld
    .getBlock({ x: targetLocation.x + x, y: targetLocation.y + y, z: targetLocation.z + z })
    ?.setPermutation(
    mc.BlockPermutation.resolve("minecraft:wool", {
    color: allColorNames[colorIndex % allColorNames.length],
    })
    );
    }
    }
    }