Skip to content
Sirawit Thaya edited this page Jun 22, 2021 · 8 revisions

Fairly basic. The sequence is something like this:

  1. Place a TNT block
  2. Use Flint and Steel on the TNT block
  3. Create a PrimedTNT entity, spawn it with a fuse of 80 world-ticks.
  4. On entity tick, countdown the fuse to 0 (it's a byte).
  5. When 0, despawn the Primed TNT, and do the explosion.

The explosion code is farily straightforward. It calculates a sphere of impact with an explosion factor or 4.0f. It then iterates through all the affected blocks (not Air) and

  1. Add the coordinates to a list of coordinates affected
  2. Set the block to Air or break block to take care of potential item drops.
  3. Randomly (0-3) sets flamable items on Fire.
  4. If an affected block is another TNT, primes it and sets the fuse to Random(0-80/4)+80/8.

Then it sends an MCPE Explode with the absolute coordinates of the explosion center, a radius of the explosion, and a list of coordinates for all affected blocks.

Depending on your implementation, it will send block updates when you set the blocks above, otherwise you just send them after the explosion. Do note, that sending block updates needs to be handled with care, because it has a tendency of creating a lot of lag on the client as well as the server. MiNET experience minimal lag on a normal TNT, but larger booms (radius of 100 and more) creates a much bigger lag (but still ok).