In this project, we're going to expand on our previous two shovel projects. Instead of just smashing the single block that we hit, when we hit a block, we'll smash that block plus all the other blocks within a defined radius of that block. This will demonstrate how the Minecraft API can be used to start doing more interesting types of modifications to the game world.

The hardware configuration for this project is exactly the same as the previous project — a single button mapped to GPIO24:

In this project, we're going to create an external function that will control what happens every time we attempt to smash a block (or dig). This function will take three arguments:

  1. The first will be the Minecraft object (mc) that we use to interact with the Minecraft server;

  2. The second will be the position of the block that was hit; and

  3. The radius we want to smash around the block we hit.

Here is what that function will look like:

Here's how the code works:

Full Code

Here is what the code for this project should look like at this point (with new changes highlighted with arrows):

  1. Assuming you still have your controller wired up, add this shovel code to the Minecraft controller code ( project) to add shovel functionality to one of your controller buttons.

  2. Change the radius to create a larger shovel.

  3. Add (or reuse) 2 buttons: one button should increase the radius, the other one should decrease it. Now you'll have a shovel of varying size!

  4. Instead of turning the blocks that were hit into Air, turn them into something else (say, Brick, perhaps). Now your code works as if you are placing blocks!

  5. Our dig() function dug a perfect cube, but that's not the only shape you can dig. Instead of using setBlocks, use multiple setBlock() calls to dig a different shape.

  6. Add some randomness — when digging with setBlock() you don't always have to turn the block into Air. Use a random function to change it into Air half the time, and a different block type the other half of the time.