Step 0: Make a new world in creative mode
Dig a small hole at least 3 blocks deep and jump in. You should also get some torches from the inventory. Press ‘E’ and search for ‘torch’
Step 1: In Minecraft press ‘C’ (for code) to enter the code builder and select Microsoft MakeCode
Step 2: Click ‘New Project’
Step 3: Give your project a good name
Step 4: Click on the word ‘run’ and change it to ‘dig’
Step 5: Drag the code blocks in to match the picture
Step 6: Close the code builder
Step 7: Test your new ‘dig’ command
You will notice that your agent is teleported to your players location. This is because of the code in the ‘On start’ block that teleports your agent whenever you close the code builder. If you forgot to do step zero and your player is not in a good position to dig a tunnel then what should you do?
The easy solution is to move your player to a location underground and then go back to the code builder (C) and press the play button again to close the code builder. Now you are ready for a real test. Bring some torches (or ask the teacher) – it could get dark.
Step 8: Check that it worked
If your code worked then the agent should now be somewhere ahead of you having dug a short tunnel only 4 blocks long. Any blocks that it destroyed should also be sitting nearby ready for you to pick up.
Step 9: Add commands to make the agent turn left or right
Move your player to the end of the tunnel right next to the agent and then return to the code builder (press C). Add 2 new chat commands ‘L’ (to make the agent turn left) and ‘R’ (to make the agent turn right). It should look like the picture here.
Step 10: Test the new turn commands
To test your new commands you close the code builder again which teleports the agent to your location. You then enter the chat window (press T) and type in either ‘L’ or ‘R’ and then press [Enter] on the keyboard. Once the agent has turned you can try running the ‘dig’ command again and then turn the other way and dig again.
Challenge 1: Make the agent dig a longer tunnel
I think 4 blocks is a bit short, but great for testing as it doesn’t take too long to finish. What would you change in your code to make the tunnel longer? You only need to change 1 number, but don’t make it too long – maximum should be 12. It’s easy to lose track of the agent as it may get hidden by falling sand or gravel.
Which number should you change to make the tunnel longer? There are only 2 numbers in the dig command. Try one and if it doesn’t work try the other!
Challenge 2: Make the agent dig a square tunnel
When you are mining, you really want to explore a large area so digging in straight lines isn’t always the best. With 2 extra blocks of code you can make your agent dig a square shaped tunnel and return to the starting position. You could also duplicate the whole ‘dig’ command (right click and select ‘duplicate’) and then add the extra code. You will need to change the name of the new command – maybe something like ‘dig4’ since it has to do 4 tunnels that connect into a square.
Your square tunnel code should have a repeat inside another repeat! Also, in Minecraft the agent can only turn 90 degrees so you just have to tell it which direction to turn – it could be left or right. Here’s the first step done for you – all you have to do now is to repeat the code 4 times!
If you added the repeat block correctly it should now dig 4 straight tunnels and do 4 turns and the agent should end up where it started. If you ran the code above ground the tunnel would look like this:
Challenge 3: A square tunnel that goes deeper on each corner
All the good stuff in Minecraft is deep underground so digging tunnels that go down makes total sense. With just 2 extra blocks added to your square tunnel code you can make your tunnel go down 1 block on each corner of your square. Bring some torches to put on each corner! Remember, the agent cannot move through solid blocks – it must destroy (hint) a block first and then move down before it digs the next tunnel.
Ok, massive hint in the next picture.
Challenge 4: Dig a room
Some of the previous challenges were pretty hard, but if you managed to finish them here’s some extra code to make tunneling more interesting. What would we get if the agent dug several tunnels right next to each other? A room!
In the bonus code below you will recognise the ‘repeat 6’ block contains the original ‘dig’ command code. Afterwards the agent moves backwards 6 steps then destroys the block to the right, moves right and repeats the tunnel again. If we do this 4 times (using the ‘repeat 4’ block) we get a 6×4 block room.
Import code
Use the following link to import the code required to this point: https://makecode.com/_Df6DAL5VYTXP
Challenge 5: Straight staircase
See if you can figure out how to do a normal staircase that goes down every block. Remember you need enough space for your player (2 blocks tall) to fit. Here are a few clues and a picture showing the shape of the staircase:
- You will need to do 3 destroys (fwd, up, dn)
- You will need 2 moves (fwd, dn)
- Put all 5 blocks in a repeat loop
Challenge 6: Spiral staircase
Once you can do a straight staircase then this should be easy and very similar to the square staircase we did previously which was made up of 4 tunnels. The spiral staircase should have 4 straight staircases in a square. All you need is 2 more blocks!
Underground cities
Does your underground mansion look something like this picture of an ant farm? Lots of rooms connected by tunnels.