类 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).

当使用时,此属性可能会触发错误。

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

当使用时,此属性可能会触发错误。

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

当使用时,此属性可能会触发错误。

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError

isWaterlogged: boolean

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

Returns or sets whether this block has water on it.

当使用时,此属性可能会触发错误。

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError

location: Vector3

该方块的坐标。

Coordinates of the specified block.

当使用时,此属性可能会触发错误。

permutation: BlockPermutation

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

Additional block configuration data that describes the block.

当使用时,此属性可能会触发错误。

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError

type: BlockType

获取方块的类型。

Gets the type of block.

当使用时,此属性可能会触发错误。

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.

当使用时,此属性可能会触发错误。

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.

方法

  • 实验性

    参数

    • 可选steps: number

      返回之前要执行的步骤数。 留空默认为一。 (返回的方块在原方块上方的距离)。

      Number of steps above to step before returning.

    返回 Block

    返回该方块上方的 Block(Y 方向正方向)。

    Returns the Block above this block (positive in the Y direction).

    当使用时,此函数可能会触发错误。

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

  • 实验性

    参数

    • 可选steps: number

      向下的步数。 留空默认为一。

      Number of steps below to step before returning.

    返回 Block

    返回该方块下方的 Block(Y 方向负方向)。

    Returns the Block below this block (negative in the Y direction).

    当使用时,此函数可能会触发错误。

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

  • 实验性

    返回 Vector3

    返回该方块在 X 轴和 Z 轴上的中心的 Vector3

    Returns the Vector3 of the center of this block on the X and Z axis.

  • 实验性

    参数

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

    当使用时,此函数可能会触发错误。

    Error

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

  • 实验性

    参数

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

    当使用时,此函数可能会触发错误。

    Error

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

  • 实验性

    参数

    • 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

    当使用时,此函数可能会触发错误。

    Error

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

  • 实验性

    返回 Vector3

    返回该方块在 X、Y 和 Z 轴上中心的 Vector3

    Returns the Vector3 of the center of this block on the X, Y, and Z axis.

  • 实验性

    参数

    • 可选steps: number

      向东的步数。

      Number of steps to the east to step before returning.

    返回 Block

    返回位于该方块东侧(X 轴正方向)的 Block

    Returns the Block to the east of this block (positive in the X direction).

    当使用时,此函数可能会触发错误。

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

  • 实验性

    类型参数

    参数

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

    当使用时,此函数可能会触发错误。

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

  • 实验性

    参数

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

    当使用时,此函数可能会触发错误。

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

  • 实验性

    返回 number

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

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

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

    Returns the net redstone power of this block.

    当使用时,此函数可能会触发错误。

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

  • 实验性

    返回 string[]

    方块拥有的标签列表。

    The list of tags that the block has.

    返回方块被设置的标签的列表。

    Returns a set of tags for a block.

    当使用时,此函数可能会触发错误。

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

  • 实验性

    参数

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

    当使用时,此函数可能会触发错误。

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

    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.

    当使用时,此函数可能会触发错误。

    Error

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

  • 实验性

    返回 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.)

  • 实验性

    参数

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

  • 实验性

    参数

    • blockName: string

      要与此 API 匹配的方块类型标识符。

      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

    若此方块符合指定条件,则返回 true。

    Returns true if the block matches the specified criteria.

    测试此方块是否符合特定条件。

    Tests whether this block matches a specific criteria.

  • 实验性

    参数

    • 可选steps: number

      在返回之前,向北移动的步数。

      Number of steps to the north to step before returning.

    返回 Block

    返回位于该方块北侧(Z轴负方向)的 Block

    Returns the Block to the north of this block (negative in the Z direction).

  • 实验性

    参数

    • offset: Vector3

      偏移向量。例如,偏移量为 0, 1, 0 将返回当前方块 上方的方块。

    返回 Block

    指定偏移位置的方块,若无法获取该方块(例如, 该方块及其所在的区块尚未加载),则返回 undefined。

    返回一个相对于当前方块的偏移向量位置的方块。

    此函数可能会抛出错误。

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

  • 实验性

    参数

    • blockType: string | BlockType

      要应用的方块类型的标识符或方块类型, 例如,minecraft:powered_repeater

      Identifier of the type of block to apply - for example, minecraft:powered_repeater.

    返回 void

    设置方块的类型。

    Sets the type of block.

    无法在只读模式下调用此函数,详见 WorldBeforeEvents

  • 预览版 实验性

    参数

    • isWaterlogged: boolean

      true if the block should have water within it.

    返回 void

    Sets whether this block has a water logged state - for example, whether stairs are submerged within water.

    无法在只读模式下调用此函数,详见 WorldBeforeEvents

  • 实验性

    参数

    • 可选steps: number

      在返回之前,向南移动的步数。

      Number of steps to the south to step before returning.

    返回 Block

    返回位于该方块南侧(Z轴正方向)的 Block

    Returns the Block to the south of this block (positive in the Z direction).

  • 实验性

    参数

    返回 boolean

    若成功设置了方块的BlockPermutation, 则返回 true,否则返回 false

    Returns true if the block permutation data was successfully set, else false.

    首先检查放置是否有效, 如何尝试在维度中将方块设置为BlockPermutation的状态,

    Tries to set the block in the dimension to the state of the permutation by first checking if the placement is valid.

    无法在只读模式下调用此函数,详见 WorldBeforeEvents

  • 实验性

    参数

    • 可选steps: number

      在返回之前,向西移动的步数。

      Number of steps to the west to step before returning.

    返回 Block

    返回位于该方块西侧(X轴负方向)的 Block

    Returns the Block to the west of this block (negative in the X direction).