How can I make a secret room using command blocks?
Solution 1:
You wouldn't want to use setblock.
A command block can only hold one command, so it can /setblock
in only one place. Take this command:
/setblock -124 45 -246 minecraft:stone
That command would take up one whole command block, and only place one block at the position (-124, 45, -246).
The better option would to be the /fill
command. Consider this:
/fill -124 45 -246 -150 50 -246 minecraft:stone
This command would fill stone blocks from the point of (-124, 45, -246) to (-150, 50, -246), effectively generating a stone wall. You'd need 12 command blocks (one for each wall, the roof and the floor to generate the walls, and 6 more to fill them with whatever block surrounds the room) plus one for each other block you have in the room, but it's a far cry from the 500+ you'd need if you were using the /setblock
command.
Approaching the problem
We know what commands we're going to use now, so let's get the coordinates of the walls. Go to where you plan your first wall to start and click F3, or FN + F3 if you're on a laptop.
Find the circled line on your computer and write down the numbers after Block:
. These are the coordinates you will use first. Now fly up to where you want the end of your wall to be and write down those coordinates too.
Place down a command block where you want your secret room entrance to be and put the following command inside:
/fill (Coordinates 1) (Coordinates 2) minecraft:planks 0 replace
Place down another command block after it, possibly using a repeater:
/fill (Coordinates 1) (Coordinates 2) minecraft:air replace
Now repeat the steps from the beginning of this section for each of the walls, roof and floor. Once you've done that, you've finished! Here's a bird's eye view of how the command blocks should look:
All the bottom ones are the /fill wood planks and the top ones /fill air.