Fix TNT drops being placed inside nodes
authorShadowNinja <shadowninja@minetest.net>
Mon, 19 Oct 2015 02:06:53 +0000 (22:06 -0400)
committerparamat <mat.gregory@virginmedia.com>
Tue, 5 Jan 2016 23:28:59 +0000 (23:28 +0000)
mods/tnt/init.lua

index 8ce018b47992fa0619991a4279b5979bb0810630..6a459655c1f3a8d8d00f1da4316a86f3825d64f6 100644 (file)
@@ -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)