TNT particles: use drops list smartly

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.
This commit is contained in:
Auke Kok 2016-03-18 23:07:15 -07:00 committed by paramat
parent 3623398b78
commit eafd1ebc43

@ -138,7 +138,7 @@ local function entity_physics(pos, radius)
end end
end end
local function add_effects(pos, radius) local function add_effects(pos, radius, drops)
minetest.add_particlespawner({ minetest.add_particlespawner({
amount = 128, amount = 128,
time = 1, time = 1,
@ -158,14 +158,12 @@ local function add_effects(pos, radius)
-- we just dropped some items. Look at the items entities and pick -- we just dropped some items. Look at the items entities and pick
-- one of them to use as texture -- one of them to use as texture
local texture = "tnt_blast.png" --fallback texture local texture = "tnt_blast.png" --fallback texture
local objs = minetest.get_objects_inside_radius(pos, 2) local most = 0
for _, obj in pairs(objs) do for name, stack in pairs(drops) do
if obj and obj:get_luaentity() then local count = stack:get_count()
local def = ItemStack(obj:get_luaentity().itemstring):get_definition() if count > most then
if def.tiles then most = count
texture = def.tiles[1] texture = minetest.registered_nodes[name].tiles[1]
break
end
end end
end end
@ -265,7 +263,7 @@ function tnt.boom(pos, def)
if not def.disable_drops then if not def.disable_drops then
eject_drops(drops, pos, def.radius) eject_drops(drops, pos, def.radius)
end end
add_effects(pos, def.radius) add_effects(pos, def.radius, drops)
end end
minetest.register_node("tnt:boom", { minetest.register_node("tnt:boom", {