跳到主要内容

🪇 事件

简介

events 部分决定了哪些物品/家具/方块将在特定事件中执行预定义行为。在 events 部分下,您需要指定一个事件触发器,例如 "right_click" 表示右键点击动作。在事件触发器下方,您必须传递一个动作列表及其对应的类型。例如,command 用于执行特定命令。

# 格式1
events:
right_click:
- type: command
command: say 1
conditions:
- type: permission
permission: "craftengine.admin"
- type: command
command: say 2
conditions: []
# 格式2
events:
- on: right_click
functions:
- type: command
command: say 1
conditions:
- type: permission
permission: "craftengine.admin"
- type: command
command: say 2
conditions: []

🧨 事件触发器

物品

  • break
  • right_click
  • left_click
  • consume
  • pick_up

方块

  • break
  • place
  • right_click
  • left_click
  • step

家具

  • break
  • place
  • right_click
警告

请注意:事件需配置在正确的区域。例如若需实现家具交互时执行指令,应将 events 置于 furniture 部分而非物品部分下。

items:
default:bench:
events: # ❌️
right_click:
- type: command
behavior:
type: furniture_item
furniture:
events: # ✅️
right_click:
- type: command

🔧 函数

取消事件

取消原始事件。

type: cancel_event

运行

按顺序运行一系列函数。这对于共享相同条件的函数非常有用。

type: run
delay: 0 # 可选; 数字; 默认值: 0
functions: # 必填; 映射列表
- type: command
- type: message

命令

以玩家、控制台或事件的形式运行命令。

type: command
command: "say 你好 <arg:player.name>" # 必填; 字符串列表/字符串
target: "self" # 可选; 枚举[all, self]/玩家选择器; 默认值: self

# 以玩家身份执行这个指令
as-player: false # 可选; 布尔; 默认值: false
# 以op身份执行这个指令,风险自担
as-op: false # 可选; 布尔; 默认值: false
# 有些自定义指令插件基于事件驱动,使用此选项可能可以兼容
as-event: false # 可选; 布尔; 默认值: false

消息

发送消息或系统动作栏消息

type: message
message: "你好 <papi:player_name>" # 必填; 字符串列表/字符串
target: "self" # 可选; 枚举[all, self]/玩家选择器
overlay: false # 可选; 默认值: false; false = 聊天框 / true = 动作栏

动作栏消息

发送一条动作栏消息

type: actionbar
actionbar: "这是一个动作栏消息" # 必填; 字符串
target: "self" # 可选; 枚举[all, self]/玩家选择器; 默认值: self

屏幕标题消息

发送一条屏幕标题消息

type: title
title: "<red>标题</red>" # 必填; 字符串
subtitle: "<Yellow>副标题</yellow>" # 必填; 字符串
fade-in: 20 # 可选; 数字; 默认值: 10
stay: 10 # 可选; 数字; 默认值: 20
fade-out: 10 # 可选; 数字; 默认值: 5

打开窗口

打开一个图形用户界面窗口

type: open_window #
gui-type: anvil # 必填; 枚举[anvil, enchantment, grindstone, loom, smithing, crafting, cartography];
title: "超级铁砧" # 可选; 字符串
target: "self" # 可选; 枚举[all, self]/玩家选择器; [默认值: self]

破坏方块

破坏一个方块

type: break_block
x: <arg:position.x> # 可选; 数字; 默认值: <arg:position.x>
y: <arg:position.y> # 可选; 数字; 默认值: <arg:position.y>
z: <arg:position.z> # 可选; 数字; 默认值: <arg:position.z>

放置方块

放置一个方块

type: place_block
block-state: "default:chinese_lantern" # 必填; 字符串
x: <arg:block.block_x> # 可选; 数字; 默认值: <arg:position.x>
y: <arg:block.block_y> # 可选; 数字; 默认值: <arg:position.y>
z: <arg:block.block_z> # 可选; 数字; 默认值: <arg:position.z>

更新方块属性

更新某个方块的方块属性

type: update_block_property
properties: # 必填; 键值对
axis: x
age: 7
x: <arg:block.block_x> # 可选; 数字; 默认值: <arg:position.x>
y: <arg:block.block_y> # 可选; 数字; 默认值: <arg:position.y>
z: <arg:block.block_z> # 可选; 数字; 默认值: <arg:position.z>

转换方块

将当前方块转换为另一个方块并保留全部的属性

type: transform_block
block: default:palm_log # 必填;新方块
properties: # 可选; 键值对
property_a: b
x: <arg:block.block_x> # 可选; 数字; 默认值: <arg:position.x>
y: <arg:block.block_y> # 可选; 数字; 默认值: <arg:position.y>
z: <arg:block.block_z> # 可选; 数字; 默认值: <arg:position.z>

掉落战利品

