🧱 方块(Block)#

#bs.block:help

Manipulate blocks with their states and NBT, and combine block properties.

“建筑是深思熟虑的空间创造。”

—路易斯·康(Louis Kahn)

虚拟方块格式

为了操作方块及其状态,Bookshelf 使用存储在方块输出中的虚拟方块格式。切勿手动更新虚拟方块格式,而应使用库中提供的辅助函数。


🔧 函数#

你可以在下方找到此模块中的所有可用函数。


生成粒子#

#bs.block:emit_block_particle

发射指定方块的方块粒子。

输入:

执行 at <entity>positioned <x> <y> <z>:默认 type 的位置,也是 pos 的参考位置。

命令存储 bs:in block.emit_block_particle

  • 粒子数据

    • type:方块类型(例如 minecraft:stone)。

      如果省略,将使用当前执行位置的方块类型。

    • properties:方块属性(例如 {facing:"east"})。

      仅在 type 存在时考虑。

    • pos:X Y Z 坐标,生成粒子的位置(默认:~ ~ ~)。

    • delta:X Y Z 值,以方块为单位的随机散布范围(默认:0 0 0)。

    • speed: 粒子的速度(默认:1)。

    • count:生成的粒子数量(默认:1)。

    • mode: 显示模式:normalforce(默认:normal)。

    • viewers: 控制哪些玩家能看到这些粒子(默认:@a)。

输出:

状态:粒子被发射。

示例:在脚下方块处生成粒子效果:

# Setup the input
data modify storage bs:in block.emit_block_particle set value { pos: "~ ~.5 ~", speed: 5, count: 30 }

# Emit the block particle (block below your feet)
execute positioned ~ ~-.5 ~ run function #bs.block:emit_block_particle

示例:在位置 0 0 0 的方块处生成粒子效果:

# Get block data
execute positioned 0 0 0 run function #bs.block:get_type

# Setup the input with the retrieved block data
data modify storage bs:in block.emit_block_particle set from storage bs:out block
data modify storage bs:in block.emit_block_particle merge value { speed: 5, count: 30 }

# Emit the block particle
function #bs.block:emit_block_particle

贡献者:Aksiome、theogiraudet


填充方块#

#bs.block:fill_block

用指定方块填充部分或全部区域。

输入:

命令存储 bs:in block.fill_block

  • 填充数据

    • block: 要填充的方块。

    • from:起始位置,须为有效的坐标字符串。

    • to:结束位置,须为有效的坐标字符串。

    • mode:设置方块时使用的模式 [outline|hollow|destroy|keep|replace|strict](默认:replace)。

    • filter:用作过滤器的方块(默认:none)。

输出:

状态:方块被放置在世界中。

示例:用石头填充区域:

# Setup the input
data modify storage bs:in block.fill_block set value {block:"minecraft:stone",from:"~-3 ~-3 ~-3",to:"~3 ~3 ~3"}

# Run the fill
function #bs.block:fill_block
#bs.block:fill_type

对部分或全部区域更改方块类型,同时保留方块状态和NBT。

输入:

命令存储 bs:in block.fill_type

  • 填充数据

    • type: 要填充的方块的id。

    • from:起始位置,须为有效的坐标字符串。

    • to:结束位置,须为有效的坐标字符串。

    • mode:设置方块时使用的模式 [outline|hollow|destroy|keep|replace|strict](默认:replace)。

    • filter:用作过滤器的方块(默认:none)。

输出:

状态:方块被放置在世界中。

示例:将橡木楼梯替换为云杉木楼梯并保留方块状态,完成时使用say命令:

# Setup the input
data modify storage bs:in block.fill_type set value {type:"minecraft:spruce_stairs",from:"~-3 ~-3 ~-3",to:"~3 ~3 ~3",filter:"minecraft:oak_stairs"}

# Run the process
function #bs.block:fill_type

贡献者:Aksiome


获取方块#

#bs.block:get_block

获取当前位置方块的所有相关数据,包括其状态和NBT。

输入:

执行 at <实体>positioned <x> <y> <z>:获取方块数据的位置。

输出:

命令存储 bs:out block

  • [只读] 方块数据

    • group: 在同一个组的方块共享相同的可能的方块状态(比如:所有的楼梯)。

    • block: 方块的完整字符串表示方块id[方块状态]{nbt}

    • item: 方块对应的物品名字符串,可能不存在。

    • type: 方块id的字符串表示(比如:minecraft:stone)。

    • state: 方块状态的完整字符串表示(比如:[shape=straight]),可能不存在。

    • nbt: 方块数据的完整字符串表示,可能不存在。

    • properties: 方块状态的数据表示(用于下落的方块之类的实体),可能不存在。

