Skip to content

方块置换 permutations

本页面镜像自
BedrockWiki

根据原始项目协议授权。本文经过AI翻译处理,如有内容遗漏,可以提交PR进行补充。

格式要求 & 最低引擎版本 1.20.30

在学习方块变换前,您应当已熟练掌握方块状态知识。

使用方块状态时,请确保资源包清单中的min_engine_version1.20.20或更高版本。

方块permutations数组提供了一种基于当前置换(状态值集合)条件性应用组件(包括事件触发器和标签)的方式。

permutations数组中的组件可以覆盖方块的基类组件以及其他组件列表中的组件。置换数组中最后出现的条目具有最高优先级。

可旋转方块方块置换 的一种常用用法。

定义置换

permutations数组是minecraft:block的直接子项,由包含组件的对象组成。当条件判断为真值(非false或0)时,相关组件将被应用。

置换条件必须遵守其 限制条件

自实验性玩法Holiday Creator Features发布,支持格式版本1.19.70及更高。

json
{
  "format_version": "1.20.30",
  "minecraft:block": {
    "description": {
      "identifier": "wiki:custom_block",
      "states": {
        "wiki:integer_state_example": [2, 4, 6, 8],
        "wiki:boolean_state_example": [false, true],
        "wiki:string_state_example": ["red", "green", "blue"]
      }
    },
    "components": {},
    "permutations": [
      {
        "condition": "q.block_state('wiki:integer_state_example') == 2",
        "components": {
          "minecraft:friction": 0.1
        }
      },
      {
        "condition": "q.block_state('wiki:boolean_state_example')",
        "components": {
          "minecraft:friction": 0.8 // 覆盖之前的置换
        }
      },
      {
        "condition": "q.block_state('wiki:string_state_example') == 'red' && !q.block_state('wiki:boolean_state_example')",
        "components": {
          "minecraft:geometry": "geometry.pig"
        }
      }
    ]
  }
}

置换条件限制

当条件评估为真值(非false或0)时,关联的组件列表将被应用。

置换条件需以Molang表达式字符串形式编写,并具有严格限制:

  • 条件判断完全基于方块的置换状态,因此只能使用q.block_state查询函数
  • 这意味着条件判断不会产生副作用
    • 禁止使用以下数学函数:math.die_rollmath.die_roll_integermath.randommath.random_integer
    • 不可进行变量赋值操作

(注:保留英文术语如Component、Entity、Block等,根据中文技术文档惯例处理专有名词)