Skip to content

物品 / 经济 / 附魔 / 耐久动作

物品操作

item.give

给予玩家背包物品。

yaml
item.give(@output)                      # 给予输出槽物品
item.give(item("mm:Reward"), 1)         # 给予 MM 物品 x1
item.give(item.create("DIAMOND"), 5)    # 给 5 个钻石

item.take

扣除槽位物品数量。

yaml
item.take(@material, 1)                 # 扣除 1 个
item.take(@input, @input.amount)        # 扣除全部

item.clear

清空槽位物品(单槽位或槽位组)。

yaml
item.clear(@input)
item.clear(@food)                       # 槽位组会全部清空

item.setType

修改物品材质。

yaml
装备.item.setType("DIAMOND_SWORD")

amount.set

设置物品堆叠数量(会被限制在 0–64)。

yaml
装备.amount.set(32)
@input.amount.set(64)

# 配合变量
新数量 = @input.amount + 10
装备.amount.set(新数量)

# 配合列表
items = @food
item = list_get(items, 0)           # 副本
item.amount.set(32)
items = list_set(items, 0, item)    # 写回

# 支持表达式
装备.amount.set(min(@input.amount * 2, 64))

附魔动作

enchant.add

yaml
装备.enchant.add("SHARPNESS", 5)
装备.enchant.add("UNBREAKING", 3, true)   # 第 3 参数 unsafe=true 允许超上限

enchant.remove

yaml
装备.enchant.remove("SHARPNESS")
装备.enchant.remove("ALL")                # 移除所有附魔

读取附魔见 引用与插值 - 附魔(支持中英文名)。

耐久动作

durability.set

设置剩余耐久(不是损伤值)。

yaml
装备.durability.set(100)
装备.durability.set(@input.maxDurability)    # 满耐久

durability.repair

修复耐久。不传参数时完全修复。

yaml
装备.durability.repair(50)        # 修复 50 点
装备.durability.repair()          # 完全修复
装备.durability.repair(100)

经济动作

金币(需 Vault)

动作说明
money.take(数量)扣除金币
money.give(数量)给予金币
yaml
money.take(1000)
money.take(消耗金币)
money.give(500)
money.give(奖励金币)

点券(需 PlayerPoints)

动作说明
points.take(数量)扣除点券
points.give(数量)给予点券
yaml
points.take(100)
points.give(50)

其他货币

  • LyShop 货币:用函数 lshop_take(货币, 数量) / lshop_give
  • CraftX 永久/临时变量:用 cx_take / cx_add 等。
  • 仓库物品:用 wh_give / wh_take

详见 集成函数

典型组合

消耗金币 + 扣除材料 + 给予成品

yaml
execute: |
  require @material.filled : "&c缺少材料"
  require money >= 消耗金币 : "&c金币不足"

  money.take(消耗金币)
  item.take(@material, 1)
  item.give(item("mm:成品"), 1)
  effect.message("&a制作完成")

强化 + 附魔 + 耐久修复

yaml
execute: |
  with @input {
    装备.lore.attr("攻击力", "+10")
    装备.enchant.add("SHARPNESS", 5)
    装备.durability.repair()
  }

失败时扣数量 / 销毁

yaml
execute: |
  chance 成功率 {
    装备.lore.attr("攻击力", "+10")
  } fail {
    if rand(100) < 30 {
      item.clear(@input)      # 30% 概率销毁
      effect.message("&4装备损坏!")
    } else {
      effect.message("&c强化失败")
    }
  }

TQ Minecraft Server Plugin Docs