命令loot replace 可用于动态替换实体/方块物品,是个十分便利的命令。然而可能很多人不知道,该命令是可以一次性替换多个槽位物品的。
- loot replace entity @s 槽位 <source>
 - loot replace block x y z 槽位 <source>
 
(1)首先会根据掉落品表确定将要掉落的物品序列,这些物品可能会相同。如果是潜影箱 "type":"dynamic"得到的掉落物,第X个就是第X个槽位的物品,即使该位置为空。但是通常的战利品表会忽视那些没有掉落物的项。
(2)根据liach查看源代码(见2L)得到结论(或见英文版wiki),确定槽位对应的编号,然后从其开始的编号从小到大依次排列构成将要放入的槽位的序列。
槽位  | 编号  | |
| 容器 | container.0~container.53 | 0~53 | 
| 快捷栏 | hotbar.0~hotbar.8 | 0~8 | 
| 背包 | inventory.0~inventory.26 | 9+0~26,即9~35 | 
| 主手 | weapon或weapon.mainhand | 98 | 
| 副手 | weapon.offhand | 99 | 
| 靴子栏 | armor.feet | 100 | 
| 护腿栏 | armor.legs | 101 | 
| 胸甲栏 | armor.chest | 102 | 
| 头盔栏 | armor.head | 103 | 
| 末影箱 | enderchest.0~enderchest.26 | 200+0~26,即200~226 | 
| 村民背包 | villager.0~villager.7 | 300+0~7,即300~307 | 
| 马、驴、骡的鞍 | horse.saddle | 400 | 
| 马的马铠、羊驼的地毯 | horse.armor | 401 | 
| 驴、骡、羊驼的箱子 | horse.chest | 499 | 
| 驴、骡、羊驼的背包 | horse.0~horse.14 | 500+0~14,即500~514 | 
(3)然后确定槽位数量。玩家可以在命令中指定槽位数量
- loot replace entity @s 槽位 槽位数量 <source>
 - loot replace block x y z 槽位 槽位数量 <source>
 
(4)最后将物品序列塞入槽位序列。
- 尝试塞入不合法的物品(头盔塞入非头部的盔甲、胸甲塞入非胸部的物品、马鞍塞入非马鞍)时,原物品不会被替换掉。
 - 没有相应槽位时,也是无法塞入物品的。包括container序号大于27的槽位也是不存在的,即使是大箱子。
 - 物品数量不足以塞满确定的槽位数量时,多余的槽位物品会被清空。
 
例如使用
- loot replace entity @s weapon.mainhand mine x y z diamond_pickaxe{isShulkerMarker:1b}
 
主手塞入潜影盒内第1个掉落物,若空则清空该位置
副手塞入潜影盒内第2个掉落物,若空则清空该位置
靴子塞入潜影盒内第3个掉落物品,若空或非法则清空该位置
护腿塞入潜影盒内第4个掉落物品,若空或非法则清空该位置
胸甲塞入潜影盒内第5个掉落物品,若空或非法则清空该位置
头盔塞入潜影盒内第6个掉落物品,若空或非法则清空该位置
例如使用
- loot replace entity @s hotbar.0 loot 战利品表
 - 或
 - loot replace entity @s container.0 loot 战利品表
 
背包塞入第10-36个物品
主手、副手、靴子、护腿、胸甲、头盔塞入第99-104个物品
末影箱塞入第201-227个物品
下面这个例子中,我们可以将玩家手部的一个物品转移到头部,类似于插件/hat指令。
- setblock ~ 255 ~ shulker_box{Items:[{Slot:0b,id:"minecraft:firework_star",Count:1b}]}
 - data modify block ~ 255 ~ Items[0].id set from entity @s SelectedItem.id
 - data modify block ~ 255 ~ Items[0].tag set from entity @s SelectedItem.tag
 - loot replace entity @s armor.head 1 mine ~ 255 ~ diamond_pickaxe{isShulkerMarker:1b}
 
- execute store result score #temp sivalue run data get entity @s SelectedItem.Count
 - execute store result block ~ 255 ~ Items[0].Count byte 1 run scoreboard players remove #temp sivalue 1
 - loot replace entity @s weapon.mainhand 1 mine ~ 255 ~ diamond_pickaxe{isShulkerMarker:1b}
 
- setblock ~ 255 ~ air
 
- {
 -     "type": "minecraft:block",
 -     "pools": [
 -         {
 -             "rolls": 1,
 -             "entries": [
 -                 {
 -                     "type": "minecraft:alternatives",
 -                     "children": [
 -                         {
 -                             "type": "minecraft:dynamic",
 -                             "name": "minecraft:contents",
 -                             "conditions": [
 -                                 {
 -                                     "condition": "minecraft:match_tool",
 -                                     "predicate": {
 -                                         "nbt":"{isShulkerMarker:1b}"
 -                                     }
 -                                 }
 -                             ]
 -                         },
 -                         {
 -                             "type": "minecraft:item",
 -                             "functions": [
 -                                 {
 -                                     "function": "minecraft:copy_name",
 -                                     "source": "block_entity"
 -                                 },
 -                                 {
 -                                     "function": "minecraft:copy_nbt",
 -                                     "source": "block_entity",
 -                                     "ops": [
 -                                         {
 -                                             "source": "Lock",
 -                                             "target": "BlockEntityTag.Lock",
 -                                             "op": "replace"
 -                                         },
 -                                         {
 -                                             "source": "LootTable",
 -                                             "target": "BlockEntityTag.LootTable",
 -                                             "op": "replace"
 -                                         },
 -                                         {
 -                                             "source": "LootTableSeed",
 -                                             "target": "BlockEntityTag.LootTableSeed",
 -                                             "op": "replace"
 -                                         }
 -                                     ]
 -                                 },
 -                                 {
 -                                     "function": "minecraft:set_contents",
 -                                     "entries": [
 -                                         {
 -                                             "type": "minecraft:dynamic",
 -                                             "name": "minecraft:contents"
 -                                         }
 -                                     ]
 -                                 }
 -                             ],
 -                             "name": "minecraft:shulker_box"
 -                         }
 -                     ]
 -                 }
 -             ]
 -         }
 -     ]
 - }
 
[groupid=1009]The Command's Power[/groupid]
