Step 1: In Minecraft press ‘C’ (for code) to enter the code builder
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 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: Multiple square tunnels going downwards
If you completed the previous challenges this is probably the easiest one. By adding a single repeat block you can now build many square tunnels on top of each other. Each square goes down 4 blocks. So if you dig 4 square tunnels you would go down 16 (4×4) blocks like a spiral staircase! You will now have 3 repeat blocks – one to do the straight tunnel, the second to repeat the tunnel 4 times, turn and go down on each corner. Finally, the third repeat will repeat the second repeat any number of times! Confused? It’s a challenge!
If you dig out the centre of the square tunnels it would look something like this.
Bonus code: 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 room.
Does your underground mansion look something like this picture of an ant farm? Lots of rooms connected by tunnels.