Skip to content

Commit 1b5b6fe

Browse files
committedJan 22, 2014
Add pointed_thing to minetest.register_on_placenode
As suggested by qwrwed.
1 parent 057858d commit 1b5b6fe

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed
 

‎builtin/item.lua

+13-2
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,22 @@ function minetest.item_place_node(itemstack, placer, pointed_thing, param2)
292292
-- Run script hook
293293
local _, callback
294294
for _, callback in ipairs(minetest.registered_on_placenodes) do
295-
-- Copy pos and node because callback can modify them
295+
-- Deepcopy pos, node and poined_thing because callback can modify them
296296
local place_to_copy = {x=place_to.x, y=place_to.y, z=place_to.z}
297297
local newnode_copy = {name=newnode.name, param1=newnode.param1, param2=newnode.param2}
298298
local oldnode_copy = {name=oldnode.name, param1=oldnode.param1, param2=oldnode.param2}
299-
if callback(place_to_copy, newnode_copy, placer, oldnode_copy, itemstack) then
299+
local pointed_thing_copy = {
300+
type = pointed_thing.type,
301+
under = {
302+
x = pointed_thing.under.x,
303+
y = pointed_thing.under.y,
304+
z = pointed_thing.under.z},
305+
above = {
306+
x = pointed_thing.above.x,
307+
y = pointed_thing.above.y,
308+
z = pointed_thing.above.z}
309+
}
310+
if callback(place_to_copy, newnode_copy, placer, oldnode_copy, itemstack, poined_thing_copy) then
300311
take_item = false
301312
end
302313
end

‎doc/lua_api.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ minetest.register_on_shutdown(func())
12021202
^ WARNING: If the server terminates abnormally (i.e. crashes), the registered
12031203
callbacks WILL LIKELY NOT BE RUN. Data should be saved at
12041204
semi-frequent intervals as well as on server shutdown.
1205-
minetest.register_on_placenode(func(pos, newnode, placer, oldnode, itemstack))
1205+
minetest.register_on_placenode(func(pos, newnode, placer, oldnode, itemstack, pointed_thing))
12061206
^ Called when a node has been placed
12071207
^ If return true no item is taken from itemstack
12081208
^ Not recommended; use on_construct or after_place_node in node definition

1 commit comments

Comments
 (1)

qwrwed commented on Jan 22, 2014

@qwrwed

@ShadowNinja: Thanks, but actually it was register_on_punchnode... This may be helpful in mods, but could you add pointed_thing to register_on_punchnode as well?

Please sign in to comment.