Minecraft – How to lock and give chest a name

minecraft-commandsminecraft-java-edition

I'm making an adventure map and I need to have a command block next to a clock set the block near it to a chest with a custom name with a lock this I what I have so far:

/setblock ~-1 ~-1 ~ Minecraft:trapped_chest 1 {display:{Name:"Locked Chest",Lock:"Chest Key 47"}}

And then it says:

[16:26:39] Data tag parsing failed: Invalid tag encountered, expected '{' as first char.

I'm in 1.8.

Best Answer

The syntax of /setblock is:

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

Which means that you need to specify an [oldBlockHandling] mode (E.G: replace) before you can specify the [dataTag].

The name tag of an entity or tile entity is CustomName, rather than just Name as it is on items. Also, neither it nor Lock are stored in a Display compound tag.

This should be your fixed command:

/setblock ~-1 ~-1 ~ trapped_chest 1 replace {CustomName:"Locked Chest",Lock:"Chest Key 47"}