A class that represents a block mask.

Block masks are used to filter blocks in a world.

Many things use them, such as the spawn protection system, and many WorldEdit commands.

Constructors

  • Creates a new block mask.

    Parameters

    • blocks: Omit<BlockMaskFilter, "raw" | "rawsb" | "rawns">[] = []

      The filters for the block mask.

    • Optionaltype: "include" | "exclude" = "include"

      The type of the block mask.

    Returns Globals.modules.cmds.BlockMask

    A new block mask.

Properties

"#blocksList": BlockMaskFilter[] = []

The filters in the block mask.

[]
"#blockTypeIds": string[]

The block IDs and filters types in the block mask.

"#hasStates": boolean

Whether the block mask has any filters with block states.

type: "include" | "exclude" = "include"

The type of the block mask.

"include" will make it only select blocks included in the block mask

"exclude" will make it only select blocks that are not included in the block mask

"include"

Accessors

  • get blocks(): BlockMaskFilter[]

    The filters in the block mask.

    Returns BlockMaskFilter[]

  • set blocks(blocks: Omit<BlockMaskFilter, "raw" | "rawsb" | "rawns">[]): void

    Parameters

    Returns void

  • get blockTypes(): string[]

    The block IDs and filters types in the block mask.

    Returns string[]

  • get includesStates(): boolean

    Whether the block mask has any filters with block states.

    Returns boolean

  • get raw(): string

    The raw string representation of the block mask.

    Returns string

    e:preset:liquid,minecraft:example_block["facing"="west","fill_level"=5,"top_slot_bit"=true],tag:minecraft:example_tag
    

Methods

  • Evaluates the block IDs and filters types in the block mask.

    This method does the following things:

    • Removes any filters that have a block ID of "none" or "any".
    • Converts any filter that is missing its raw, rawsb, or rawns getter to a BlockMaskFilter that does have the getters.

    Returns void

  • Pushes new filters to the block mask.

    Parameters

    • ...blocks: Omit<BlockMaskFilter, "raw" | "rawsb" | "rawns">[]

      The filters to push to the block mask.

    Returns number

    The new amount of filters in the block mask.

  • Tests if a block matches the block mask.

    Parameters

    • block:
          | string
          | Block
          | BlockPermutation
          | BlockType
          | {
              states?: Record<string, string | number | boolean>;
              type: string | BlockType;
          }

      The block to test.

    • Optionalmode: "include" | "exclude" = ...

      The mode to test in. If specified, this paramter will override the block mask's type property.

    Returns boolean

    Whether the block matches the block mask.

  • Converts the block mask to a string.

    It returns the same value as BlockMask.prototype.raw.

    Returns string

    The raw string representation of the block mask.

  • Extracts a block mask from a string.

    Parameters

    • str: string

      The string to extract the block mask from.

    • OptionalextraIdParsingEnabled: boolean = true

      Whether to enable extra ID parsing. If emabled, filters with block IDs of "none" or "any" will be removed.

    • OptionalmodeOverride: "include" | "exclude"

      Override the mode of the block mask. If not provided, the mode will be determined based on the string.

    Returns Globals.modules.cmds.BlockMask

    The block mask extracted from the string.

  • Extracts all block masks from a string.

    Parameters

    • str: string

      The string to extract the block masks from.

    • OptionalextraIdParsingEnabled: boolean = true

      Whether to enable extra ID parsing. If emabled, filters with block IDs of "none" or "any" will be removed.

    • OptionalmodeOverride: "include" | "exclude"

      Override the mode of the block mask. If not provided, the mode will be determined based on the string.

    Returns Globals.modules.cmds.BlockMask[]

    The block masks extracted from the string.

  • Extracts the raw strings of all block masks from a string.

    Parameters

    • str: string

      The string to extract the block masks from.

    Returns string[]

    The raw strings of the block masks extracted from the string, or null if no block masks were found.

  • Extracts all block masks from a string and their raw strings.

    Parameters

    • str: string

      The string to extract the block masks from.

    • OptionalextraIdParsingEnabled: boolean = true

      Whether to enable extra ID parsing. If emabled, filters with block IDs of "none" or "any" will be removed. Only applies to the block masks, the raw strings are not affected.

    • OptionalmodeOverride: "include" | "exclude"

      Override the mode of the block mask. If not provided, the mode will be determined based on the string. Only applies to the block masks, the raw strings are not affected.

    Returns { parsed: Globals.modules.cmds.BlockMask[]; raw: string[] }

    An object containing the raw strings and the block masks extracted from the string.

  • Extracts a raw block mask from a string.

    Parameters

    • str: string

      The string to extract the raw block mask from.

    Returns string

    The raw block mask, or null if no raw block mask was found.

  • Extracts a block mask and its raw string from a string.

    Parameters

    • str: string

      The string to extract the block mask from.

    • OptionalextraIdParsingEnabled: boolean = true

      Whether to enable extra ID parsing. If emabled, filters with block IDs of "none" or "any" will be removed. Only applies to the block mask, the raw string is not affected.

    • OptionalmodeOverride: "include" | "exclude"

      Override the mode of the block mask. If not provided, the mode will be determined based on the string. Only applies to the block mask, the raw string is not affected.

    Returns { parsed: Globals.modules.cmds.BlockMask; raw: string }

    The raw string and the block mask extracted from the string.

  • Parses a string into a BlockMask object.

    Returns void

    This function is non-functional, and does absolutely nothing.

  • Tests if the states in the first parameter extend the states in the second parameter.

    Parameters

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

      The states to test.

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

      The states to test against.

    Returns boolean

    True if the states in the first parameter extend the states in the second parameter, false otherwise.

    const BlockMask = modules.cmds.BlockMask;

    const states = {
    "foo": true,
    "bar": false,
    };
    const statesMask = {
    "foo": true,
    "bar": true,
    };
    const result = BlockMask.testForStatesMatch(states, statesMask);
    console.log(result); // false
    const BlockMask = modules.cmds.BlockMask;

    const states = {
    "foo": true,
    "bar": false,
    };
    const statesMask = {
    "foo": true,
    };
    const result = BlockMask.testForStatesMatch(states, statesMask);
    console.log(result); // true
    const BlockMask = modules.cmds.BlockMask;

    const states = {
    "foo": true,
    "bar": false,
    };
    const statesMask = {
    "foo": true,
    "bar": false,
    "baz": false,
    };
    const result = BlockMask.testForStatesMatch(states, statesMask);
    console.log(result); // false