类 BlockPermutation实验性

表示一个由 BlockType 类型和属性(有时也称为方块状态)组成的组合, 用于描述一个方块(但不属于特定的 Block)。

import { world, BlockPermutation, BlockSignComponent, BlockComponentTypes, DimensionLocation } from "@minecraft/server";
import { MinecraftBlockTypes } from "@minecraft/vanilla-data";

function addTranslatedSign(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) {
const players = world.getPlayers();

const dim = players[0].dimension;

const signBlock = dim.getBlock(targetLocation);

if (!signBlock) {
log("Could not find a block at specified location.");
return -1;
}
const signPerm = BlockPermutation.resolve(MinecraftBlockTypes.StandingSign, { ground_sign_direction: 8 });

signBlock.setPermutation(signPerm);

const signComponent = signBlock.getComponent(BlockComponentTypes.Sign) as BlockSignComponent;

signComponent?.setText({ translate: "item.skull.player.name", with: [players[0].name] });
}
  • 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).
import { world, BlockPermutation, BlockSignComponent, BlockComponentTypes, DimensionLocation } from "@minecraft/server";
import { MinecraftBlockTypes } from "@minecraft/vanilla-data";

function addTranslatedSign(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) {
const players = world.getPlayers();

const dim = players[0].dimension;

const signBlock = dim.getBlock(targetLocation);

if (!signBlock) {
log("Could not find a block at specified location.");
return -1;
}
const signPerm = BlockPermutation.resolve(MinecraftBlockTypes.StandingSign, { ground_sign_direction: 8 });

signBlock.setPermutation(signPerm);

const signComponent = signBlock.getComponent(BlockComponentTypes.Sign) as BlockSignComponent;

signComponent?.setText({ translate: "item.skull.player.name", with: [players[0].name] });
}

属性

type: BlockType

表示当前组合的 BlockType

The BlockType that the permutation has.

方法

  • 实验性

    参数

    • liquidType: Water

      此函数需要检测的液体类型。

      The type of liquid this function should be called for.

    返回 boolean

    返回此方块在被液体接触时是否会被移除。

    Whether this block is removed when touched by liquid.

    返回此方块在被液体接触时是否会被移除。

    Returns whether this block is removed when touched by liquid.

    This function can throw errors.

    Error

  • 实验性

    参数

    • liquidType: Water

      此函数需要检测的液体类型。

      The type of liquid this function should be called for.

    返回 boolean

    返回此方块是否可以覆盖液体。

    Whether this block can have a liquid placed over it.

    返回此方块是否可以覆盖液体,例如是否可以被水浸透。

    Returns whether this block can have a liquid placed over it, i.e. be waterlogged.

    This function can throw errors.

    Error

  • 实验性

    返回 Record<string, string | number | boolean>

    返回此组合拥有的所有方块状态的列表。

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

    返回与此方块关联的所有可用的方块状态。

    Returns all available block states associated with this block.

  • 实验性

    参数

    • 可选amount: number

      放置在原型物品堆中的此方块实例的数量。

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

    返回 ItemStack

    基于此方块组合检索一个原型物品堆,可用于物品容器/容器槽 API。

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

  • 实验性

    类型参数

    参数

    • stateName: T

      要获取其值的方块状态的名称。

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

    返回 BlockStateSuperset[T]

    若此组合拥有该状态则返回状态值,否则返回 undefined

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

    获取此组合的某个状态。

    Gets a state for the permutation.

  • 实验性

    返回 string[]

    创建此组合的副本。

    Creates a copy of the permutation.

  • 实验性

    参数

    • tag: string

    返回 boolean

    若此组合具有该标签则返回 true,否则返回 false

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

    检查此组合是否具有特定的标签。

    Checks to see if the permutation 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")}`);
    }
    }
  • 实验性

    参数

    • liquidType: Water

      此函数需要检测的液体类型。

      The type of liquid this function should be called for.

    返回 boolean

    返回此方块是否阻止液体流动。

    Whether this block stops liquid from flowing.

    返回此方块是否阻止液体流动。

    Returns whether this block stops liquid from flowing.

    This function can throw errors.

    Error

  • 实验性

    参数

    • liquidType: Water

      此函数需要检测的液体类型。

      The type of liquid this function should be called for.

    返回 boolean

    返回此方块在被液体接触时是否会被移除并生成其物品。

    Whether this block is removed and spawns its item when touched by liquid.

    返回此方块在被液体接触时是否会被移除并生成其物品。

    Returns whether this block is removed and spawns its item when touched by liquid.

    This function can throw errors.

    Error

  • 实验性

    类型参数

    参数

    • blockName: T

      一个可选的状态集合,用于进行比较。 An optional set of states to compare against.

    • 可选states: BlockStateArg<T>

    返回 boolean

    返回一个布尔值,指示指定的组合是否与此组合匹配。 若未指定状态,则匹配会更广泛地检查类型集合。

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

  • 实验性

    类型参数

    参数

    • name: T

      方块属性的标识符。 Identifier of the block property.

    • value: BlockStateSuperset[T]

      方块属性的值。 Value of the block property.

    返回 BlockPermutation

    返回具有特定属性设置的派生 BlockPermutation。

    Returns a derived BlockPermutation with a specific property set.

    This function can throw errors.

  • 实验性

    类型参数

    参数

    • blockName: T

      要检查的方块的标识符。

      Identifier of the block to check.

    • 可选states: BlockStateArg<T>

    返回 BlockPermutation

    给定一个类型标识符和一个可选的属性集合, 将返回一个可在其他方块 API 中使用的 BlockPermutation(方块参数) 对象(例如,block.setPermutation)。

    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)

    This function can throw errors.

    import { BlockPermutation, DimensionLocation } from "@minecraft/server";
    import { Vector3Utils } from "@minecraft/math";
    import { MinecraftBlockTypes } from "@minecraft/vanilla-data";

    function addBlockColorCube(targetLocation: DimensionLocation) {
    const allWoolBlocks: string[] = [
    MinecraftBlockTypes.WhiteWool,
    MinecraftBlockTypes.OrangeWool,
    MinecraftBlockTypes.MagentaWool,
    MinecraftBlockTypes.LightBlueWool,
    MinecraftBlockTypes.YellowWool,
    MinecraftBlockTypes.LimeWool,
    MinecraftBlockTypes.PinkWool,
    MinecraftBlockTypes.GrayWool,
    MinecraftBlockTypes.LightGrayWool,
    MinecraftBlockTypes.CyanWool,
    MinecraftBlockTypes.PurpleWool,
    MinecraftBlockTypes.BlueWool,
    MinecraftBlockTypes.BrownWool,
    MinecraftBlockTypes.GreenWool,
    MinecraftBlockTypes.RedWool,
    MinecraftBlockTypes.BlackWool,
    ];

    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++;
    targetLocation.dimension
    .getBlock(Vector3Utils.add(targetLocation, { x, y, z }))
    ?.setPermutation(BlockPermutation.resolve(allWoolBlocks[colorIndex % allWoolBlocks.length]));
    }
    }
    }
    }