Minecraft – Place a complete bed using /setblock

minecraft-commandsminecraft-java-edition

I am setting up different means of transportation on our server. Right now I'm building an airship with four cabins. In each cabin is a bed. The idea is that each room has a different destination and when you sleep in the bed it teleports you to the same room in a duplicate of that airship at the destination area (to make it like you're really travelling in the ship).

I tried teleporting a sleeping player (using {Sleeping:1b}) but the sleeping animation continued and then moved the player back to the original bed. I corrected this by destroying the bed before teleporting and that fixed it however now I have another issue resulting from that. I replace the bed with /setblock and it only places the foot of the bed.

How can I use a command block to replace the bed so that both the foot and head of the bed are present?

Best Answer

You'll need to use two commands; one to set the foot part, one to set the head part. To setblock the head part of the bed, add 8 to the dataValue you used for the foot part.

For example, these two commands will create a bed facing north:

/setblock 0 64 0 bed 0
/setblock 0 64 1 bed 8

Or these two for a bed facing east:

/setblock 0 64 0 bed 3
/setblock 1 64 0 bed 11