示例:获取脚下方块的数据:

# Run the get function on a block
execute positioned ~ ~-.5 ~ run function #bs.block:get_block

# See the result
data get storage bs:out block
#bs.block:get_type

获取当前位置的方块类型。虽然此函数输出的状态、NBT和属性为空,但这不影响管理方块状态的函数的运行。

输入:

执行 at <实体>positioned <x> <y> <z>:获取方块数据的位置。

输出:

命令存储 bs:out block

  • [只读] 方块数据

    • group: 在同一个组的方块共享相同的可能的方块状态(比如:所有的楼梯)。

    • block: 方块的完整字符串表示(仅方块类型)。

    • item: 方块对应的物品名字符串,可能不存在。

    • type: 方块id的字符串表示(比如:minecraft:stone)。

示例:获取脚下方块的类型数据:

# Run the get function on a block
execute positioned ~ ~-.5 ~ run function #bs.block:get_type

# See the result
data get storage bs:out block

只读输出

bs:out block 输出是只读的。手动修改部分内容可能导致潜在漏洞。因此,模块提供了许多可以修改输出的函数来保证它的完整性。

贡献者:Aksiome、theogiraudet


获取附加属性#

#bs.block:get_blast_resistance

获取当前位置方块的爆炸抗性值。

输入:

执行 at <实体>positioned <x> <y> <z>:获取方块数据的位置。

输出:

命令存储 bs:out block

  • [只读] 方块数据

    • blast_resistance:该位置的方块的爆炸抗性。

什么是爆炸抗性?

爆炸抗性是一个数值,Minecraft 用它来确定方块抵抗爆炸的能力。数值越高,方块就越难被 TNT、苦力怕或其他爆炸摧毁。

示例:获取脚下方块的爆炸抗性:

# Run the get function on a block
execute positioned ~ ~-.5 ~ run function #bs.block:get_blast_resistance

# See the result
data get storage bs:out block
#bs.block:get_friction

获取当前位置方块的摩擦力值。

输入:

执行 at <实体>positioned <x> <y> <z>:获取方块数据的位置。

输出:

命令存储 bs:out block

  • [只读] 方块数据

    • friction:该位置方块的摩擦力。

什么是摩擦力?

摩擦力是一个数值,Minecraft 用它来确定方块的滑度。例如,石头的摩擦力为 0.6,而冰的摩擦力更高,为 0.98

示例:获取脚下方块的摩擦力:

# Run the get function on a block
execute positioned ~ ~-.5 ~ run function #bs.block:get_friction

# See the result
data get storage bs:out block
#bs.block:get_hardness

获取当前位置方块的硬度值。

输入:

执行 at <实体>positioned <x> <y> <z>:获取方块数据的位置。

输出:

命令存储 bs:out block

  • [只读] 方块数据

    • hardness:该位置的方块的硬度。

什么是硬度?

硬度是一个数值,Minecraft 用它来确定用工具破坏方块所需的时间。例如,石头的硬度比泥土高,黑曜石拥有游戏中最高的硬度之一。

示例:获取脚下方块的硬度:

# Run the get function on a block
execute positioned ~ ~-.5 ~ run function #bs.block:get_hardness

# See the result
data get storage bs:out block
#bs.block:get_instrument

获取当前位置方块的音符盒乐器(例如 harpbasssnare)。

输入:

执行 at <实体>positioned <x> <y> <z>:获取方块数据的位置。

输出:

命令存储 bs:out block

  • [只读] 方块数据

    • instrument:该位置方块的乐器。

示例:获取脚下方块的乐器:

# Run the get function on a block
execute positioned ~ ~-.5 ~ run function #bs.block:get_instrument

# See the result
data get storage bs:out block
#bs.block:get_jump_factor

获取当前位置方块的跳跃因子数值。

输入:

执行 at <实体>positioned <x> <y> <z>:获取方块数据的位置。

输出:

命令存储 bs:out block

  • [只读] 方块数据

    • jump_factor:该位置的方块的跳跃系数。

示例:获取脚下方块的跳跃因子:

# Run the get function on a block
execute positioned ~ ~-.5 ~ run function #bs.block:get_jump_factor

# See the result
data get storage bs:out block
#bs.block:get_luminance

获取当前位置方块的亮度值。亮度可能取决于方块属性。例如,light 方块可能根据其等级具有不同的亮度值。

输入:

执行 at <实体>positioned <x> <y> <z>:获取方块数据的位置。

输出:

命令存储 bs:out block

  • [只读] 方块数据

    • luminance:该位置的方块的亮度。

