We add on_create() handlers for both burning TNT and burning
gunpowder. Because gunpowder will explode TNT in 1 second,
and not 4, we need to modify the 4 second timer after we
make the TNT burning. Other mods can now place burning TNT
that will by default explode after 4 seconds.
I spotted two places where under stress (many explosions) luajit would
end up passing nil to these functions. I'm not entirely sure how,
but it seems good form to guard against it, which does make it
more robust. After this patch, I'm not able to crash the server. With
many explosions, it may still lag significantly, but always returns
in the end.
We define the blast intensity as the square of the tnt_radius, divided
by the square of the distance to the explosion center, where distance
is limited to 1 at the lower end.
When destroying nodes, we calculate the intensity for each node, and
only destroy the nodes when the intensity is 1.0 or larger. To avoid
perfectly spherical explosions, we make sure to retain a randomness
factor of 20%. This will make explosion edges jagged and not smooth,
but not too much.
We pass the calculated intensity to on_blast() functions as well,
except we take the jitter here out and make sure it's always 1.0
or larger.
We apply a log scale to the size of the stacks ejected, so that
in larger explosions we are getting larger stacks. For normal r=3
explosions, this gives stack sizes ~6-7 or so, but for r=10 explosions
it could end up giving stacks of 25+.V
The drops list already has quantities, so let's just select the one
with the highest quantity from it, and use that as tile. Fallback
tile will therefore only be used if explosion happens in air. Oh well.
We add a dirt-like particle (drawn from scratch, uses some
colors from default_dirt's palette) to spawn many particles
that have collision enabled around the center of the blast.
This has the effect of obscuring the center of the blast, as
that is a painfully visible empty area when the explosion happens,
as there's only a little spark.
The dirt particles bounce around the walls and floor a bit,
and disappear rapidly, well before the smoke particles disappear.
This is a nice visual distraction that obscures the sudden
appearance of the gaping hole, and makes it a whole lot more
believable.
But not too much.
TNT is a bit underwhelming at the moment. We can make it a bit
more interesting by ejecting not just one or two itemstacks,
but a bunch of them. This code splits up the drops into
separate itemstacks that are 2-5 items together, which
results in generally roughly 10 itemstacks being ejected.
Since now we have multiple ejecta, it makes sense to tune
the ejecta velocities a bit better to get the appearance of
an actual explosion better. The items will not all start
with the same vertical velocity, since that would look
like fireworks. Instead we give them all a different vertical
speed.
If the node is special and has an on_blast() handler, we need
to call it instead of getting node drops manually. However, we
do want to know if drops should be added for the special nodes,
so we modify the on_blast() handler code to allow the nodedef
handlers to pass back itemstacks. This could be used by e.g.
the doors mod to drop door items after a blast.
Since this API is documented in lua_api.txt, a separate PR will
be incoming to update the on_blast() documentation.
By adding the timer to the tnt:tnt_burning node it will help mods add the block and cause an explosion after 4 seconds instead of doing nothing like in it's current state.
Spread ABM intervals evenly across 1 to 16 seconds
16s ensures no nodes are missed when player walks past
Adjust chance values to compensate, for identical action rates
Combine lavacooling ABMs into one, return to chance = 1
Grass growth: add 'neighbors = "air"' to avoid
processing the thousands of underground dirt nodes
Grass death: Reduce action rate to that of grass growth
Fire: Use chance = 1 for flame extinguishing
and flame removal when mod is disabled