Prevent auto-rotated nodes replacing the nodes they are placed on

master
ShadowNinja 2014-01-06 20:31:49 -05:00
parent 78f7f9eca8
commit 811ea6cfc0
1 changed files with 73 additions and 65 deletions

View File

@ -267,36 +267,43 @@ if minetest then
local dirs1 = {9, 18, 7, 12} local dirs1 = {9, 18, 7, 12}
local dirs2 = {20, 23, 22, 21} local dirs2 = {20, 23, 22, 21}
function minetest.rotate_and_place(itemstack, placer, pointed_thing, infinitestacks, orient_flags) function minetest.rotate_and_place(itemstack, placer, pointed_thing,
infinitestacks, orient_flags)
orient_flags = orient_flags or {} orient_flags = orient_flags or {}
local node = minetest.get_node(pointed_thing.under) local unode = minetest.get_node_or_nil(pointed_thing.under)
if not minetest.registered_nodes[node.name] if not unode then
or not minetest.registered_nodes[node.name].on_rightclick then return
end
local undef = minetest.registered_nodes[unode.name]
if undef and undef.on_rightclick then
undef.on_rightclick(pointed_thing.under, node, placer,
itemstack)
return
end
local pitch = placer:get_look_pitch()
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
local wield_name = itemstack:get_name()
local above = pointed_thing.above local above = pointed_thing.above
local under = pointed_thing.under local under = pointed_thing.under
local pitch = placer:get_look_pitch() local iswall = (above.y == under.y)
local pname = minetest.get_node(under).name local isceiling = not iswall and (above.y < under.y)
local node = minetest.get_node(above) local anode = minetest.get_node_or_nil(above)
local fdir = minetest.dir_to_facedir(placer:get_look_dir()) if not anode then
local wield_name = itemstack:get_name() return
local reg_node = minetest.registered_nodes[pname] end
local pos = pointed_thing.above
local node = anode
if not reg_node or not reg_node.on_rightclick then if undef and undef.buildable_to then
pos = pointed_thing.under
local iswall = (above.x ~= under.x) or (above.z ~= under.z) node = unode
local isceiling = (above.x == under.x) and (above.z == under.z)
and (pitch > 0)
local pos1 = above
if reg_node and reg_node.buildable_to then
pos1 = under
iswall = false iswall = false
end end
reg_node = minetest.registered_nodes[minetest.get_node(pos1).name] local ndef = minetest.registered_nodes[node.name]
if not reg_node or not reg_node.buildable_to then if not ndef or not ndef.buildable_to then
return return
end end
@ -314,18 +321,23 @@ if minetest then
end end
if iswall then if iswall then
minetest.add_node(pos1, {name = wield_name, param2 = dirs1[fdir+1] }) minetest.set_node(pos, {name = wield_name,
param2 = dirs1[fdir+1]})
elseif isceiling then elseif isceiling then
if orient_flags.force_facedir then if orient_flags.force_facedir then
minetest.add_node(pos1, {name = wield_name, param2 = 20 }) minetest.set_node(pos, {name = wield_name,
param2 = 20})
else else
minetest.add_node(pos1, {name = wield_name, param2 = dirs2[fdir+1] }) minetest.set_node(pos, {name = wield_name,
param2 = dirs2[fdir+1]})
end end
else -- place right side up else -- place right side up
if orient_flags.force_facedir then if orient_flags.force_facedir then
minetest.add_node(pos1, {name = wield_name, param2 = 0 }) minetest.set_node(pos, {name = wield_name,
param2 = 0})
else else
minetest.add_node(pos1, {name = wield_name, param2 = fdir }) minetest.set_node(pos, {name = wield_name,
param2 = fdir})
end end
end end
@ -334,10 +346,6 @@ if minetest then
return itemstack return itemstack
end end
end end
else
minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack)
end
end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------