示例:获取脚下方块的光照度:

# Run the get function on a block
execute positioned ~ ~-.5 ~ run function #bs.block:get_luminance

# See the result
data get storage bs:out block
#bs.block:get_sounds

获取当前位置方块的声音。

输入:

执行 at <实体>positioned <x> <y> <z>:获取方块数据的位置。

输出:

命令存储 bs:out block

  • [只读] 方块数据

    • sounds:方块的声音。

      • break: 玩家破坏方块时的声音。

      • fall: 玩家掉在方块上时的声音。

      • hit: 玩家敲击方块时的声音。

      • place: 玩家放置方块时的声音。

      • step: 玩家在方块上走路时的声音。

示例:获取脚下方块的声音:

# Run the get function on a block
execute positioned ~ ~-.5 ~ run function #bs.block:get_sounds

# See the result
data get storage bs:out block
#bs.block:get_speed_factor

获取当前位置方块的速度因子值。

输入:

执行 at <实体>positioned <x> <y> <z>:获取方块数据的位置。

输出:

命令存储 bs:out block

  • [只读] 方块数据

    • speed_factor:该位置的方块的速度系数。

示例:获取脚下方块的速度因子:

# Run the get function on a block
execute positioned ~ ~-.5 ~ run function #bs.block:get_speed_factor

# See the result
data get storage bs:out block

小技巧

