In the last project, we learned how to read the list of previous hit events, cycle through them and then take some action (printing out the coordinates of the block that was hit). In this project, we're going to continue with the same idea, but instead of just printing out information about the block that was hit, we're going to create an effect on that block.

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

The code for this project is going to look identical to the code in our last project, with one exception, highlighted below:

from rstem.button import Button from rstem.mcpi import minecraft, control, block import time control.show() mc = minecraft.Minecraft.create() button = Button(24) while True: if button.presses(): control.hit(duration=0.2) hits = mc.events.pollBlockHits() for hit in hits: * mc.setBlock(hit.pos, block.AIR) time.sleep(0.01)

In the example above, instead of just printing out where a block was hit, we turn the block into Air, making the block disappear.

The `mc.setBlock()` function takes two arguments:

1. The location of the block that was hit: This was gathered by the `mc.events.pollBlockHits()` function; and

2. The type of block that should be created in this location: In this case, we're creating a block type of "AIR" — this is essentially the same as removing the block entirely.

You've now created a shovel, which, you've probably noticed, does the exact same thing as just smashing blocks. However, our shovel code can be modified to do a whole lot more than just smashing a single block. In fact, in the next project, we'll expand on our shovel functionality in a way that can't be done without custom programming.

1. Can you modify the code so that instead of breaking the block in front of you, instead you break the block behind you? How about to the left or right?