类 Block实验性

表示世界维度中的特定位置的方块。 方块对象对应了唯一的 X、Y、Z 与维度,可用于读取或修改此位置的方块状态。 此类型在 1.17.10.21 有重大更新。

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.

属性

dimension: Dimension

返回方块所在维度对象。

Returns the dimension that the block is within.

方块所在维度对象。

isAir: boolean

返回 true 如果这个方块是空气方块(例如,空的空间)

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

This property can throw when used.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError

isLiquid: boolean

如果这个方块是液体方块,例如水方块和熔岩方块等,则返回 true。 空气方块和石头方块等则不属于液体方块。 含水方块不算作液体方块。

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

This property can throw when used.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError

isSolid: boolean

如果该块是实心且不可通行的,则返回 true -(例如,鹅卵石块和钻石块是实心的,而梯子块和栅栏块则不是)。

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 property can throw when used.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError

isWaterlogged: boolean

返回或设置该方块是否含水。

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

This property can throw when used.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError

location: Vector3

该方块的坐标。

Coordinates of the specified block.

This property can throw when used.

permutation: BlockPermutation

描述该方块的附加配置数据。 (常称为方块状态)

Additional block configuration data that describes the block.

This property can throw when used.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError

type: BlockType

获取方块的类型。

Gets the type of block.

This property can throw when used.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError

typeId: string

该方块的类型标识符。

Identifier of the type of block for this block. Warning: Vanilla block names can be changed in future releases, try using 'Block.matches' instead for block comparison.

This property can throw when used.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError

x: number

方块的 X 坐标。

X coordinate of the block.

y: number

方块的 Y 坐标。

Y coordinate of the block.

z: number

方块的 Z 坐标。

Z coordinate of the block.

方法

  • 实验性

    参数

    • blockToPlace: string | BlockPermutation | BlockType

      被检查放置可行性的BlockPermutationBlockType或方块标识符。

      Block type or block permutation to check placement for.

    • 可选faceToPlaceOn: Direction

      被检查放置的方向(可选)。

      Optional specific face of this block to check placement against.

    返回 boolean

    如果在此面可以放置这样的方块则返回 true

    Returns true if the block type or permutation can be placed on this block, else false.

    检查在该方块的指定面上放置BlockPermutationBlockType或指定标识符的方块是否可行。

    Checks to see whether it is valid to place the specified block type or block permutation, on a specified face on this block

  • 实验性

    类型参数

    参数

    • componentId: T

      组件的标识符 (例如 'minecraft:inventory')。 如果未指定命名空间前缀,将默认使用 'minecraft:'。 可用的组件标识符可以在 BlockComponentTypes 枚举中找到。

      The identifier of the component (e.g., 'minecraft:inventory'). If no namespace prefix is specified, 'minecraft:' is assumed. Available component IDs can be found as part of the BlockComponentTypes enum.

    返回 BlockComponentTypeMap[T]

    如果该组件存在于该方块,则返回该组件。 否则返回 undefined。

    Returns the component if it exists on the block, otherwise undefined.

    获取一个方块的组件(代表附加功能),例如,一个箱子方块的库存组件。

    Gets a component (that represents additional capabilities) for a block - for example, an inventory component of a chest block.

  • 实验性

    参数

    • 可选amount: number

      要设置在物品对象-ItemStack中的这个方块的数量。

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

    • 可选withData: boolean

      是否包括物品对象的附加数据。

      Whether additional data facets of the item stack are included.

    返回 ItemStack

    一个带有指定数量和数据的物品对象。 如果方块类型不兼容,则返回 undefined。

    An itemStack with the specified amount of items and data. Returns undefined if block type is incompatible.

    创建一个基于该方块的原型物品对象-ItemStack,可以与 Container/ContainerSlot 接口 一起使用。

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

  • 实验性

    返回 number

    如果这个方块不适用红石能量,返回 undefined。

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

    返回该方块的净红石能量强度。 考虑了所有输入和输出后的总红石能量强度。 表示了一个方块与周围环境中所有红石元件的相互作用后的红石能量状态。

    Returns the net redstone power of this block.

  • 实验性

    参数

    • tag: string

      要检查的标签。

      Tag to check for.

    返回 boolean

    如果该方块的BlockPermutation具有该标签,则返回 true,否则返回 false

    Returns true if the permutation of this block has the tag, else false.

    检查该方块的BlockPermutation是否具有特定的标签。

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

    返回 boolean

    如果这个方块对象仍然存在且有效,则返回 true

    True if this block object is still working and valid.

    如果对该方块的引用仍然有效,则返回 true(例如,如果方块未加载,对该方块的引用将不再有效)。

    Returns true if this reference to a block is still valid (for example, if the block is unloaded, references to that block will no longer be valid.)

  • 实验性

    参数

    • blockName: string

      Block type identifier to match this API against.

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

      Optional set of block states to test this block against.

    返回 boolean

    Returns true if the block matches the specified criteria.

    Tests whether this block matches a specific criteria.