Bang! — Simulating an On-TNT-Exploded Event in MakeCode for Minecraft


Bang Code

The Bang program  places TNT in the ground of a flat world. It then places a  flint and steel item in the player inventory. The player is teleported to within a few blocks above the TNT so that the TNT can be ignited. 

I wanted the player to be way high above the TNT area so that the full effect of the explosion could be seen. After igniting the TNT, it is hard to manually fly the player rapidly enough and high enough to catch the full view. What I needed was a TNT-Exploded event that, when triggered, would teleport the player high enough to get the desired view. But after reading, searching and experimenting, I didn’t find a way to do this with MakeCode’s built-in events (e.g., on block destroyed).

My solution was to simulate a TNT-Exploded event. The key idea was that after the event is enabled, it repeatedly tests the block under origin. The block is originally grass,  then replaced by TNT, and  when the TNT explodes, it is destroyed and replaced by air. When the event is enabled and the test for air succeeds, the TNT has exploded and the player is teleported high in the sky.

Before running bang, be sure the player is flying; otherwise, she will fall all the way to  bedrock after the teleport. I would like to find a way to programmatically put the player in flying mode, but haven’t found it as of this writing.

The implementation of the TNT-Exploded event uses the global variable TNT_eventEnabled, which is false until the TNT is in place and the player is in position to ignite it. Once the event is enabled, the forever loop, which runs repeatedly, proceeds to test for air under origin. When air is found, the player is teleported sky high and the event is disabled so that it will run only once for each run of bang.


Bang is a companion program to Flat Fixer. Using the two programs, Bang can make a mess and Flat Fixer can clean it up again and again and …

Get the Code

Bang! code is shared on Code Connection at this URL

To get and use the code, follow these steps.

Click the Import button import button , which is upper right in the Code Connection window just below the banner. This will open the window shown below.
Import choices

Click the Import URL button Import URL, which is on the right, to open the window shown below.

Import Copy link

Paste the URL supplied for the program you want to use in the space under the text “Copy the URL …”
import url with url

Click the Go ahead! button go ahead button.

The next window you will see will be the MakeCode window with the code downloaded from the URL. At this point, you can treat it like any other code, e.g., run it, save it locally, modify it, publish your changes or whatever else your heat desires.

We have tested several other methods of downloading the code using the URL, for example, pasting the URL in a browser. No joy. For more detailed instruction see our post How to Use Shared MakeCode on Microsoft Code Connection for Minecraft.

One thought on “Bang! — Simulating an On-TNT-Exploded Event in MakeCode for Minecraft

  1. Pingback: Flat Fixer in MakeCode for Minecraft | We Code MakeCode

Comments are closed.