/item
来源:Commands/item;原文修订 ID:3780270。
本命令仅适用于 Java 版;权限等级为 2。基岩版对应命令见 /replaceitem。原文提示:Java 26.3 的 slot_source 错误相关结果尚待更新。
操作或复制方块(箱子、熔炉等)或实体(玩家、生物等)物品栏中的物品。
语法
item modify (block <pos>|entity <targets>) <slot> <modifier>:用指定物品修饰器修改指定槽位中的物品。item replace (block <pos>|entity <targets>) <slot> with <item> [<count>]:用指定物品替换指定槽位的物品。item replace (block <pos>|entity <targets>) <slot> from (block <sourcePos>|entity <sourceTarget>) <sourceSlot> [<modifier>]:将来源物品复制到目标槽位,并可用 modifier 修改。item override (block <pos>|entity <targets>) <slots> with <item> [<count>]。item override (block <pos>|entity <targets>) <slots> from (block <sourcePos>|entity <sourceTarget>) <sourceSlots> [<modifier>]。
override 类似 replace,但可以跨多个槽位填入物品;目标槽位比来源槽位多时,额外目标槽位被清空。详见参数与槽位。
item fill (block <pos>|entity <targets>) <slots> with <item> [<count>]。item fill (block <pos>|entity <targets>) <slots> from (block <sourcePos>|entity <sourceTarget>) <sourceSlots> [<modifier>]。
fill 类似 override,但不会清空额外目标槽位,而是重复来源槽位中的物品以填满全部目标槽位。
简化语法树
item ...
... modify <TARGET> <slot> <modifier>
... replace <TARGET> <slot>
... with <item> [<count>]
... from <SOURCE> <sourceSlot> [<modifier>]
... override <TARGET> <slots>
... fill <TARGET> <slots>
... with <item> [<count>]
... from <SOURCE> <sourceSlots> [<modifier>]
<TARGET> = (block <pos>|entity <targets>)
<SOURCE> = (block <sourcePos>|entity <sourceTarget>)
最简形式
item (modify (block <pos>|entity <targets>) <slot> <modifier>|replace (block <pos>|entity <targets>) <slot> (with <item> [<count>]|from (block <sourcePos>|entity <sourceTarget>) <sourceSlot> [<modifier>])|(override|fill) (block <pos>|entity <targets>) <slots> (with <item> [<count>]|from (block <sourcePos>|entity <sourceTarget>) <sourceSlots> [<modifier>]))
完全展开
保留原文展开形式中的参数名(其中部分 override 形式写作 <slot>):
item modify block <pos> <slot> <modifier>
item modify entity <targets> <slot> <modifier>
item replace block <pos> <slot> with <item> [<count>]
item replace block <pos> <slot> from block <sourcePos> <sourceSlot> [<modifier>]
item replace block <pos> <slot> from entity <sourceTarget> <sourceSlot> [<modifier>]
item replace entity <targets> <slot> with <item> [<count>]
item replace entity <targets> <slot> from block <sourcePos> <sourceSlot> [<modifier>]
item replace entity <targets> <slot> from entity <sourceTarget> <sourceSlot> [<modifier>]
item override block <pos> <slot> with <item> [<count>]
item override block <pos> <slot> from block <sourcePos> <sourceSlots> [<modifier>]
item override block <pos> <slot> from entity <sourceTarget> <sourceSlots> [<modifier>]
item override entity <targets> <slot> with <item> [<count>]
item override entity <targets> <slot> from block <sourcePos> <sourceSlots> [<modifier>]
item override entity <targets> <slot> from entity <sourceTarget> <sourceSlots> [<modifier>]
item fill block <pos> <slots> with <item> [<count>]
item fill block <pos> <slots> from block <sourcePos> <sourceSlots> [<modifier>]
item fill block <pos> <slots> from entity <sourceTarget> <sourceSlots> [<modifier>]
item fill entity <targets> <slots> with <item> [<count>]
item fill entity <targets> <slots> from block <sourcePos> <sourceSlots> [<modifier>]
item fill entity <targets> <slots> from entity <sourceTarget> <sourceSlots> [<modifier>]
参数
pos(block_pos):要修改的方块位置。targets(entity):要修改的一个或多个实体。slot(item_slot):要修改的物品栏槽位;有效值取决于目标是方块还是实体。slots(slot_source):类似 slot,但可包含多个槽位。modifier(loot_modifier):要对所选物品应用的物品修饰器。item(item_stack):要放入方块或实体物品栏槽位的物品。count(integer):放入的物品数量,范围 1–99。大于 99 无法解析;大于物品最大堆叠数时失败。sourcePos(block_pos):复制物品的来源方块位置。sourceTarget(entity):复制物品的来源实体;“单个实体”限制在原文标为适用至 Java 26.3 之前。sourceSlot(item_slot):复制物品的来源槽位,有效值取决于来源是方块还是实体。sourceSlots(slot_source):类似 sourceSlot,但可包含多个槽位。
结果
命令不完整或任意参数不正确时无法解析。下列情况失败:
/item modify ...或/item ... from ...的 modifier 不符合任一条件:若是资源位置,须指向已有物品修饰器;若是字符串 NBT 标签,须能解析为指向已有修饰器的资源位置;若是非字符串 NBT 标签,须能解码为物品修饰器。/item modify block ...或/item replace block ...的 pos 未载入、超出世界、不是容器,或没有指定槽位。/item modify entity ...或/item replace entity ...的目标未解析到实体(指定名称的玩家须在线);或者全部实体均至少满足一项:没有指定槽位(例如僵尸没有 horse.armor),或指定物品不能放入其该槽位(例如将石头放入玩家 armor.chest)。/... with <item> <count>的 count 超过物品堆叠上限。/... from block ...的 sourcePos 未载入、超出世界、不是容器,或没有指定槽位。/... from entity ...的 sourceTarget 未解析到单个实体(指定玩家须在线),或来源实体没有指定槽位(例如僵尸没有 horse.armor)。
其他情况成功。
输出
失败时成功次数、success、result 均为 0。/item (modify|replace) block ... 成功时三者均为 1;/item (modify|replace) entity ... 成功时成功次数和 success 为 1,result 为物品成功被替换的实体数量。原文未列 override/fill 的独立输出行。
示例
- 将上方两格处单个箱子右下角槽位替换为 4 棵云杉树苗:
/item replace block ~ ~2 ~ container.26 with minecraft:spruce_sapling 4。 - 将最近玩家最右侧快捷栏槽位替换为 4 棵云杉树苗:
/item replace entity @p hotbar.8 with minecraft:spruce_sapling 4。 - 用选定玩家主手物品替换其副手:
/item replace entity @s weapon.offhand from entity @s weapon.mainhand。 - 将棕色旗帜戴到玩家头上:
/item replace entity @s armor.head with minecraft:brown_banner。 - 增加主手物品数量:
/item modify entity @s weapon.mainhand example:increase_count;数据包文件data/example/item_modifier/increase_count.json内容为:
{
"function": "minecraft:set_count",
"count": 1,
"add": true
}
- 不使用外部文件增加主手物品数量:
item modify entity @s weapon.mainhand {"function":"minecraft:set_count","count":1,"add":true}。 - 将手中物品放到头上:
/item replace entity @s armor.head from entity @s weapon.mainhand。
另见
- /data:也能替换容器或生物物品栏物品,或修改盔甲与武器掉落概率。
- /give:无需指定槽位或覆盖其他物品即可给予玩家物品。
- /replaceitem:基岩版对应命令。
中文翻译/改编自 Minecraft Wiki 原条目,原文作者可由页面历史查看;译文遵循 CC BY-NC-SA 3.0(署名、非商业性使用、相同方式共享)。