From: darkrose Date: Sun, 3 Jun 2012 10:02:10 +0000 (+1000) Subject: Add can_dig callback X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=a149c6ecde66a89bd1080bddf8848a19115a79d4;p=zefram%2Fminetest%2Fminetest_engine.git Add can_dig callback --- diff --git a/builtin/item.lua b/builtin/item.lua index c4bd2420..3d545eec 100644 --- a/builtin/item.lua +++ b/builtin/item.lua @@ -229,7 +229,7 @@ function minetest.node_dig(pos, node, digger) minetest.debug("node_dig") local def = ItemStack({name=node.name}):get_definition() - if not def.diggable then + if not def.diggable or (def.can_dig and not def.can_dig(pos,digger)) then minetest.debug("not diggable") minetest.log("info", digger:get_player_name() .. " tried to dig " .. node.name .. " which is not diggable " @@ -345,6 +345,7 @@ minetest.nodedef_default = { on_place = redef_wrapper(minetest, 'item_place'), -- minetest.item_place on_drop = redef_wrapper(minetest, 'item_drop'), -- minetest.item_drop on_use = nil, + can_dig = nil, on_punch = redef_wrapper(minetest, 'node_punch'), -- minetest.node_punch on_dig = redef_wrapper(minetest, 'node_dig'), -- minetest.node_dig diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 4321bf76..3f640da4 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1149,6 +1149,9 @@ Node definition (register_node) ^ Called after destructing node when node was dug using minetest.node_dig ^ default: nil + can_dig = function(pos,player) + ^ returns true if node can be dug, or false if not + ^ default: nil on_punch = func(pos, node, puncher), ^ default: minetest.node_punch