In this project, we will allow our Minecraft character to place a bomb anywhere in the Minecraft world with a the press of a button, and then detonate that bomb with another press of the button.

For this project, we only need a single button on the breadboard. In our code below, we assume the button is attached to GPIO24. You are welcome to use a setup from a previous project, as long as one of the buttons is correctly attached to GPIO you use in your code:

For this project, we'll create a game loop that has two modes:

To keep track of the modes, we use the variable place_mode, which will be set to True when we're in place mode. The game starts in place mode.

To find out where the bomb is placed when the button is hit in Place mode, we use the pollBlockHits() function, similar to the way we used it in the project.

Finally, our detonate() function is identical to the dig() function in the project.

Here is what the full code for this project should look like:

Give it a try... Hit the button once to place the bomb, then move away and hit the button again to detonate the bomb.

  1. Assuming you still have your controller wired up, add this bomb code to the Minecraft controller code ( project) so that you can place a bomb while using the CREATOR Kit as a controller.

  2. The default radius of our explosion is 1. Can you change the code to use a larger radius? Don't go too big, if you do, you can end up deleting the whole Minecraft world (and the Minecraft server will likely hang for a while as that occurs). Don't forget, though, you can always recreate a new world from the Minecraft start screen.

  3. Can you change the code to allow Steve to place two blocks, one after the other, and detonate them both together?