起因是我在做物品处理机,处理任意64个物品压缩成1个带64× Lore的物品时,发现输出到箱子内时,如果要用loot insert的话,必须要解决动态物品id的问题。然后我发现似乎用"type": "minecraft:dynamic"类型配合挖掘潜影箱的战利品表,可以做到这一点。
例如玩家手持64个物品,我们想把其数量修改为32。
execute as @a[nbt={SelectedItem:{Count:64b}}] run function test:modify
test:modify
- setblock ~ 255 ~ shulker_box{Items:[{Slot:0b,id:"minecraft:stone",Count:32b}]}
- 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
- replaceitem entity @s weapon.mainhand air
- loot replace entity @s weapon.mainhand 1 mine ~ 255 ~ minecraft:diamond_pickaxe{isShulkerMarker:1b}
- setblock ~ 255 ~ air
修改minecraft/loot_tables/blocks/shulker_box.json为使用特定nbt的镐挖掘时,掉落内含物而且不掉落潜影盒。
- {
- "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"
- }
- ]
- }
- ]
- }
- ]
- }
具体想修改物品信息的情形,可以通过直接修改潜影盒内物品实现,这里不做赘述。
唯一的缺点就是,需要在255高度引入额外的方块潜影盒,这会导致原有的位于255高度的方块消失。