Add pointed_thing to minetest.register_on_placenode
authorShadowNinja <shadowninja@minetest.net>
Wed, 22 Jan 2014 03:05:29 +0000 (22:05 -0500)
committerShadowNinja <shadowninja@minetest.net>
Wed, 22 Jan 2014 03:06:40 +0000 (22:06 -0500)
As suggested by qwrwed.

builtin/item.lua
doc/lua_api.txt

index 8c0c0ed31c2f74d3357319c51e8b8f34089f916e..7a6bb6cf5c1ebb2c67e41205f28f961d427cae8b 100644 (file)
@@ -292,11 +292,22 @@ function minetest.item_place_node(itemstack, placer, pointed_thing, param2)
        -- Run script hook
        local _, callback
        for _, callback in ipairs(minetest.registered_on_placenodes) do
-               -- Copy pos and node because callback can modify them
+               -- Deepcopy pos, node and poined_thing because callback can modify them
                local place_to_copy = {x=place_to.x, y=place_to.y, z=place_to.z}
                local newnode_copy = {name=newnode.name, param1=newnode.param1, param2=newnode.param2}
                local oldnode_copy = {name=oldnode.name, param1=oldnode.param1, param2=oldnode.param2}
-               if callback(place_to_copy, newnode_copy, placer, oldnode_copy, itemstack) then
+               local pointed_thing_copy = {
+                       type = pointed_thing.type,
+                       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 callback(place_to_copy, newnode_copy, placer, oldnode_copy, itemstack, poined_thing_copy) then
                        take_item = false
                end
        end
index 5552b3a310bc399b1c552fb3609f4c1077443ad3..4614ca062d88eb541a05348c805fc1210d969729 100644 (file)
@@ -1202,7 +1202,7 @@ minetest.register_on_shutdown(func())
 ^ WARNING: If the server terminates abnormally (i.e. crashes), the registered
            callbacks WILL LIKELY NOT BE RUN.  Data should be saved at
            semi-frequent intervals as well as on server shutdown.
-minetest.register_on_placenode(func(pos, newnode, placer, oldnode, itemstack))
+minetest.register_on_placenode(func(pos, newnode, placer, oldnode, itemstack, pointed_thing))
 ^ Called when a node has been placed
 ^ If return true no item is taken from itemstack
 ^ Not recommended; use on_construct or after_place_node in node definition