根据给定的战利品表掉落物品

type: drop_loot
x: <arg:block.block_x> + 0.5 # 可选; 数字; 默认值: <arg:position.x>
y: <arg:block.block_y> + 0.5 # 可选; 数字; 默认值: <arg:position.y>
z: <arg:block.block_z> + 0.5 # 可选; 数字; 默认值: <arg:position.z>
loot:
pools: ...

更新交互游戏刻

更新最后一次交互结束时的游戏刻

type: update_interaction_tick

设置物品数量

设置此事件中当前物品的数量

type: set_count
add: true # 默认值: false
count: -1 # 必填; 数字
target: "self" # 可选; 枚举[all, self]/玩家选择器

设置饥饿值

设置玩家的饥饿值(0~20)

type: set_food
add: true # 可选; 枚举; 默认值: false
food: 4 # 必填; 数字
target: "self" # 可选; 枚举[all, self]/玩家选择器

设置饱和度

设置玩家的饱和度(0~10)

type: set_saturation
add: true
saturation: 2.5
target: "self" # 可选; 枚举[all,self]/玩家选择器

挥手

挥动此事件中涉及的手,或配置中指定的手

type: swing_hand
hand: main_hand # 可选; 枚举[main_hand, off_hand]; 不填会从上下文获取需要挥动的手

粒子效果

生成一个粒子效果

type: particle
particle: minecraft:end_rod # 必填; 字符串
x: "<arg:position.x>" # 可选; 数字; 默认值: <arg:position.x>
y: "<arg:position.y>" # 可选; 数字; 默认值: <arg:position.y>
z: "<arg:position.z>" # 可选; 数字; 默认值: <arg:position.z>
count: 5 # 可选; 数字; 默认值: 1
offset-x: 0.3 # 可选; 数字; 默认值: 0
offset-y: 0.3 # 可选; 数字; 默认值: 0
offset-z: 0.3 # 可选; 数字; 默认值: 0
speed: 0 # 可选; 数字; 默认值: 0

# 以下参数仅在粒子为特定类型时才有效。

# 带物品粒子选项的粒子类型:item
item: default:chinese_lantern

# 带方块粒子选项的粒子类型:block、block_marker、falling_dust、dust_pillar 和 block_crumble
block-state: default:plam_log[axis=y]

# 带幽匿块充能粒子选项的粒子类型:sculk_charge
charge: 1.5

# 带尖啸粒子选项的粒子类型:shriek
shriek: 1

# 带粉末粒子选项的粒子类型:dust
color: 255,255,255
scale: 1.0

# 带粉末颜色过渡选项的粒子类型:dust_color_transition
from: 255,255,255
to: 0,0,0
scale: 4.0

# 带振动粒子选项的粒子类型:vibration
target-x: 0
target-y: 1
target-z: 0
arrival-time: 10

# 带目标颜色粒子选项的粒子类型:trail
target-x: 0
target-y: 1
target-z: 0
duration: 10

状态效果

添加一个状态效果

type: potion_effect
potion-effect: minecraft:blindness # 必填; 字符串
duration: 20 # 可选; 数字; 默认值: 20
amplifier: 0 # 可选; 数字; 默认值: 0
ambient: false # 可选; 布尔; 是否来自信标
particles: true # 可选; 布尔

移除状态效果

移除一个状态效果

type: remove_potion_effect
potion-effect: minecraft:blindness # 如果 'all' 为 true 则为可选; 布尔
all: false # 可选; 布尔; 默认值: false

等级经验

添加技能/职业经验

type: leveler_exp
plugin: AuraSkills # 可选; 字符串
leveler: fishing # 可选; 字符串; 职业/技能 ID
count: 10 # 可选; 数字

设置冷却时间

为玩家设置冷却时间

type: set_cooldown
time: 1m30s
id: my_cooldown_id # 可选; 字符串
add: false # 可选; 布尔; 默认值: false (是否累加冷却时间)

移除冷却时间

为玩家移除冷却时间

type: remove_cooldown
id: my_cooldown_id # 如果 'all' 为 true 则为可选; 字符串
all: false # 可选; 布尔; 默认值: false

播放声音

播放一个声音

type: play_sound
sound: minecraft:xxxx.xxx
x: <arg:position.x> # 如果使用了 'target' 参数则为可选; 数字
y: <arg:position.y> # 如果使用了 'target' 参数则为可选; 数字
z: <arg:position.z> # 如果使用了 'target' 参数则为可选; 数字
target: "self" # 可选; 枚举[all, self]/玩家选择器
pitch: 1 # 可选; 数字; 默认值: 1
volume: 1 # 可选; 数字; 默认值: 1
source: master # 可选; 枚举[music, master, record, weather, block, hostile, neutral, player, ambient, voice, ui]; 默认值: master

