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

Methods

Constructors

Methods

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

  • 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],
    })
    );
    }
    }
    }