Minecraft command to set item frame content from a chest content
In Minecraft Java 1.16, I can use the /data get block command to get the contents of a chest:
/data get block -121 76 105 Items[0]Which tells me that the chest has one map#48 in the upper-left slot:
-121, 76, 105 has the following block data: {Slot: 0b, id: "minecraft:filled_map", tag: {map: 48}, count: 1b}Also, I can use /data modify entity .. set value command to set the contents of an existing item frame:
/data modify entity @e[x=-129,y=79,z=99,type=minecraft:item_frame,limit=1,distance=0..1] Item set value {id:"minecraft:filled_map", tag: {map: 48}, Count: 1}Voila, the item_frame now contains a filled_map!
What's more, it also works if I add the spurious NBT data, like a Slot tag:
/data modify entity @e[x=-129,y=79,z=99,type=minecraft:item_frame,limit=1,distance=0..1] Item set value {Slot: 0b, id:"minecraft:filled_map", tag: {map: 48}, Count: 1}So I was hoping to combine these commands, and set the item frame based on the chest contents using the /data modify entity ... set from block command:
/data modify entity @e[x=-129,y=79,z=99,type=minecraft:item_frame,limit=1,distance=0..1] Item set from block -127 76 105 Items[0]Unfortunately, this gives an error: The target block is not a block entity.
I tried a few modification, by only setting the Item tags:
/data modify entity @e[x=-129,y=79,z=99,type=minecraft:item_frame,limit=1,distance=0..1] Item set value {Slot: 0b, id:"minecraft:filled_map", Count: 1}
/data modify entity @e[x=-129,y=79,z=99,type=minecraft:item_frame,limit=1,distance=0..1] Item.tag set from block -127 76 105 Items[0].tagBut again, I get the error The target block is not a block entity.
Is there a way to set an item frame content based on a chest slot?
11 Answer
Root cause: PEBKAC.
- Make sure that you use the correct coordinates
- Use NBT tags
TileX,TileY,TileZto select the correct target entity. - Use
Items[{Slot: 0b}]as source slot selector instead ofItems[0]
/data modify entity @e[type=minecraft:item_frame, limit=1, nbt={TileX:-129,TileY:78,TileZ:99}] Item set from block -127 76 105 Items[{Slot: 0b}]The most likely cause for The target block is not a block entity error is that you did not select the correct source block or target entity. That's what I did wrong:
/data modify entity @e[x=-129,y=79,z=99,type=minecraft:item_frame,limit=1,distance=0..1] Item set from block -127 76 105 Items[0]should have been:
/data modify entity @e[x=-129,y=79,z=99,type=minecraft:item_frame,limit=1,distance=0..1] Item set from block -121 76 105 Items[0]Did you spot it? Congrats to you. It took me two hours to see that the x coordinate was off: -127 instead of -121 (If you need me, I'm overthere in the corner feeling stupid)
My suggestion to others who end up here with the same issue is to:
Check that you can read data from the source block:
/data get block -121 76 105 Items[0]Check that the correct target entity is selected:
/data get entity @e[type=minecraft:item_frame, limit=1, nbt={TileX:-129,TileY:78,TileZ:99}]
Especially for the target entity, note that the coordinates are sometimes off:
- Use TileX, TileY, TileX (in the nbt data) as entity selector instead of x, y, z.
- The returned Pos(ition) is slightly different: -128.5, 78.5, 99.03. Consider using
@e[x=-128.5,y=78.5,z=99,...as entity selector. - For /summon seems to be one-off in Y-coordinates compared to /data. To create the above item_frame entity, I had to specify y=78 instead of y=79:
/summon minecraft:item_frame -129 78 99 {Facing:3, Item:{id:"minecraft:filled_map", tag: {map: 48}, Count: 1}}