这些函数将结果合并到 bs:out block 中,而不是替换它。这意味着之前获取的方块数据(例如来自 #bs.block:get_block)保持不变。

贡献者:Aksiome


是否接触电源#

#bs.block:is_touching_power

确定当前位置是否接触已通电的方块或被红石元件通电。

输入:

执行 at <entity>positioned <x> <y> <z>:待检查方块的位置。

输出:

返回:成功或失败。

#bs.block:is_touching_strong_power

确定当前位置是否接触强通电的方块或被红石元件通电。

输入:

执行 at <entity>positioned <x> <y> <z>:待检查方块的位置。

输出:

返回:成功或失败。

#bs.block:is_touching_weak_power

确定当前位置是否接触弱通电的方块。

输入:

执行 at <entity>positioned <x> <y> <z>:待检查方块的位置。

输出:

返回:成功或失败。

示例:检查当前位置是否应激活红石机构:

execute if function #bs.block:is_touching_power run say ACTIVATE

不支持的红石组件

这些函数不支持 trapped_chest 方块。它们依赖方块状态来确定通电情况,而 trapped_chest 方块在打开时不会更新其方块状态。

贡献者:Aksiome


查找方块#

#bs.block:lookup_type {type:<value>}

从给定的类型字符串 ID 获取方块数据。输出等同于 #bs.block:get_type,但包含所有不依赖方块状态的附加属性。

输入:

函数宏

  • 参数

    • type: 方块对应的方块类型的字符串id。

输出:

命令存储 bs:out block

  • [只读] 方块数据

    • group: 在同一个组的方块共享相同的可能的方块状态(比如:所有的楼梯)。

    • block: 方块的完整字符串表示(仅方块类型)。

    • item: 方块对应的物品名字符串,可能不存在。

    • type: 方块id的字符串表示(比如:minecraft:stone)。

    • can_occlude:该方块是否遮挡相邻面。

    • ignited_by_lava:该方块暴露于熔岩时能否着火。

    • blast_resistance:该位置的方块的爆炸抗性。

    • friction:该位置方块的摩擦力。

    • hardness:该位置的方块的硬度。

    • jump_factor:该位置的方块的跳跃系数。

    • speed_factor:该位置的方块的速度系数。

    • instrument:该位置方块的乐器。

    • sounds:方块的声音。

      • break: 玩家破坏方块时的声音。

      • hit: 玩家敲击方块时的声音。

      • fall: 玩家掉在方块上时的声音。

      • place: 玩家放置方块时的声音。

      • step: 玩家在方块上走路时的声音。

示例:获取石头类型的方块数据:

# Get block type data
function #bs.block:lookup_type {type:"minecraft:stone"}

# See the result
data get storage bs:out block.block
#bs.block:lookup_item {item:<value>}

重要

Minecraft在方块和物品之间的映射并不完美。某些物品可能对应多个方块,此函数只会返回其中之一。

从给定的物品字符串 ID 获取方块数据。输出等同于 #bs.block:get_type,但包含所有不依赖方块状态的附加属性。

输入:

函数宏

  • 参数

    • item: 方块对应的物品的字符串id。

输出:

命令存储 bs:out block

  • [只读] 方块数据

    • group: 在同一个组的方块共享相同的可能的方块状态(比如:所有的楼梯)。

    • block: 方块的完整字符串表示(仅方块类型)。

    • item: 方块对应的物品名字符串,可能不存在。

    • type: 方块id的字符串表示(比如:minecraft:stone)。

    • can_occlude:该方块是否遮挡相邻面。

    • ignited_by_lava:该方块暴露于熔岩时能否着火。

    • blast_resistance:该位置的方块的爆炸抗性。

    • friction:该位置方块的摩擦力。

    • hardness:该位置的方块的硬度。

    • jump_factor:该位置的方块的跳跃系数。

    • speed_factor:该位置的方块的速度系数。

    • instrument:该位置方块的乐器。

    • sounds:方块的声音。

      • break: 玩家破坏方块时的声音。

      • hit: 玩家敲击方块时的声音。

      • fall: 玩家掉在方块上时的声音。

      • place: 玩家放置方块时的声音。

      • step: 玩家在方块上走路时的声音。

示例:获取石头物品的方块数据:

# Get block type data
function #bs.block:lookup_item {item:"minecraft:stone"}

# See the result
data get storage bs:out block.block

只读输出

bs:out block 输出是只读的。手动修改部分内容可能导致潜在漏洞。因此,模块提供了许多可以修改输出的函数来保证它的完整性。

贡献者:Aksiome


管理方块状态#

#bs.block:keep_properties {properties:[]}

筛选属性,仅保留需要的属性。此函数作用于存储在方块输出中的虚拟方块格式

输入:

函数宏

  • 参数

    • properties: 要保留的方块状态列表。

      • 方块属性数据

        • name: 方块属性名称(比如:shape)。

存储 bs:out block 无需手动指定,而应使用相关函数,例如get_block

输出:

命令存储 bs:out block blockstateproperties 会在运行后同步更新。

示例:仅保留朝向和形状的方块状态:

# Once (on stairs)
execute positioned ~ ~ ~ run function #bs.block:get_block

# Run the transformation
function #bs.block:keep_properties {properties:[{name:"facing"},{name:"shape"}]}

# See the result
data get storage bs:out block.block
#bs.block:merge_properties {properties:[]}

将当前位置的状态属性合并到输出中。只要语法正确,就会执行合并,而不考虑逻辑一致性(例如,对不同植物使用 ‘age’)。此函数作用于存储在方块输出中的虚拟方块格式

输入:

执行 at <实体>positioned <x> <y> <z>:作为输入的方块位置。

函数宏

  • 参数

    • properties: 要合并的方块状态列表。

      • 方块属性数据

        • name: 方块属性名称(比如:shape)。

存储 bs:out block 无需手动指定,而应使用相关函数,例如get_block

输出:

命令存储 bs:out block blockstateproperties 会在运行后同步更新。

示例:将某个方块的朝向合并更新到楼梯上:

# Once (on stairs)
execute positioned ~ ~ ~ run function #bs.block:get_block

# Run the transformation (on a block with facing)
execute positioned ~ ~ ~ run function #bs.block:merge_properties {properties:[{name:"facing"}]}

# See the result
data get storage bs:out block.block
#bs.block:remove_properties {properties:[]}

移除不需要的属性。此函数作用于存储在方块输出中的虚拟方块格式

输入:

函数宏

  • 参数

    • properties: 要移除的方块状态列表。

      • 方块属性数据

        • name: 方块属性名称(比如:shape)。

存储 bs:out block 无需手动指定,而应使用相关函数,例如get_block

输出:

命令存储 bs:out block blockstateproperties 会在运行后同步更新。

示例:移除朝向和形状属性:

# Once (on stairs)
execute positioned ~ ~ ~ run function #bs.block:get_block

# Run the transformation
function #bs.block:remove_properties {properties:[{name:"facing"},{name:"shape"}]}

# See the result
data get storage bs:out block.block
#bs.block:replace_properties {properties:[]}

替换属性值。无效值不会被替换。此函数作用于存储在方块输出中的虚拟方块格式

输入:

函数宏

  • 参数

    • properties: 要替换的方块状态列表。

      • 方块属性数据

        • name: 方块属性名称(比如:shape)。

        • value: 方块属性值(比如:east)。

存储 bs:out block 无需手动指定,而应使用相关函数,例如get_block

输出:

命令存储 bs:out block blockstateproperties 会在运行后同步更新。

示例:替换朝向方块状态:

# Once (on stairs)
execute positioned ~ ~ ~ run function #bs.block:get_block

# Run the transformation
function #bs.block:replace_properties {properties:[{name:"facing",value:"east"}]}

# See the result
data get storage bs:out block.block
#bs.block:shift_properties {properties:[]}

将属性值按指定步数偏移,并在可用值之间循环。此函数作用于存储在方块输出中的虚拟方块格式

输入:

函数宏

  • 参数

    • properties: 要偏移的方块状态列表。

      • 方块属性数据

        • name: 方块属性名称(比如:shape)。

        • by: 偏移数量(默认为1)。

存储 bs:out block 无需手动指定,而应使用相关函数,例如get_block

输出:

命令存储 bs:out block blockstateproperties 会在运行后同步更新。

示例:将朝向属性值偏移2:

# Once (on stairs)
execute positioned ~ ~ ~ run function #bs.block:get_block

# Run the transformation
function #bs.block:shift_properties {properties:[{name:"facing",by:2}]}

# See the result
data get storage bs:out block.block

贡献者:Aksiome


管理方块类型#

#bs.block:replace_type {type:<value>}

替换方块类型,同时尽量保留状态。仅当输出分组与输入匹配时,状态才会保留。此函数作用于存储在方块输出中的虚拟方块格式

输入:

函数宏

  • 参数

    • type: 方块id的字符串表示(比如:minecraft:stone)。

存储 bs:out block 无需手动指定,而应使用相关函数,例如get_block

输出:

返回值:是否找到了方块类型并进行了替换。

命令存储 bs:out block blockstateproperties 会在运行后同步更新。

示例:将橡木楼梯替换为云杉木楼梯,并保留当前状态:

# Once (on oak_stairs)
execute positioned ~ ~ ~ run function #bs.block:get_block

# Replace type data
function #bs.block:replace_type {type:"minecraft:spruce_stairs"}

# See the result
data get storage bs:out block.block
#bs.block:map_type {type:<value>,mapping_registry:<value>}

根据预定义的映射规则,将方块输出的属性(attr)替换为输入方块的属性(attr),生成新的方块类型。注册表定义如下:

data modify storage bs:const block.mapping_registry.bs.colors set value [ \
  { set: "wool", attrs: ["red"], type: "minecraft:red_wool" }, \
  { set: "wool", attrs: ["green"], type: "minecraft:green_wool" }, \
  { set: "carpet", attrs: ["red"], type: "minecraft:red_carpet" }, \
  { set: "carpet", attrs: ["green"], type: "minecraft:green_carpet" }, \
]

此函数作用于存储在方块输出中的虚拟方块格式。它将输出中的类型替换为属于同一集合且更匹配输入类型属性的类型。

例如,使用上述映射注册表:如果输入是 minecraft:red_wool(attrs:[“red”]),且虚拟方块类型是 minecraft:green_carpet(set:“carpet”),则结果方块将是 minecraft:red_carpet(set:“carpet”,attrs:[“red”])。

Bookshelf 包含两个预定义的映射注册表(bs.shapesbs.colors)。如果这些不够用,你可以创建自己的

输入:

函数宏

  • 参数

    • type: 方块id的字符串表示(比如:minecraft:stone)。

    • mapping_registry: 一个映射表的nbt路径(比如:bs.shapes),用于替换。

存储 bs:out block 无需手动指定,而应使用相关函数,例如get_block

输出:

返回值:是否找到了方块类型并进行了替换。

命令存储 bs:out block blockstateproperties 会在运行后同步更新。

示例:将所有橡木相关方块替换为云杉木(该函数将橡木楼梯方块替换为云杉木楼梯方块):

# Once (on oak_stairs)
execute positioned ~ ~ ~ run function #bs.block:get_block

# Replace type data
function #bs.block:map_type { type: "minecraft:spruce_planks", mapping_registry: "bs.shapes" }

# See the result
data get storage bs:out block.block
#bs.block:mix_type {type:<value>,mapping_registry:<value>}

实验性

由于方块关系定义存在主观性,此函数的运行结果可能不尽人意。同时,其注册表虽涵盖大量常见方块,但基于人工整理收集,无法保证全面性。

根据预定义的映射规则,将方块输出的属性和输入方块的属性混合,生成新的方块类型。注册表定义如下:

data modify storage bs:const block.mapping_registry.bs.shapes set value [ \
  { set: "cube", attrs: ["stone"], type: "minecraft:stone" }, \
  { set: "cube", attrs: ["brick"], type: "minecraft:bricks" }, \
  { set: "cube", attrs: ["stone", "brick"], type: "minecraft:stone_bricks" }, \
  { set: "stairs", attrs: ["stone"], type: "minecraft:stone_stairs" }, \
  { set: "stairs", attrs: ["brick"], type: "minecraft:brick_stairs" }, \
  { set: "stairs", attrs: ["stone","brick"], type: "minecraft:stone_brick_stairs" }, \
]

此函数作用于存储在方块输出中的虚拟方块格式。它将输出中的类型替换为属于同一集合且更匹配输出与输入类型的属性,同时优先考虑输入类型。

例如,使用上述映射注册表:如果输入是 minecraft:bricks(attrs:[“brick”]),且虚拟方块类型是 minecraft:stone_stairs(set:“stairs”,attrs:[“stone”]),则结果方块将是 minecraft:stone_brick_stairs(set:“stairs”,attrs:[“stone”,“brick”])。

Bookshelf 包含两个预定义的映射注册表(bs.shapesbs.colors)。如果这些不够用,你可以创建自己的

输入:

函数宏

  • 参数

    • type: 方块id的字符串表示(比如:minecraft:stone)。

    • mapping_registry: 一个映射表的nbt路径(比如:bs.shapes),用于替换。

存储 bs:out block 无需手动指定,而应使用相关函数,例如get_block

输出:

返回值:是否找到了方块类型并进行了替换。

命令存储 bs:out block blockstateproperties 会在运行后同步更新。

示例:将苔石方块与砖块混合,得到苔石砖:

# Once (on mossy_cobblestone)
execute positioned ~ ~ ~ run function #bs.block:get_block

# Replace type data
function #bs.block:mix_type { type: "minecraft:bricks", mapping_registry: "bs.shapes" }

# See the result
data get storage bs:out block.block

贡献者:Aksiome


匹配#

#bs.block:match

检查当前位置是否和给定方块匹配。

输入:

执行 at <实体>positioned <x> <y> <z>:要检查的方块位置。

命令存储 bs:in block.match.block 要检查的方块的完整字符串表示。

输出:

返回值:检查是否成功或失败(1或0)。

示例:检查0 0 0处的方块是否匹配0 1 0处的方块:

# Get block data at 0 0 0
execute positioned 0 0 0 run function #bs.block:get_block

# Setup the input
data modify storage bs:in block.match.block set from storage bs:out block.block

# Run a command if it's a match
execute positioned 0 1 0 if function #bs.block:match run say It's a match

贡献者:Aksiome、theogiraudet


播放声音#

#bs.block:play_break_sound

播放方块的破坏声音。

输入:

执行 at <entity>positioned <x> <y> <z>:默认 type 的位置,也是 pos 的参考位置。

存储 bs:in block.play_break_sound

  • 方块声音数据

    • type:方块类型(例如 minecraft:stone)。

      如果省略,将使用当前执行位置的方块类型。

    • source: 声音来源:mastermusicrecordweatherblockhostileneutralplayerambientvoice(默认:master)。

    • targets:能够听到声音的实体(默认:@s)。

    • pos:声音位置的 X Y Z 坐标(默认值:~ ~ ~)。

    • pitch:声音的音调(默认值:1.0)。

    • volume:声音的音量(默认值:1.0)。

    • min_volume:声音的最小音量(默认值:0.0)。

输出:

状态:音效被播放。

#bs.block:play_fall_sound

播放方块的落地声音。

输入:

执行 at <entity>positioned <x> <y> <z>:默认 type 的位置,也是 pos 的参考位置。

存储空间 bs:in block.play_fall_sound

  • 方块声音数据

    • type:方块类型(例如 minecraft:stone)。

      如果省略,将使用当前执行位置的方块类型。

    • source: 声音来源:mastermusicrecordweatherblockhostileneutralplayerambientvoice(默认:master)。

    • targets:能够听到声音的实体(默认:@s)。

    • pos:声音位置的 X Y Z 坐标(默认值:~ ~ ~)。

    • pitch:声音的音调(默认值:1.0)。

    • volume:声音的音量(默认值:1.0)。

    • min_volume:声音的最小音量(默认值:0.0)。

输出:

状态:音效被播放。

#bs.block:play_hit_sound

播放方块的击中声音。

输入:

执行 at <entity>positioned <x> <y> <z>:默认 type 的位置,也是 pos 的参考位置。

存储 bs:in block.play_hit_sound

  • 方块声音数据

    • type:方块类型(例如 minecraft:stone)。

      如果省略,将使用当前执行位置的方块类型。

    • source: 声音来源:mastermusicrecordweatherblockhostileneutralplayerambientvoice(默认:master)。

    • targets:能够听到声音的实体(默认:@s)。

    • pos:声音位置的 X Y Z 坐标(默认值:~ ~ ~)。

    • pitch:声音的音调(默认值:1.0)。

    • volume:声音的音量(默认值:1.0)。

    • min_volume:声音的最小音量(默认值:0.0)。

输出:

状态:音效被播放。

#bs.block:play_place_sound

播放方块的放置声音。

输入:

执行 at <entity>positioned <x> <y> <z>:默认 type 的位置,也是 pos 的参考位置。

存储 bs:in block.play_place_sound

  • 方块声音数据

    • type:方块类型(例如 minecraft:stone)。

      如果省略,将使用当前执行位置的方块类型。

    • source: 声音来源:mastermusicrecordweatherblockhostileneutralplayerambientvoice(默认:master)。

    • targets:能够听到声音的实体(默认:@s)。

    • pos:声音位置的 X Y Z 坐标(默认值:~ ~ ~)。

    • pitch:声音的音调(默认值:1.0)。

    • volume:声音的音量(默认值:1.0)。

    • min_volume:声音的最小音量(默认值:0.0)。

输出:

状态:音效被播放。

#bs.block:play_step_sound

播放方块的行走声音。

输入:

执行 at <entity>positioned <x> <y> <z>:默认 type 的位置,也是 pos 的参考位置。

存储 bs:in block.play_step_sound

  • 方块声音数据

    • type:方块类型(例如 minecraft:stone)。

      如果省略,将使用当前执行位置的方块类型。

    • source: 声音来源:mastermusicrecordweatherblockhostileneutralplayerambientvoice(默认:master)。

    • targets:能够听到声音的实体(默认:@s)。

    • pos:声音位置的 X Y Z 坐标(默认值:~ ~ ~)。

    • pitch:声音的音调(默认值:1.0)。

    • volume:声音的音量(默认值:1.0)。

    • min_volume:声音的最小音量(默认值:0.0)。

输出:

状态:音效被播放。

示例:播放脚下方块的脚步声:

# Setup the input
data modify storage bs:in block.play_step_sound set value { source: "block", pos: "~ ~.5 ~" }

# Play the block sound (block below your feet)
execute positioned ~ ~-.5 ~ run function #bs.block:play_step_sound

示例:播放位置 0 0 0 处方块的破坏声:

# Get block data
execute positioned 0 0 0 run function #bs.block:get_type

# Setup the input with the retrieved block data
data modify storage bs:in block.play_break_sound set value { source: "block" }
data modify storage bs:in block.play_break_sound.type set from storage bs:out block.type

# Play the block sound
function #bs.block:play_break_sound

贡献者:Aksiome、theogiraudet


设置方块#

#bs.block:set_block

在当前位置放置方块。

输入:

执行 at <实体>positioned <x> <y> <z>:要放置方块的位置。

命令存储 bs:in block.set_block

  • 放置方块数据

    • block: 要放置的方块的完整字符串表示。

    • mode: 放置方块的模式 [destroy|keep|replace|strict] (默认: replace)。

输出:

状态:方块被放置在世界中。

示例:在0 0 0处放置石头方块并破坏已有方块:

# Setup the input
data modify storage bs:in block.set_block set value {block:"minecraft:stone",mode:"destroy"}

# Run the function
execute positioned 0 0 0 run function #bs.block:set_block
#bs.block:set_type

在尝试保留方块状态和NBT的同时替换当前位置的方块类型。

输入:

执行 at <实体>positioned <x> <y> <z>:要放置方块的位置。

命令存储 bs:in block.set_type

  • 放置方块数据

    • block: 要放置的方块id的字符串表示。

    • mode: 放置方块的模式 [destroy|keep|replace|strict] (默认: replace)。

输出:

状态:方块被放置在世界中。

示例:将所有楼梯替换为橡木楼梯,并保留方块状态:

# Setup the input
data modify storage bs:in block.set_type.type set value "minecraft:oak_stairs"

# Run the function
execute positioned 0 0 0 run function #bs.block:set_type

贡献者:Aksiome、theogiraudet


生成实体#

#bs.block:spawn_block_display

生成给定方块对应的方块展示实体。

输入:

执行 at <实体>positioned <x> <y> <z>:实体生成的位置。

命令存储 bs:in block.spawn_block_display

  • 方块展示实体数据

    • type: 方块类型(和方块输出(bs:out block)类似)。

    • properties: 方块属性(和方块输出(bs:out block)类似)。

    • extra_nbt: 生成实体附加的NBT数据。

输出:

状态:生成的实体。

示例:使用0 0 0处的方块生成方块展示实体:

# Get block data
execute positioned 0 0 0 run function #bs.block:get_block

# Setup the input
data modify storage bs:in block.spawn_block_display set from storage bs:out block

# Summon the block display
function #bs.block:spawn_block_display
#bs.block:spawn_falling_block

生成给定方块对应的下落的方块。

输入:

执行 at <实体>positioned <x> <y> <z>:实体生成的位置。

命令存储 bs:in block.spawn_falling_block

  • 下落的方块数据

    • type: 方块类型(和方块输出(bs:out block)类似)。

    • properties: 方块属性(和方块输出(bs:out block)类似)。

    • extra_nbt: 生成实体附加的NBT数据。

输出:

状态:生成的实体。

示例:使用0 0 0处的方块生成下落的方块:

# Get block data
execute positioned 0 0 0 run function #bs.block:get_block

# Setup the input
data modify storage bs:in block.spawn_falling_block set from storage bs:out block

# Summon the block display
function #bs.block:spawn_falling_block
#bs.block:spawn_solid_block_display

生成给定方块对应的方块展示实体,并且有和方块一样的碰撞逻辑。

输入:

执行 at <实体>positioned <x> <y> <z>:实体生成的位置。

命令存储 bs:in block.spawn_solid_block_display

  • 方块展示实体数据

    • type: 方块类型(和方块输出(bs:out block)类似)。

    • properties: 方块属性(和方块输出(bs:out block)类似)。

    • extra_nbt: 生成实体附加的NBT数据。

输出:

状态:生成的实体。

示例:使用0 0 0处的方块生成带碰撞箱的方块展示实体:

# Get block data
execute positioned 0 0 0 run function #bs.block:get_block

# Setup the input
data modify storage bs:in block.spawn_solid_block_display set from storage bs:out block

# Summon the block display
function #bs.block:spawn_solid_block_display

贡献者:Aksiome、theogiraudet


👁️ 谓词#

以下列出了此模块中所有可用的谓词。


是否导电#

bs.block:is_conductive

检查当前位置的方块是否能传导红石。导电性可能取决于方块属性。例如,台阶方块只有在双层台阶时才能导电。

贡献者:Aksiome


是否通电#

bs.block:is_powered

检查方块是否 conductive 并通电。

贡献者:Aksiome


是否可生成#

bs.block:is_spawnable

检查当前位置的方块是否可以作为有效的生成表面。这不考虑光照级别,可能取决于方块属性。例如,slab 只有在其不是下半砖时才可生成。

贡献者:Aksiome


是否强充能#

bs.block:is_strongly_powered

Check if the block is conductive and strongly powered by redstone.

什么是强充能?

当方块可以给相邻的红石粉(包括其上方和下方的红石粉)充能,并且可以激活相邻的机械组件、给背向方块的 Redstone Repeater 和 Redstone Comparator 充能时,该方块即被强充能。

方块被红石电源元件、已充能的 Redstone Repeater 或已充能的 Redstone Comparator 充能后,即变为强充能状态。

贡献者:Aksiome


是否弱充能#

bs.block:is_weakly_powered

Check if the block is conductive and weakly powered by redstone.

什么是弱充能?

弱充能的方块不能给相邻红石粉充能,但仍能激活相邻红石机械,以及给背向方块的 Redstone Repeater 和 Redstone Comparator 充能。

当方块仅由红石粉充能时,它变为弱充能状态。

贡献者:Aksiome


🏷️ 标签#

You can find below all tags available in this module.


是否可遮挡#

#bs.block:can_occlude

判断方块是否遮挡相邻面(即是否足够实心以隐藏相邻方块的面)。

贡献者:Aksiome


拥有状态#

#bs.hitbox:has_state

判断方块是否可以有状态属性(例如方向、含水状态)。

贡献者:Aksiome


是否可被岩浆点燃#

#bs.hitbox:ignited_by_lava

判断方块是否会因为接触熔岩而着火。

贡献者:Aksiome


🎓 自定义映射注册表#

此模块允许你创建根据特定需求定制的个性化映射注册表。


要创建新的注册表,你需要在 bs:const block.mapping_registry 命令存储中定义一个数组。每个新注册表都应该有命名空间,且每个元素必须包含 setattrstype。以下是定义新映射注册表的方法:

data modify storage bs:const block.mapping_registry.<namespace>.<name> [
  { set: "cube", attrs: ["oak"], type: "minecraft:oak_planks" }, \
  { set: "cube", attrs: ["spruce"], type: "minecraft:spruce_planks" }, \
  \
  { set: "stairs", attrs: ["oak"], type: "minecraft:oak_stairs" }, \
  { set: "stairs", attrs: ["spruce"], type: "minecraft:spruce_stairs" }, \
  \
  { set: "slab", attrs: ["oak"], type: "minecraft:oak_slab" }, \
  { set: "slab", attrs: ["spruce"], type: "minecraft:spruce_slab" }, \
]

💬 这对你有帮助吗?

欢迎在下方留下你的问题和反馈!