Add on_rightclick(pos, node, clicker) callback for nodes

master
PilzAdam 2013-01-04 00:05:56 +01:00
parent d2b1210376
commit 5bc14e2fe4
2 changed files with 17 additions and 2 deletions

View File

@ -231,9 +231,19 @@ function minetest.item_place_object(itemstack, placer, pointed_thing)
end end
function minetest.item_place(itemstack, placer, pointed_thing) function minetest.item_place(itemstack, placer, pointed_thing)
-- Call on_rightclick if the pointed node defines it
if pointed_thing.type == "node" then
local n = minetest.env:get_node(pointed_thing.under)
local nn = n.name
if minetest.registered_nodes[nn] and minetest.registered_nodes[nn].on_rightclick then
minetest.registered_nodes[nn].on_rightclick(pointed_thing.under, n, placer)
return
end
end
if itemstack:get_definition().type == "node" then if itemstack:get_definition().type == "node" then
return minetest.item_place_node(itemstack, placer, pointed_thing) return minetest.item_place_node(itemstack, placer, pointed_thing)
else elseif itemstack:get_definition().type ~= "none" then
return minetest.item_place_object(itemstack, placer, pointed_thing) return minetest.item_place_object(itemstack, placer, pointed_thing)
end end
end end
@ -375,6 +385,7 @@ minetest.nodedef_default = {
can_dig = nil, can_dig = nil,
on_punch = redef_wrapper(minetest, 'node_punch'), -- minetest.node_punch on_punch = redef_wrapper(minetest, 'node_punch'), -- minetest.node_punch
on_rightclick = nil,
on_dig = redef_wrapper(minetest, 'node_dig'), -- minetest.node_dig on_dig = redef_wrapper(minetest, 'node_dig'), -- minetest.node_dig
on_receive_fields = nil, on_receive_fields = nil,
@ -464,7 +475,7 @@ minetest.noneitemdef_default = { -- This is used for the hand and unknown items
tool_capabilities = nil, tool_capabilities = nil,
-- Interaction callbacks -- Interaction callbacks
on_place = nil, on_place = redef_wrapper(minetest, 'item_place'),
on_drop = nil, on_drop = nil,
on_use = nil, on_use = nil,
} }

View File

@ -942,6 +942,8 @@ minetest.item_place_object(itemstack, placer, pointed_thing)
^ Place item as-is ^ Place item as-is
minetest.item_place(itemstack, placer, pointed_thing) minetest.item_place(itemstack, placer, pointed_thing)
^ Use one of the above based on what the item is. ^ Use one of the above based on what the item is.
^ Calls on_rightclick of pointed_thing.under if defined instead
^ Note: is not called when wielded item overrides on_place
minetest.item_drop(itemstack, dropper, pos) minetest.item_drop(itemstack, dropper, pos)
^ Drop the item ^ Drop the item
minetest.item_eat(hp_change, replace_with_item) minetest.item_eat(hp_change, replace_with_item)
@ -1482,6 +1484,8 @@ Node definition (register_node)
on_punch = func(pos, node, puncher), on_punch = func(pos, node, puncher),
^ default: minetest.node_punch ^ default: minetest.node_punch
^ By default: does nothing ^ By default: does nothing
on_rightclick = func(pos, node, clicker),
^ default: nil
on_dig = func(pos, node, digger), on_dig = func(pos, node, digger),
^ default: minetest.node_dig ^ default: minetest.node_dig
^ By default: checks privileges, wears out tool and removes node ^ By default: checks privileges, wears out tool and removes node