From 6f49a19fc21a3af6d395732e27a4a4279f9b4e76 Mon Sep 17 00:00:00 2001 From: PilzAdam Date: Sun, 2 Sep 2012 16:12:39 +0200 Subject: [PATCH] Bugfix when droping many items --- init.lua | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/init.lua b/init.lua index 957c159..eae6a48 100644 --- a/init.lua +++ b/init.lua @@ -99,20 +99,39 @@ end minetest.register_on_dignode(function(pos, oldnode, digger) local drop = minetest.get_drops(oldnode.name, digger:get_wielded_item():get_name()) + if drop == nil then + return + end for _,item in ipairs(drop) do - for i=1,item:get_count() do - local obj = minetest.env:add_item(pos, item:get_name()) - if obj ~= nil then - obj:get_luaentity().collect = true - local x = math.random(1, 5) - if math.random(1,2) == 1 then - x = -x + if type(item) == "string" then + local obj = minetest.env:add_item(pos, item) + if obj ~= nil then + obj:get_luaentity().collect = true + local x = math.random(1, 5) + if math.random(1,2) == 1 then + x = -x + end + local z = math.random(1, 5) + if math.random(1,2) == 1 then + z = -z + end + obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z}) end - local z = math.random(1, 5) - if math.random(1,2) == 1 then - z = -z + else + for i=1,item:get_count() do + local obj = minetest.env:add_item(pos, item:get_name()) + if obj ~= nil then + obj:get_luaentity().collect = true + local x = math.random(1, 5) + if math.random(1,2) == 1 then + x = -x + end + local z = math.random(1, 5) + if math.random(1,2) == 1 then + z = -z + end + obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z}) end - obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z}) end end end