From Minetest Developer Wiki
(Redirected from handle node drops)
Jump to navigation Jump to search


<source>minetest.handle_node_drops(pos, drops, digger)</source>


Handles drops from nodes after digging: Default action is to put them into digger's inventory

Can be overridden to get different functionality (eg. dropping items on ground)


Taken from PilzAdam's item_drop mod. <source> function minetest.handle_node_drops(pos, drops, digger) for _,item in ipairs(drops) do local count, name if type(item) == "string" then count = 1 name = item else count = item:get_count() name = item:get_name() end for i=1,count do local obj = minetest.add_item(pos, 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})

-- FIXME this doesnt work for deactiveted objects if minetest.setting_get("remove_items") and tonumber(minetest.setting_get("remove_items")) then minetest.after(tonumber(minetest.setting_get("remove_items")), function(obj) obj:remove() end, obj) end end end end end </source>