From c76a91943cfc6c464f984ffa02c848c7f4c76294 Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Sun, 18 Oct 2015 22:06:53 -0400 Subject: [PATCH] Fix TNT drops being placed inside nodes --- mods/tnt/init.lua | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/mods/tnt/init.lua b/mods/tnt/init.lua index 8ce018b4..6a459655 100644 --- a/mods/tnt/init.lua +++ b/mods/tnt/init.lua @@ -29,8 +29,20 @@ minetest.after(0, function() end) local function rand_pos(center, pos, radius) - pos.x = center.x + math.random(-radius, radius) - pos.z = center.z + math.random(-radius, radius) + local def + local reg_nodes = minetest.registered_nodes + local i = 0 + repeat + -- Give up and use the center if this takes too long + if i > 4 then + pos.x, pos.z = center.x, center.z + break + end + pos.x = center.x + math.random(-radius, radius) + pos.z = center.z + math.random(-radius, radius) + def = reg_nodes[minetest.get_node(pos).name] + i = i + 1 + until def and not def.walkable end local function eject_drops(drops, pos, radius)