CHAPTER 7
COMBINATION LOCK
This combination lock on your door will keep strangers away from your precious goods! It uses three numbers, but you can easily expand it to use four, five, or more numbers, as you will see. This lock is best for an area that you will only open temporarily while you are there, like a special storage area.
The lock is based on the way that comparators behave with item frames. You’ve probably already seen that an item in an item frame can be rotated and goes through eight positions. A comparator can produce a signal based on that position. The item frame must be placed on a block behind the comparator for this to work. When there is no item in the frame, the comparator produces no signal. When you place an item in, and the item is straight up and down (or, the same way its icon appears in the Minecraft inventory), the comparator makes a signal strength of 1. Each time the item is rotated, the comparator increases the signal strength by one, up to the last position before it returns to normal, 8.
The arrow in this item frame is in the same position as the arrow icon you see in your inventory. Because it is in the default position, an attached comparator will send the default signal strength of 1.
Before creating your combination lock, decide what your three-number combination number will be. Each number must be between 1 and 8. The number of blocks and redstone you use will depend on your combination, as you will see. For this tutorial, we’re using the combination number 3-8-5. Once you work through this project, you will see how you can easily change it to use your own secret number.
What You Need:
64+ blocks of your choice (I’ve used 33 birch blocks, 3 lime green wool, 27 yellow wool, and 1 magenta wool.)
1 iron door
3 item frames
3 arrows
3 comparators
4 redstone torches
4 repeaters
60+ redstone dust
1. Build a wall that is 3 blocks high and 11 blocks long using blocks of your choice. (I’ve used birch wood blocks.) Leave a 2-block space for a door on the right, 1 block in from the right side. This is the wall your lock and door will be on.
2. Place the iron door in the space you’ve left, and place 3 item frames 1 block up from the bottom of the wall, and spaced 1 block apart from each other, as shown. There should be 3 blocks between the rightmost item frame and the door. (The recipe for an item frame is 1 leather surrounded by 8 sticks.)
3. In each item frame, place an arrow. It should be pointing diagonally to the upper left, just as the arrow in your Minecraft inventory looks. This is position 1.
NOTE: For the item frame, you can choose any item that will clearly show what position it is in. This will be any item that isn’t vertically symmetrical. Its top and bottom should be different, like an arrow, a sword, or a feather. If you use something that looks very much the same when it is rotated, like a snowball, it will be difficult to tell what position it is in.
4. Rotate each arrow to the position that shows what number it is. We are using the numbers 3 – 8 – 5 for the lock, so click the leftmost item frame 2 times to move the arrow to the 3 position. Click the middle item frame 7 times, and click the right frame 4 times.
5. Behind the wall, place 3 blocks on the ground, exactly opposite the item frames. I’ve used lime green wool. On top of these, place 3 comparators facing away from the item frames. Because the comparators are already detecting the item frames, they will light up.
6. Now let’s test the signal strength of each comparator. Just above and in front of each comparator, place a row of 9 blocks (I’ve used yellow wool), for a total of 3 rows. On top of each of these yellow wool blocks place redstone dust. Now look at how far the redstone signal travels on each. The comparator behind the leftmost item frame at position 3 should have 3 blocks of dust lit up. The second comparator should send the signal 8 blocks, and the third or rightmost should send the signal only 5 blocks. (If you have different results, check the position of the item in the item frame.)
7. Now remove all of the blocks on these rows that are not carrying signal, leaving just the redstone and yellow wool blocks that are lit up. The left row will be 3 blocks long, the middle will be 8 blocks long, and the right will be 5 blocks long.
8. On the very end of all 3 rows, place a redstone torch as shown. Notice that the signal traveling from the comparator turns these torches off.
9. Beneath each row, add redstone dust that reaches from the green wool holding the comparator to the block right below the torch at the end.
10. At the end of each line of redstone you just placed, add a repeater facing away from the wall.
11. At the end of the longest row of yellow blocks add 1 redstone dust. Add enough redstone dust at the end of the other 2 rows so that they reach the same length as the first, as shown.
12. Use 2 redstone dust to connect the 3 lines at their ends.
13. At the end of the redstone line nearest the door, place 3 redstone dust to bring the signal out and then change direction toward the door, as shown.
14. Place a repeater facing toward the door at the end of the line you just created.
15. Run redstone dust from the repeater all the way back to the wall. Stop just 1 block before you reach the wall.
16. At the wall, on the same side as your redstone, break the 2 blocks next to the door and the 2 blocks in front of this, as shown.
17. Now use 3 redstone dust to connect the trail to the block beside the door, as shown.
18. At the moment, the redstone is working the opposite to the way we want it. The door will remain closed whenever the combination is right. It will open whenever the combination is wrong. Test this out by changing the position of an arrow in one of the item frames. To fix this, we change the signal to be the opposite of what it is now. First, break 2 of the redstone dust in the last trail that leads to the door.
19. On the side closest to the last repeater, place 1 block. I’ve used magenta wool.
20. On the front side of the block you just placed, facing the wall, place a redstone torch. The redstone torch will be turned off from any signal coming to the block it is on. If there is no signal, it will send its own signal to the door. Congratulations! You are done with the redstone! Go test your lock, changing the item frames to the right positions and the wrong positions.
21. Now you can add any design touches you want. Here, I’ve created a storage building. I closed off the redstone section and added a storage room with lots of chests, furnaces, and crafting tables. I’ve used jungle wood, acacia and birch wood planks, slabs, and stairs, orange-stained clay, glowstone, and birch wood fence.
How to Customize the Lock
You can change this lock so that it uses your own private number. You will need to change the length of each row of redstone behind the item frame to match the numbers you choose. To do this, just follow steps 4 through 12 again to determine how long the row needs to be and to hook it up to the rest of the rows. You can also add more numbers, by copying and adding the same pattern of item frame, comparator, redstone dust, and repeaters to this setup.
How It Works
Each item frame–comparator combination sends out a signal whose length in blocks is the same as the item’s position. If the item frame arrow is in the wrong position, the comparator will send out a signal that is either too long or too short. If the signal is too long, the redstone dust beneath the yellow wool will reach the repeater, and turn the redstone signal to the final repeater on. (The final repeater is there to make sure none of the redstone signals fizzle out because the lines of dust are too long.) If the signal is too short, the redstone dust will not reach either the top torch or the bottom repeater. However, this lets the redstone torch turn back on. The torch then powers the redstone signal reaching the final repeater before the door. If any signal comes through to the final repeater, the repeater will send along the signal to the torch and turn it off. The torch off means that no signal to open the door will reach the door. Only when all of the three possible signals from the comparators are off will a redstone signal, from the very last redstone torch, reach the door and open it.