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:

def dig(mc, pos, radius): r_vector = Vec3(radius,radius,radius) mc.setBlocks(pos - r_vector, pos + r_vector, block.AIR)

Here's how the code works:

- On Line 1, we define our function, called "dig" with the three arguments we discuss above.

- On Line 2, we create a variable called "r_vector" (for "radius vector), which defines a 3-dimensional space using our predefined radius value.

- On Line 3, we use the `.setBlocks()` function to modify all the blocks in the r_vector radius around the location of the hit block.

## Full Code

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

from rstem.button import Button from rstem.mcpi import minecraft, control, block from rstem.mcpi.vec3 import Vec3 import time control.show() mc = minecraft.Minecraft.create() button = Button(24) *radius = 1 *def dig(mc, pos, radius): * r_vector = Vec3(radius,radius,radius) * mc.setBlocks(pos - r_vector, pos + r_vector, block.AIR) while True: if button.presses(): control.hit(duration=0.2) hits = mc.events.pollBlockHits() for hit in hits: * dig(mc, hit.pos, radius) time.sleep(0.01)

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.