跳转至

Block

文档版本:1.21.0.24

Block类。代表维度中的一个方块。一个方块对应了一维度中唯一的X、Y和Z轴坐标值,可读取或修改该坐标下的方块状态等数据。

属性

dimension
read-only dimension: Dimension;
dimensionDimension
返回该方块所在的维度的对象。
isAir
read-only isAir: boolean;
isAirboolean
如果该方块为空气,值为true
isLiquid
read-only isLiquid: boolean;
isLiquidboolean
如果该方块属于液体方块(含水方块不属于液体方块),值为true
location
read-only location: Vector3;
locationVector3
该方块的坐标。
permutation
read-only permutation: BlockPermutation;
permutationBlockPermutation
该方块的置换。
type
read-only type: BlockType;
typeBlockType
该方块的类型。
typeId
read-only typeId: string;
typeIdstring
该方块的类型对应的标识符。
x
read-only x: int32;
xint32
该方块的X轴坐标值。
y
read-only y: int32;
yint32
该方块的Y轴坐标值。
z
read-only z: int32;
zint32
该方块的Z轴坐标值。

方法

above

获取位于该方块上方一定距离处的方块(即Y轴正方向延长线上的方块)。

above(steps: int32): Block | undefined
stepsint321
向Y轴正方向延伸的距离(以米为单位)。
返回值:Block|undefined
获取到的方块对象。
below

获取位于该方块下方一定距离处的方块(即Y轴负方向延长线上的方块)。

below(steps: int32): Block | undefined
stepsint321
向Y轴负方向延伸的距离(以米为单位)。
返回值:Block|undefined
获取到的方块对象。
bottomCenter

获取该方块底面中心处的坐标(即该方块在X和Z轴上的中心坐标)。

bottomCenter(): Vector3
返回值:Vector3
包含该方块底面中心处坐标值的Vector3对象。
center

获取该方块中心处的坐标(即该方块在X、Y和Z轴上的中心坐标)。

center(): Vector3
返回值:Vector3
包含该方块中心处坐标值的Vector3对象。
east

获取位于该方块东面一定距离处的方块(即X轴正方向延长线上的方块)。

east(steps: int32): Block | undefined
stepsint321
向X轴正方向延伸的距离(以米为单位)。
返回值:Block|undefined
获取到的方块对象。
getComponent

获取一个该方块的组件。

getComponent(componentId: string): BlockComponent | undefined
componentIdstring
要获取的组件的标识符。
返回值:BlockComponent|undefined
如果该方块具有这个组件,返回该组件的对象,否则返回undefined
getItemStack

创建一个基于该方块的物品堆叠。

getItemStack(amount: int32, withData: boolean): ItemStack | undefined
amountint321∈[1, 255]
该物品堆叠所含物品的数量。
withDatabooleanFalse
该物品堆叠是否附加用户数据。
返回值:ItemStack|undefined
创建出的物品堆叠对象。如果方块类型不兼容则返回undefined
getTags

获取该方块的所有标签。

getTags(): string[]
返回值:string[]
一个包含该方块所有标签的数组。
hasTag

检查该方块的置换中是否具有指定的标签。

hasTag(tag: string): boolean
tagstring
要检查的标签。
返回值:boolean
如果该方块的置换中具有此标签,返回true
isValid

检查该方块是否有效(被加载且在可放置方块范围内)。

isValid(): boolean
返回值:boolean
如果该方块有效,返回true
matches

测试该方块是否符合给定条件(方块类型和方块状态)。

matches(blockName: string, states?: Record<string, boolean | int32 | string>): boolean
blockNamestring
要测试的方块类型的标识符。
states?:Record<string, boolean | int32 | string>null
要测试的方块状态集合。
返回值:boolean
如果该方块符合给定的条件,返回true
north

获取位于该方块北面一定距离处的方块(即Z轴负方向延长线上的方块)。

north(steps: int32): Block | undefined
stepsint321
向Z轴负方向延伸的距离(以米为单位)。
返回值:Block|undefined
获取到的方块对象。
offset

获取相对于该方块位置给定偏移量处的方块。

offset(offset: Vector3): Block | undefined
offsetVector3
要偏移的量(以米为单位)。
返回值:Block|undefined
获取到的方块对象。
setPermutation

设置该方块的置换。

setPermutation(permutation: BlockPermutation): void
permutationBlockPermutation
要设置的置换的对象。
返回值:void
script_api.minecraft/server.block.setpermutation.return
setType

设置该方块的类型。

setType(blockType: BlockType | string): void
blockTypeBlockType|string
要设置的类型的标识符或BlockType对象。
返回值:void
script_api.minecraft/server.block.settype.return
south

获取位于该方块南面一定距离处的方块(即Z轴正方向延长线上的方块)。

south(steps: int32): Block | undefined
stepsint321
向Z轴正方向延伸的距离(以米为单位)。
返回值:Block|undefined
获取到的方块对象。
west

获取位于该方块西面一定距离处的方块(即X轴负方向延长线上的方块)。

west(steps: int32): Block | undefined
stepsint321
向X轴负方向延伸的距离(以米为单位)。
返回值:Block|undefined
获取到的方块对象。