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].tag
But 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?
Best Answer
Root cause: PEBKAC.
TileX
,TileY
,TileZ
to select the correct target entity.Items[{Slot: 0b}]
as source slot selector instead ofItems[0]
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:should have been:
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:
Check that the correct target entity is selected:
Especially for the target entity, note that the coordinates are sometimes off:
@e[x=-128.5,y=78.5,z=99,...
as entity selector./summon minecraft:item_frame -129 78 99 {Facing:3, Item:{id:"minecraft:filled_map", tag: {map: 48}, Count: 1}}