Skip to content

Commit

Permalink
Deepcopy pointed_thing for after_place_node, give it to on_rightclick…
Browse files Browse the repository at this point in the history
… too.
  • Loading branch information
Ekdohibs committed Jan 11, 2014
1 parent 3bbd280 commit e21b29f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
15 changes: 11 additions & 4 deletions builtin/item.lua
Expand Up @@ -270,12 +270,18 @@ function minetest.item_place_node(itemstack, placer, pointed_thing, param2)

-- Run callback
if def.after_place_node then
-- Copy place_to because callback can modify it
-- Deepcopy place_to and pointed_thing because callback can modify it
local place_to_copy = {x=place_to.x, y=place_to.y, z=place_to.z}
local pointed_thing_copy = {
type = pointed_thing.type,
under = pointed_thing.under,
above = pointed_thing.above
under = {
x = pointed_thing.under.x,
y = pointed_thing.under.y,
z = pointed_thing.under.z},
above = {
x = pointed_thing.above.x,
y = pointed_thing.above.y,
z = pointed_thing.above.z}
}
if def.after_place_node(place_to_copy, placer, itemstack,
pointed_thing_copy) then
Expand Down Expand Up @@ -317,7 +323,8 @@ function minetest.item_place(itemstack, placer, pointed_thing, param2)
local n = minetest.get_node(pointed_thing.under)
local nn = n.name
if minetest.registered_nodes[nn] and minetest.registered_nodes[nn].on_rightclick then
return minetest.registered_nodes[nn].on_rightclick(pointed_thing.under, n, placer, itemstack) or itemstack, false
return minetest.registered_nodes[nn].on_rightclick(pointed_thing.under, n,
placer, itemstack, pointed_thing) or itemstack, false
end
end

Expand Down
2 changes: 1 addition & 1 deletion builtin/misc_helpers.lua
Expand Up @@ -278,7 +278,7 @@ if minetest then
local undef = minetest.registered_nodes[unode.name]
if undef and undef.on_rightclick then
undef.on_rightclick(pointed_thing.under, node, placer,
itemstack)
itemstack, pointed_thing)
return
end
local pitch = placer:get_look_pitch()
Expand Down
6 changes: 4 additions & 2 deletions doc/lua_api.txt
Expand Up @@ -2205,10 +2205,12 @@ Node definition (register_node)
on_punch = func(pos, node, puncher),
^ default: minetest.node_punch
^ By default: does nothing
on_rightclick = func(pos, node, clicker, itemstack),
on_rightclick = func(pos, node, clicker, itemstack, pointed_thing),
^ default: nil
^ if defined, itemstack will hold clicker's wielded item
Shall return the leftover itemstack
^ Shall return the leftover itemstack
^ Note: pointed_thing can be nil, if a mod calls this function

on_dig = func(pos, node, digger),
^ default: minetest.node_dig
^ By default: checks privileges, wears out tool and removes node
Expand Down

0 comments on commit e21b29f

Please sign in to comment.