Skip to content

动态修改配方 ​

当前 API Minecraft 1.21.1 / MBD2 21.1.1

使用 onBeforeRecipeModify 为一个机器定义替换选中的运行时配方。这是实现升级系统在运行时更改时长、并行数或内容的支持方式。

js
MBDMachineEvents.onBeforeRecipeModify('example:crusher', event => {
  const mbd = event.event
  const upgrades = mbd.machine.getTraitByName('upgrades')
  if (upgrades === null) return

  const count = upgrades.storage.getStackInSlot(0).count
  const builder = mbd.recipe.toBuilder()
  builder.duration(Math.max(20, Math.ceil(mbd.recipe.duration * (1 - count * 0.01))))
  mbd.setRecipe(builder.buildMBDRecipe())
})

使用此钩子时,请在编辑器中启用机器的配方修改行为。始终构建新配方;不要修改缓存的共享配方。

Released under the MIT License.