槽位类型
ItemMaster 提供 8 种槽位类型,所有槽位都使用函数式语法定义:
type(参数1=值1, 参数2=值2, ...)所有槽位都必须指定 id
id 是脚本中引用槽位的唯一依据。onchange 的键、slot.set("xxx", 装备) 的第一个参数、@xxx 引用里的 xxx,全部都是槽位 ID(不是布局字符,也不是类型名)。
快速总览
| 类型 | 用途 | 核心参数 |
|---|---|---|
| decoration | 纯装饰,不可交互 | material, name, lore |
| input | 接收玩家放入的物品 | match, placeholder, multiple, accept |
| output | 存放脚本生成的结果 | — |
| material | 消耗材料,带数量要求 | match, amount |
| button | 可点击触发脚本 | material, name, execute/action, source |
| preview | 展示"如果执行"的效果 | source, script |
| display | 动态信息展示,支持变量插值 | material, name, lore |
| toggle | 二态开关,常用于锁定属性 | toggleid, on, off |
decoration - 装饰槽位
纯装饰用途,玩家无法交互。
yaml
slots:
X: decoration(id=边框, material=BLACK_STAINED_GLASS_PANE, name=" ")
D: decoration(id=说明, material=PAPER, name="&e说明", lore="&7第一行|&7第二行")
C: decoration(id=图标, material=PAPER, name="&b图标", model=1001)| 参数 | 类型 | 说明 |
|---|---|---|
material | String | 物品材质 |
name | String | 显示名称(支持颜色码) |
lore | String | 描述文本,多行用 | 分隔 |
model / custommodeldata | Integer | 自定义模型数据 |
input - 输入槽位
接收玩家放入的物品,支持静态匹配和动态接受条件。
yaml
slots:
# 基本
I: input(id=input, match="lore.contains('可强化')")
# 占位物品(玩家未放入时显示)
I: input(id=input, match="type.isWeapon()", placeholder=GRAY_STAINED_GLASS_PANE:"&7请放入武器")
# 完整占位配置
I: input(id=input, placeholder_material=BARRIER, placeholder_name="&7请放入装备", placeholder_lore="&7需要可强化标签")
# 槽位组
F: input(id=food, multiple=true, match="lore.contains('可被吞噬')")
# 动态接受条件(运行时计算)
I: input(id=input, accept="等级 >= 5")| 参数 | 类型 | 说明 |
|---|---|---|
id | String | 槽位 ID(必须) |
match | String | 物品匹配表达式(静态,初始化时解析) |
placeholder | String | 占位物品(MATERIAL 或 MATERIAL:名称) |
placeholder_material / placeholder_name / placeholder_lore | String | 完整占位配置 |
multiple | Boolean | 槽位组模式(默认 false) |
accept | String | 动态接受条件(可用 @cursor 引用待放入的物品) |
match vs accept
| 特性 | match | accept |
|---|---|---|
| 执行时机 | GUI 初始化时解析 | 玩家放入时计算 |
| 可用变量 | 无(静态匹配) | variables 中的变量 + 内置变量 + @cursor |
| 性能 | 预编译,更快 | 每次放入都计算 |
| 适合场景 | 固定类型 / Lore 过滤 | 等级限制、库存检查等动态条件 |
yaml
# 组合使用
I: input(id=input, match="type.isSword()", accept="@cursor.durability > 50")accept 可用的变量:@cursor(或 @放入物品)、variables 中的所有变量、player.level 等内置变量。
槽位组操作
当 multiple=true 时,@id 变成 List<ItemStack>,空位表示为 null:
yaml
execute: |
饲料数量 = count_filled(@food)
总攻击力 = sum_attr(@food, "攻击力")
slot.clear("food") # 清空整组
# 遍历:for 只支持数值范围
槽位数 = list_size(@food)
for i in 0..槽位数-1 {
物品 = list_get(@food, i)
if 物品 != null {
log("物品:", 物品)
}
}WARNING
list_get(@food, i) 返回的是深拷贝,修改后不会影响原列表。要持久化修改,需要 list_set 写回,或直接用副本 slot.set 回去。
output - 输出槽位
用于放置脚本生成的结果。
yaml
slots:
O: output(id=output)| 参数 | 类型 | 说明 |
|---|---|---|
id | String | 槽位 ID(必须) |
output 经常配合 slot.set("output", 成品) 写入、item.give(@output) 派发。
material - 材料槽位
消耗材料用的槽位,支持数量要求(可写成表达式)。
yaml
slots:
# 固定数量
M: material(id=material, match="type.is(DIAMOND)", amount=5)
# 动态数量(表达式)
M: material(id=material, match="type.is(IRON_INGOT)", amount="等级 * 2")
# 带占位提示
M: material(id=stone, match="type.is(DIAMOND)", amount=3, placeholder=DIAMOND:"&b需要钻石x3")| 参数 | 类型 | 说明 |
|---|---|---|
id | String | 槽位 ID(必须) |
match | String | 物品匹配表达式 |
amount | String / Number | 需要数量(支持表达式) |
placeholder | String | 占位物品 |
button - 按钮槽位
可点击的按钮,触发指定脚本。
yaml
slots:
# 默认按钮(点击执行 execute 块)
B: button(id=confirm, material=LIME_WOOL, name="&a确认")
# 指定命名脚本
B: button(id=confirm, material=LIME_WOOL, name="&a确认强化", execute=confirm_script)
# 内联脚本(一行 action)
B: button(id=start, material=EMERALD, name="&a开始", action="effect.message('开始执行')")
# 动态物品(源于表达式)
B: button(id=gem1, source="vault.get('gem1')")| 参数 | 类型 | 说明 |
|---|---|---|
id | String | 槽位 ID |
material | String | 按钮材质 |
name | String | 名称(支持变量插值) |
lore | String | 描述(支持变量插值,多行用 | 分隔) |
execute / action | String | 点击执行的脚本或脚本引用 |
source | String | 动态物品来源表达式 |
命名脚本
把多个按钮做成不同行为,最好在顶级 scripts 块里定义命名脚本,按钮上用 execute=脚本名 引用。不要给 execute 加 @scripts. 前缀。
preview - 预览槽位
把源物品复制一份,在沙箱中跑预览脚本,再显示"如果执行后"的结果。不可交互。
yaml
slots:
# 仅复制显示(无修改)
P: preview(id=preview, source="@input")
# 带预览脚本
P: preview(id=preview, source="@input", script=preview_script)
# 带占位物品
P: preview(id=预览, source="@主装备", script=preview_script,
placeholder=BARRIER:"&c强化预览",
placeholder_lore="&8放入装备后|&8显示强化后效果")| 参数 | 类型 | 说明 |
|---|---|---|
id | String | 槽位 ID |
source | String | 物品来源(如 @input、@主装备) |
script | String | 预览时执行的脚本名(引用 scripts 块) |
placeholder | String | 源槽位为空时显示的占位物品 |
placeholder_lore | String | 占位物品的 Lore |
预览脚本的变量作用域
预览脚本只能访问 variables: 中定义的变量,无法访问 execute: 中的变量。所有 execute 中才有的计算都需要在预览脚本内重新算一遍。详见 预览模式。
预览脚本内可以直接写 lore.xxx(...)、name.xxx(...),不需要 装备. 前缀,系统会把操作直接应用到预览副本。
display - 显示槽位
动态展示信息,名称和 Lore 支持变量插值({变量})。
yaml
slots:
D: display(id=信息, material=PAPER, name="&e强化信息",
lore="&7当前等级: {当前等级}|&7成功率: {成功率}%")| 参数 | 类型 | 说明 |
|---|---|---|
id | String | 槽位 ID |
material | String | 物品材质 |
name | String | 名称(支持变量插值) |
lore | String | 描述(支持变量插值,多行用 | 分隔) |
display 的内容在每次 variables 执行后都会重新渲染。
toggle - 开关槽位
二态开关,常用于洗练系统里锁定属性。
yaml
slots:
# 基本
T: toggle(id=锁定1, toggleid=lock1, on=LIME_DYE, off=GRAY_DYE)
# 和某个物品变化联动重置
T: toggle(id=锁定1, toggle=lock1, on=LIME_DYE, off=GRAY_DYE, bind="@input")| 参数 | 类型 | 说明 |
|---|---|---|
id | String | 槽位 ID |
toggleid / toggle | String | 开关 ID(必须) |
on | String | 开启状态材质 |
off | String | 关闭状态材质 |
bind | String | 绑定物品来源(变化时重置开关) |
脚本中通过 @toggleid.on 或 @toggleid.state 读状态:
yaml
if @lock1.on {
// 已锁定
}
if !@lock1.state {
// 未锁定
}
# 统计开启的开关
开启数量 = count_on(@lock1, @lock2, @lock3)槽位引用语法
定义好的槽位在脚本里用 @槽位ID 引用:
yaml
@input # ItemStack(或 List<ItemStack> 槽位组)
@input.filled # Boolean: 是否有物品
@input.amount # Number: 数量
@input.type # String: 材质名
@input.name # String: 显示名
@input.durability # Number: 当前耐久
@input.maxDurability # Number: 最大耐久
# 简化方法
@input.attr("攻击力")
@input.counter("次数")
@input.counterMax("次数")
@input.text("品质")
# 模板提取(最灵活)
@input.t("强化等级: {#level}/{#max}", "level")更多引用语法见 引用与插值。
下一步阅读:YAML 注意事项。