Add overridable function for handling dropped items from nodes
authorPerttu Ahola <celeron55@gmail.com>
Sun, 2 Sep 2012 16:38:44 +0000 (19:38 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Sun, 2 Sep 2012 16:38:44 +0000 (19:38 +0300)
builtin/item.lua
doc/lua_api.txt

index 4e3c74444d18374f2ddf02e49e4d31f304b529bc..0f8dcff1fbc2192de307c8d35ff8cbd02a7c2432 100644 (file)
@@ -260,6 +260,16 @@ function minetest.node_punch(pos, node, puncher)
        end
 end
 
+function minetest.handle_node_drops(pos, drops, digger)
+       -- Add dropped items to object's inventory
+       if digger:get_inventory() then
+               local _, dropped_item
+               for _, dropped_item in ipairs(drops) do
+                       digger:get_inventory():add_item("main", dropped_item)
+               end
+       end
+end
+
 function minetest.node_dig(pos, node, digger)
        minetest.debug("node_dig")
 
@@ -284,14 +294,9 @@ function minetest.node_dig(pos, node, digger)
        local dp = minetest.get_dig_params(def.groups, tp)
        wielded:add_wear(dp.wear)
        digger:set_wielded_item(wielded)
-
-       -- Add dropped items to object's inventory
-       if digger:get_inventory() then
-               local _, dropped_item
-               for _, dropped_item in ipairs(drops) do
-                       digger:get_inventory():add_item("main", dropped_item)
-               end
-       end
+       
+       -- Handle drops
+       minetest.handle_node_drops(pos, drops, digger)
 
        local oldmetadata = nil
        if def.after_dig_node then
index d3e254a2d8643fad1368050df654b092c02bc80d..b71b6d62c0516b8a2cc970a863e1bacfd8366a00 100644 (file)
@@ -891,6 +891,12 @@ minetest.get_craft_recipe(output) -> input
 ^ input.items = for example { stack 1, stack 2, stack 3, stack 4,
                               stack 5, stack 6, stack 7, stack 8, stack 9 }
 ^ input.items = nil if no recipe found
+minetest.handle_node_drops(pos, drops, digger)
+^ drops: list of itemstrings
+^ 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)
 
 Rollbacks:
 minetest.rollback_get_last_node_actor(p, range, seconds) -> actor, p, seconds