aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorPilzAdam <adam-k@outlook.com>2012-12-17 19:49:18 +0100
committerPilzAdam <adam-k@outlook.com>2012-12-17 19:49:18 +0100
commit29c17c14f1ef42f8080a44b1e3308f34de8b5df2 (patch)
treec62289a707f2311e70fd72aad70d2cf8e01286f8 /builtin
parentf4ed37ec6f1d24c2da3dab14b3478d3b0452d7aa (diff)
downloadminetest-29c17c14f1ef42f8080a44b1e3308f34de8b5df2.tar.gz
minetest-29c17c14f1ef42f8080a44b1e3308f34de8b5df2.tar.bz2
minetest-29c17c14f1ef42f8080a44b1e3308f34de8b5df2.zip
Add ability to change the itemstack in placenode callbacks
Diffstat (limited to 'builtin')
-rw-r--r--builtin/item.lua14
1 files changed, 11 insertions, 3 deletions
diff --git a/builtin/item.lua b/builtin/item.lua
index 80c665c99..acc1e6262 100644
--- a/builtin/item.lua
+++ b/builtin/item.lua
@@ -192,11 +192,15 @@ function minetest.item_place_node(itemstack, placer, pointed_thing)
-- Add node and update
minetest.env:add_node(place_to, newnode)
+ local take_item = true
+
-- Run callback
if def.after_place_node then
-- Copy place_to because callback can modify it
local place_to_copy = {x=place_to.x, y=place_to.y, z=place_to.z}
- def.after_place_node(place_to_copy, placer)
+ if def.after_place_node(place_to_copy, placer, itemstack) then
+ take_item = false
+ end
end
-- Run script hook
@@ -206,10 +210,14 @@ function minetest.item_place_node(itemstack, placer, pointed_thing)
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}
- callback(place_to_copy, newnode_copy, placer, oldnode_copy)
+ if callback(place_to_copy, newnode_copy, placer, oldnode_copy, itemstack) then
+ take_item = false
+ end
end
- itemstack:take_item()
+ if take_item then
+ itemstack:take_item()
+ end
return itemstack
end