aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorPilzAdam <pilzadam@minetest.net>2013-09-11 16:32:05 +0200
committerPilzAdam <pilzadam@minetest.net>2013-09-28 23:46:48 +0200
commit731392866f3f2595a08ca279b1d39584f6783ec0 (patch)
tree2a0fbe082061c80f1b1430a564282063e3616194 /builtin
parent5dce44ec5e5f7231dba3cdbec3f1fdc683ce5a34 (diff)
downloadminetest-731392866f3f2595a08ca279b1d39584f6783ec0.tar.gz
minetest-731392866f3f2595a08ca279b1d39584f6783ec0.tar.bz2
minetest-731392866f3f2595a08ca279b1d39584f6783ec0.zip
Allow to manually specify param2 in minetest.item_place() and return success
Diffstat (limited to 'builtin')
-rw-r--r--builtin/item.lua24
1 files changed, 12 insertions, 12 deletions
diff --git a/builtin/item.lua b/builtin/item.lua
index 6a01f37f6..5f3c71770 100644
--- a/builtin/item.lua
+++ b/builtin/item.lua
@@ -179,11 +179,11 @@ function minetest.get_node_drops(nodename, toolname)
return got_items
end
-function minetest.item_place_node(itemstack, placer, pointed_thing)
+function minetest.item_place_node(itemstack, placer, pointed_thing, param2)
local item = itemstack:peek_item()
local def = itemstack:get_definition()
if def.type ~= "node" or pointed_thing.type ~= "node" then
- return itemstack
+ return itemstack, false
end
local under = pointed_thing.under
@@ -194,7 +194,7 @@ function minetest.item_place_node(itemstack, placer, pointed_thing)
if not oldnode_under or not oldnode_above then
minetest.log("info", placer:get_player_name() .. " tried to place"
.. " node in unloaded position " .. minetest.pos_to_string(above))
- return itemstack
+ return itemstack, false
end
local olddef_under = ItemStack({name=oldnode_under.name}):get_definition()
@@ -206,7 +206,7 @@ function minetest.item_place_node(itemstack, placer, pointed_thing)
minetest.log("info", placer:get_player_name() .. " tried to place"
.. " node in invalid position " .. minetest.pos_to_string(above)
.. ", replacing " .. oldnode_above.name)
- return itemstack
+ return itemstack, false
end
-- Place above pointed node
@@ -222,10 +222,10 @@ function minetest.item_place_node(itemstack, placer, pointed_thing)
.. def.name .. " at " .. minetest.pos_to_string(place_to))
local oldnode = minetest.get_node(place_to)
- local newnode = {name = def.name, param1 = 0, param2 = 0}
+ local newnode = {name = def.name, param1 = 0, param2 = param2}
-- Calculate direction for wall mounted stuff like torches and signs
- if def.paramtype2 == 'wallmounted' then
+ if def.paramtype2 == 'wallmounted' and not param2 then
local dir = {
x = under.x - above.x,
y = under.y - above.y,
@@ -233,7 +233,7 @@ function minetest.item_place_node(itemstack, placer, pointed_thing)
}
newnode.param2 = minetest.dir_to_wallmounted(dir)
-- Calculate the direction for furnaces and chests and stuff
- elseif def.paramtype2 == 'facedir' then
+ elseif def.paramtype2 == 'facedir' and not param2 then
local placer_pos = placer:getpos()
if placer_pos then
local dir = {
@@ -251,7 +251,7 @@ function minetest.item_place_node(itemstack, placer, pointed_thing)
not check_attached_node(place_to, newnode) then
minetest.log("action", "attached node " .. def.name ..
" can not be placed at " .. minetest.pos_to_string(place_to))
- return itemstack
+ return itemstack, false
end
-- Add node and update
@@ -283,7 +283,7 @@ function minetest.item_place_node(itemstack, placer, pointed_thing)
if take_item then
itemstack:take_item()
end
- return itemstack
+ return itemstack, true
end
function minetest.item_place_object(itemstack, placer, pointed_thing)
@@ -295,19 +295,19 @@ function minetest.item_place_object(itemstack, placer, pointed_thing)
return itemstack
end
-function minetest.item_place(itemstack, placer, pointed_thing)
+function minetest.item_place(itemstack, placer, pointed_thing, param2)
-- Call on_rightclick if the pointed node defines it
if pointed_thing.type == "node" and placer and
not placer:get_player_control().sneak then
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
+ return minetest.registered_nodes[nn].on_rightclick(pointed_thing.under, n, placer, itemstack) or itemstack, false
end
end
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, param2)
end
return itemstack
end