MythicMobs 技能

释放 MythicMobs 技能

type: mythic_mobs_skill
skill: skill_id # 必填; 字符串
power: 1.0 # 可选; 数字; 默认值: 1.0

生成家具

生成一个家具

type: spawn_furniture
furniture-id: "default:bench" # 可选; 字符串
x: <arg:position.x> # 可选; 数字; 默认值: <arg:position.x>
y: <arg:position.y> # 可选; 数字; 默认值: <arg:position.y>
z: <arg:position.z> # 可选; 数字; 默认值: <arg:position.z>
pitch: <arg:position.pitch> # 可选; 数字; 默认值: <arg:position.pitch>
yaw: <arg:position.yaw> # 可选; 数字; 默认值: <arg:position.yaw>
anchor-type: ground # 可选; 枚举[ground,ceiling,wall]
play-sound: true # 可选; 布尔; 默认值: true

移除家具

移除一个家具

type: remove_furniture
drop-loot: true # 可选; 布尔; 默认值: true
play-sound: true # 可选; 布尔; 默认值: true

替换家具

替换一个家具

type: replace_furniture
furniture-id: "default:bench"
x: <arg:furniture.x> # 可选; 数字; 默认值: <arg:furniture.x>
y: <arg:furniture.y> # 可选; 数字; 默认值: <arg:furniture.y>
z: <arg:furniture.z> # 可选; 数字; 默认值: <arg:furniture.z>
pitch: <arg:furniture.pitch> # 可选; 数字; 默认值: <arg:furniture.pitch>
yaw: <arg:furniture.yaw> # 可选; 数字; 默认值: <arg:furniture.yaw>
anchor-type: ground # 可选; 枚举[ground,ceiling,wall]
drop-loot: true # 默认值: true
play-sound: true # 默认值: true

传送

传送至指定地点

type: teleport
x: <arg:position.x> # 必填; 数字
y: 100 # 必填; 数字
z: <arg:position.z> + 5 # 必填; 数字
pitch: <arg:player.pitch> # 可选; 默认值: 0
yaw: <arg:player.yaw> # 可选; 默认值: 0
world: world # 可选; 字符串;

弹窗

发送一个弹窗

type: toast
toast: 这是一个弹窗 # 必填; 字符串
advancement-type: goal # 可选; 枚举[goal,task,challenge]; 默认值: goal
icon: minecraft:stone # 必填; 字符串

伤害

伤害一个玩家

type: damage
target: self # 可选; 枚举[all, self]/玩家选择器; 默认值: self
amount: 1.0 # 可选; 数字; 默认值: 1.0
damage-type: generic # 可选; 字符串; 默认值: generic

设置变量

设置一个变量

type: set_variable
name: my_variable # 必填; 字符串
number: 1.0 # 可选; 数字
as-int: false # 可选; 布尔; 默认值: false
text: "你好" # 可选; 字符串

村民交易

打开一个自定义村民交易界面

type: merchant_trade
title: "自定义奸商"
offers:
- cost-1:
item: iron_pickaxe
# 可选的检查收购物品的额外信息,默认为空
components: # 当物品与指定的物品堆叠组件限制相同时检查才能成功
minecraft:enchantments: # 检查指定的物品堆叠组件
minecraft:unbreaking: 1
# 可选的第二个收购物品,默认为空
cost-2:
item: cobblestone
# 收购物品的基础数量,默认为 1
count: 8
result:
item: default:topaz
count: 4
# 添加更多的交易选项
- cost-1: stone
result: default:topaz
# 生物从此交易选项中能获得的经验值,默认为 1
experience: 3

移除实体

从当前上下文中移除实体

type: remove_entity

条件判断

运行首个满足指定条件的函数。 译者注:只要满足了某个条件,执行完该条件内的函数,就会结束条件判断函数的运行,即使后面有可以满足的条件,也不会执行该条件内的函数。

type: if_else
rules:
- conditions:
- type: permission
permission: group.admin
functions:
- type: command
command: say 管理员你好
- conditions:
- type: permission
permission: group.vip
functions:
- type: command
command: say VIP你好
- functions:
- type: command
command: say 玩家你好

条件匹配

根据源数值进行匹配,并执行首个匹配案例对应的函数。其功能类似于编程语言中的 switch-case 语句

type: when
source: <papi:player_world>
cases:
- when: "world"
functions:
- type: message
message: "您位于主世界。"
- when:
- "world_nether"
- "world_the_end"
functions:
- type: message
message: "您正处于危险维度!"
# 可选配置
fallback:
- type: message
message: "您处于未知世界中。"

消耗物品耐久度

消耗当前上下文中玩家手持的物品耐久度

type: damage_item
amount: 1 # 可选; 数字; 默认值: 1
信息

更多函数即将到来...