参考手册Inventory

背包与装备

背包工具赋予 AI 管理物品的能力:丢弃、存储、取出和装备。这些工具是 AI 与 Minecraft 物品系统交互的基础。

工具列表

工具功能参数返回值
drop_item丢弃物品item_name(可选), count(可选), target_entity(可选)丢弃结果
take_from_container从容器取出物品x, y, z, item_name(可选), count(可选)取物结果
put_to_container向容器放入物品x, y, z, item_name(可选), count(可选)放物结果
equip_item装备或卸下物品item_name, slot(可选), action(可选)装备结果

工具详解

drop_item — 丢弃物品

从背包中丢弃指定物品,可指定数量或丢弃给目标实体。

{
  "tool": "drop_item",
  "params": { "item_name": "dirt", "count": 5 }
}

丢弃给其他玩家或实体:

{
  "tool": "drop_item",
  "params": { "item_name": "diamond", "count": 1, "target_entity": "玩家UUID" }
}

take_from_container — 从容器取物

从箱子、熔炉、漏斗等容器中取出物品。

{
  "tool": "take_from_container",
  "params": { "x": 50, "y": 63, "z": -100, "item_name": "stone", "count": 32 }
}

不指定 item_name 时取走容器中的全部物品:

{
  "tool": "take_from_container",
  "params": { "x": 50, "y": 63, "z": -100 }
}

put_to_container — 向容器放物

将背包中的物品放入容器中存储。

{
  "tool": "put_to_container",
  "params": { "x": 50, "y": 63, "z": -100, "item_name": "cobblestone", "count": 64 }
}

equip_item — 装备物品

将物品装备到指定槽位,支持主手、副手、头盔、胸甲、护腿、靴子。

{
  "tool": "equip_item",
  "params": { "item_name": "diamond_sword", "slot": "hand", "action": "equip" }
}

卸下装备:

{
  "tool": "equip_item",
  "params": { "item_name": "diamond_sword", "slot": "hand", "action": "unequip" }
}

可用的装备槽位:hand(主手)、offhand(副手)、head(头盔)、chest(胸甲)、legs(护腿)、feet(靴子)

典型场景

整理物品到箱子:

1. mine_block(x, y, z) → 挖掘到石头
2. 背包已满 → put_to_container(x, y, z, "cobblestone", 64)
   → 将圆石存入容器
3. 继续挖掘...

更换装备准备战斗:

1. equip_item("diamond_helmet", "head", "equip") → 戴钻石头盔
2. equip_item("diamond_chestplate", "chest", "equip") → 穿钻石胸甲
3. equip_item("diamond_sword", "hand", "equip") → 拿钻石剑
4. 准备就绪 → 进入战斗

错误处理

场景错误码说明
背包中无该物品DROP_FAILED / EQUIP_FAILED要操作物品不存在
背包已满INVENTORY_FULL无法接收更多物品
容器无物TAKE_FAILED容器为空或物品不存在
容器已满PUT_FAILED容器空间不足