Skip to content

事件触发器

触发器让节点或图鉴条目在玩家达成某个玩法条件时自动完成,不需要命令或 API 授予。是否启用由 config.yml > advancement.triggers_enabled 控制,见配置详解

两处使用同一套事件与条件语法,但落点不同:

位置写法命中效果
advancements/*.yml 节点triggers.entries完成原版 Advancement 节点,并执行 actions.complete
codex/*.yml 条目unlock.triggers把分类条目变为已解锁,不自动激活也不自动领取

节点与页面字段见成就页定义,分类条目字段见配置详解分类条目 GUI

triggers.entries

原版节点的触发器写在节点下:

yaml
triggers:
  entries:
    - event: "craft_item"
      condition:
        type: "all_of"
        entries:
          - '%result_type% == "CRAFTING_TABLE"'

字段:

字段类型说明
eventstring触发器类型。会按 CoreLib 规范 ID 归一化。
conditionCoreLib condition group可选。省略时只要事件发生就授予。

同一节点可配置多个 trigger,满足任意一个即尝试授予节点。

unlock.triggers

分类条目的触发器写在条目的 unlock 下,eventcondition 语法与上面完全一致:

yaml
entries:
  master_miner:
    unlock:
      triggers:
        - event: "block_break"
          condition:
            type: "all_of"
            entries:
              - '%block_type% == "DIAMOND_ORE"'
      advancements:
        - "emakicodex:example/first_step"

unlock.triggersunlock.advancements 是并列通路,任一命中即解锁该条目。命中只改变解锁态:属性奖励要玩家在 GUI 左键激活,一次性奖励要右键领取。

可用触发器

完整共享事件 ID 说明见 CoreLib 的 共享玩法事件 ID。本页只列出 EmakiCodex 两类触发器常用变量。

event场景条件变量
entity_kill击杀普通实体%entity_type%
mythic_mob_kill击杀 MythicMobs 生物%mythic_id%%mythic_level%
block_break破坏方块%block_type%
crop_harvest破坏成熟作物%block_type%
craft_item合成物品%result_type%%result_amount%
furnace_extract从熔炉取出产物%result_type%%result_amount%
player_fish钓鱼事件%fish_state%
brew_complete酿造完成%potion_type%
entity_tame驯服生物%entity_type%

所有触发器都会额外提供:

变量说明
%player%玩家名。
%world%玩家所在世界名。

触发条件会先替换上述事件变量,再在安装 PlaceholderAPI 时继续解析剩余 PAPI 占位符。

条件组示例

击杀末影龙或凋灵:

yaml
triggers:
  entries:
    - event: "entity_kill"
      condition:
        type: "any_of"
        entries:
          - '%entity_type% == "ENDER_DRAGON"'
          - '%entity_type% == "WITHER"'

合成至少 16 个目标物品:

yaml
triggers:
  entries:
    - event: "craft_item"
      condition:
        type: "all_of"
        entries:
          - '%result_type% == "DIAMOND_BLOCK"'
          - '%result_amount% >= 16'

击杀指定 MythicMobs:

yaml
triggers:
  entries:
    - event: "mythic_mob_kill"
      condition:
        type: "all_of"
        entries:
          - '%mythic_id% == "ancient_guardian"'
          - '%mythic_level% >= 10'

上述示例写在原版节点的 triggers.entries 下;用于分类条目时,把同样的列表放到条目的 unlock.triggers 下即可。

相关页面