Minecraft – way to change the way chests are facing in /summon

minecraft-commandsminecraft-java-edition

I am creating an adventure map and players will need items every so often so I am using

/summon FallingSand 2140.5 9 -423.5 {TileID:54,Time:1,TileEntityData:{Items:[{id:diamond_helmet,Slot:0,Count:1},{id:diamond_chestplate,Slot:1,Count:1},{id:diamond_leggings,Slot:2,Count:1},{id:diamond_boots,Slot:3,Count:1},{id:diamond_sword,Slot:4,Count:1}]}} 

To summon a chest with the items in it. When the chest spawns it auto-faces South, is there a way using datatags to make it face North?

Best Answer

The facing of a chest is determined by it's block data value, ranging from 2 to 5 (North, South, West, East). For Falling Sand Entities the data value of the block can be set by adding a Data tag to the entity:

/summon FallingSand 2140.5 9 -423.5 {Block:minecraft:chest,Data:2,Time:1,TileEntityData:{Items:[{id:diamond_helmet,Slot:0,Count:1},{id:diamond_chestplate,Slot:1,Count:1},{id:diamond_leggings,Slot:2,Count:1},{id:diamond_boots,Slot:3,Count:1},{id:diamond_sword,Slot:4,Count:1}]}}

(I also replaced TileID with the newer Block. This doesn't exactly matter, but numerical IDs are being phased out gradually, and I expect TileID to break in the future.)


However, as pointed out by MBraedley in the comments, summoning a chest with items can be done directly via setblock, rather than using the old roundabout way of summoning falling sand.

The syntax is

/setblock <x> <y> <z> <TileName> [dataValue] [oldBlockHandling] [dataTag] 

Here, the data value can be set directly. To set the data tag, you'll need to specify oldBlockHandling, I suggest using the default value of replace:

/setblock 2140 9 -423 minecraft:chest 2 replace {Items:[{id:diamond_helmet,Slot:0,Count:1},{id:diamond_chestplate,Slot:1,Count:1},{id:diamond_leggings,Slot:2,Count:1},{id:diamond_boots,Slot:3,Count:1},{id:diamond_sword,Slot:4,Count:1}]}

This command is not only shorter and easier to read, it also executes much faster than the summon version. That is because it doesn't need to create an entity, have it drop to the floor, determine collision, and then turn it into a block and remove the entity.