From 41a51a6678054f712187574bdfd807e73872ab7a Mon Sep 17 00:00:00 2001 From: Auke Kok Date: Mon, 25 Jan 2016 22:27:15 -0800 Subject: [PATCH 1/3] Allow the on_blast API to pass an itemstack. 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. --- mods/tnt/init.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mods/tnt/init.lua b/mods/tnt/init.lua index 6a459655..33f0754d 100644 --- a/mods/tnt/init.lua +++ b/mods/tnt/init.lua @@ -93,7 +93,12 @@ local function destroy(drops, pos, cid) end local def = cid_data[cid] if def and def.on_blast then - def.on_blast(vector.new(pos), 1) + local node_drops = def.on_blast(vector.new(pos), 1) + if node_drops then + for _, item in ipairs(node_drops) do + add_drop(drops, item) + end + end return end if def and def.flammable then From 42dc2ed99cc323d831ba095d3453e27f64441a8b Mon Sep 17 00:00:00 2001 From: Auke Kok Date: Sun, 24 Jan 2016 23:27:50 -0800 Subject: [PATCH 2/3] Make TNT a bit more fun. 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. --- mods/tnt/init.lua | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/mods/tnt/init.lua b/mods/tnt/init.lua index 33f0754d..99d11a23 100644 --- a/mods/tnt/init.lua +++ b/mods/tnt/init.lua @@ -49,23 +49,20 @@ local function eject_drops(drops, pos, radius) local drop_pos = vector.new(pos) for _, item in pairs(drops) do local count = item:get_count() - local max = item:get_stack_max() - if count > max then - item:set_count(max) - end while count > 0 do - if count < max then - item:set_count(count) - end + local take = math.min(math.random(2,5), + item:get_count(), + item:get_stack_max()) rand_pos(pos, drop_pos, radius) - local obj = minetest.add_item(drop_pos, item) + local obj = minetest.add_item(drop_pos, item:get_name() .. " " .. take) if obj then obj:get_luaentity().collect = true obj:setacceleration({x=0, y=-10, z=0}) - obj:setvelocity({x=math.random(-3, 3), y=10, + obj:setvelocity({x=math.random(-3, 3), + y=math.random(0, 10), z=math.random(-3, 3)}) end - count = count - max + count = count - take end end end From 24e72140979ff7d936aaa088fa66c4e0236ba636 Mon Sep 17 00:00:00 2001 From: Auke Kok Date: Sun, 24 Jan 2016 23:48:38 -0800 Subject: [PATCH 3/3] TNT: add some depth to the explosion effect 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. --- mods/tnt/init.lua | 32 ++++++++++++++++++++++++++++++-- mods/tnt/textures/tnt_blast.png | Bin 0 -> 855 bytes 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 mods/tnt/textures/tnt_blast.png diff --git a/mods/tnt/init.lua b/mods/tnt/init.lua index 99d11a23..a9552608 100644 --- a/mods/tnt/init.lua +++ b/mods/tnt/init.lua @@ -146,7 +146,7 @@ local function entity_physics(pos, radius) end end -local function add_effects(pos, radius) +local function add_effects(pos, radius, drops) minetest.add_particlespawner({ amount = 128, time = 1, @@ -162,6 +162,34 @@ local function add_effects(pos, radius) maxsize = 16, texture = "tnt_smoke.png", }) + + -- we just dropped some items. Look at the items entities and pick + -- one of them to use as texture + local texture = "tnt_blast.png" --fallback texture + for name, drop in pairs(drops) do + local def = minetest.registered_nodes[name] + if def and def.tiles and def.tiles[1] then + texture = def.tiles[1] + break + end + end + + minetest.add_particlespawner({ + amount = 64, + time = 0.1, + minpos = vector.subtract(pos, radius / 2), + maxpos = vector.add(pos, radius / 2), + minvel = {x=-3, y=0, z=-3}, + maxvel = {x=3, y=5, z=3}, + minacc = {x=0, y=-10, z=0}, + maxacc = {x=0, y=-10, z=0}, + minexptime = 0.8, + maxexptime = 2.0, + minsize = 2, + maxsize = 6, + texture = texture, + collisiondetection = true, + }) end local function burn(pos) @@ -223,7 +251,7 @@ local function boom(pos) local drops = explode(pos, radius) entity_physics(pos, radius) eject_drops(drops, pos, radius) - add_effects(pos, radius) + add_effects(pos, radius, drops) end minetest.register_node("tnt:tnt", { diff --git a/mods/tnt/textures/tnt_blast.png b/mods/tnt/textures/tnt_blast.png new file mode 100644 index 0000000000000000000000000000000000000000..bbb1096f5d81f68b0247f1bd386357f1c14c2579 GIT binary patch literal 855 zcmV-d1E~CoP)o&74tn0wNWtEkm#^jZ>SJP!74EEBU-F0SihuX3Ls`c>`{pYM;V{Pz0=Ql$KI zE%7{$!T1g-raXT7f}f5uUcEjC;P5cS7b}D@hO3*5uwod^oqJMMX4tk(Q4}cSVbTe2 zFC(OsoSuYet(im{?9=a>+^$^SfB1kD|FYXYA_x|I)2i`#D(IiI$wiI9a7ef5a2Z9s zxlp`(9x{z3Vl)HWEbd8mF~@aXF0Z%qt#hB&QdCxkQ_ zlOzdOHyQojmR`0J9yJVFYwR>l8IBX;IA$-%c>MGQCY>-C4*6^hLI~;%u`HK&S1a;l z%AN7JU2e}O@;oO}4pO9i8Y?>WjM+-iZ8``ca9x+BaNR;#h&s;xo4 z7w}FsING;)_4*tsC6`e|w;k}H?vt1*A3x5xT}(Oq@foAJ!|45=DB~fzO^3ff#Rwr7 z{TBi7?4XR4lIy#SNwh(0&FM*ql#;iX5hk6Wj7L!v*roDATCIdM8nRRYhle4PwdUpX z5XBC09McFk{PEWplu|tTHsI3;}TUTrW0;A2k5r9 heHdfdt!UP{&;J-adc&TrL81Tv002ovPDHLkV1k_