forked from mtcontrib/homedecor_modpack
fix right click oddities of expansion nodes and make sure to always return the leftover itemstack
This commit is contained in:
parent
20f5afb624
commit
d5fbfbf305
@ -41,7 +41,7 @@ local function select_node(pointed_thing)
|
|||||||
local pos = pointed_thing.under
|
local pos = pointed_thing.under
|
||||||
local def = minetest.registered_nodes[minetest.get_node(pos).name]
|
local def = minetest.registered_nodes[minetest.get_node(pos).name]
|
||||||
|
|
||||||
if not def or (not def.on_rightclick and not def.buildable_to) then
|
if not def or not def.buildable_to then
|
||||||
pos = pointed_thing.above
|
pos = pointed_thing.above
|
||||||
def = minetest.registered_nodes[minetest.get_node(pos).name]
|
def = minetest.registered_nodes[minetest.get_node(pos).name]
|
||||||
end
|
end
|
||||||
@ -81,20 +81,27 @@ local function stack(itemstack, placer, fdir, pos, def, pos2, node1, node2)
|
|||||||
|
|
||||||
if not homedecor.expect_infinite_stacks then
|
if not homedecor.expect_infinite_stacks then
|
||||||
itemstack:take_item()
|
itemstack:take_item()
|
||||||
return itemstack
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
|
||||||
|
local function rightclick_pointed_thing(pos, placer, itemstack)
|
||||||
|
local node = minetest.get_node_or_nil(pos)
|
||||||
|
if not node then return false end
|
||||||
|
local def = minetest.registered_nodes[node.name]
|
||||||
|
if not def or not def.on_rightclick then return false end
|
||||||
|
return def.on_rightclick(pos, node, placer, itemstack) or itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Stack one node above another
|
-- Stack one node above another
|
||||||
-- leave the last argument nil if it's one 2m high node
|
-- leave the last argument nil if it's one 2m high node
|
||||||
function homedecor.stack_vertically(itemstack, placer, pointed_thing, node1, node2)
|
function homedecor.stack_vertically(itemstack, placer, pointed_thing, node1, node2)
|
||||||
local pos, def = select_node(pointed_thing)
|
local rightclick_result = rightclick_pointed_thing(pointed_thing.under, placer, itemstack)
|
||||||
if not def then return end -- rare corner case, but happened in #205
|
if rightclick_result then return rightclick_result end
|
||||||
|
|
||||||
if def.on_rightclick then
|
local pos, def = select_node(pointed_thing)
|
||||||
return def.on_rightclick(pointed_thing.under, minetest.get_node(pos), placer, itemstack)
|
if not def then return itemstack end -- rare corner case, but happened in #205
|
||||||
end
|
|
||||||
|
|
||||||
local top_pos = { x=pos.x, y=pos.y+1, z=pos.z }
|
local top_pos = { x=pos.x, y=pos.y+1, z=pos.z }
|
||||||
|
|
||||||
@ -105,12 +112,11 @@ end
|
|||||||
-- like homedecor.stack_vertically but tests first if it was placed as a right wing, then uses node1_right and node2_right instead
|
-- like homedecor.stack_vertically but tests first if it was placed as a right wing, then uses node1_right and node2_right instead
|
||||||
|
|
||||||
function homedecor.stack_wing(itemstack, placer, pointed_thing, node1, node2, node1_right, node2_right)
|
function homedecor.stack_wing(itemstack, placer, pointed_thing, node1, node2, node1_right, node2_right)
|
||||||
local pos, def = select_node(pointed_thing)
|
local rightclick_result = rightclick_pointed_thing(pointed_thing.under, placer, itemstack)
|
||||||
if not def then return end -- rare corner case, but happened in #205
|
if rightclick_result then return rightclick_result end
|
||||||
|
|
||||||
if def.on_rightclick then
|
local pos, def = select_node(pointed_thing)
|
||||||
return def.on_rightclick(pointed_thing.under, minetest.get_node(pos), placer, itemstack)
|
if not def then return itemstack end -- rare corner case, but happened in #205
|
||||||
end
|
|
||||||
|
|
||||||
local forceright = placer:get_player_control()["sneak"]
|
local forceright = placer:get_player_control()["sneak"]
|
||||||
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
|
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
|
||||||
@ -125,12 +131,11 @@ function homedecor.stack_wing(itemstack, placer, pointed_thing, node1, node2, no
|
|||||||
end
|
end
|
||||||
|
|
||||||
function homedecor.stack_sideways(itemstack, placer, pointed_thing, node1, node2, dir)
|
function homedecor.stack_sideways(itemstack, placer, pointed_thing, node1, node2, dir)
|
||||||
local pos, def = select_node(pointed_thing)
|
local rightclick_result = rightclick_pointed_thing(pointed_thing.under, placer, itemstack)
|
||||||
if not def then return end -- rare corner case, but happened in #205
|
if rightclick_result then return rightclick_result end
|
||||||
|
|
||||||
if def.on_rightclick then
|
local pos, def = select_node(pointed_thing)
|
||||||
return def.on_rightclick(pointed_thing.under, minetest.get_node(pos), placer, itemstack)
|
if not def then return itemstack end -- rare corner case, but happened in #205
|
||||||
end
|
|
||||||
|
|
||||||
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
|
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
|
||||||
local fdir_transform = dir and homedecor.fdir_to_right or homedecor.fdir_to_fwd
|
local fdir_transform = dir and homedecor.fdir_to_right or homedecor.fdir_to_fwd
|
||||||
@ -215,11 +220,10 @@ function homedecor.unextend_bed(pos, color)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function homedecor.place_banister(itemstack, placer, pointed_thing)
|
function homedecor.place_banister(itemstack, placer, pointed_thing)
|
||||||
local pos, def = select_node(pointed_thing)
|
local rightclick_result = rightclick_pointed_thing(pointed_thing.under, placer, itemstack)
|
||||||
|
if rightclick_result then return rightclick_result end
|
||||||
|
|
||||||
if def.on_rightclick then
|
local pos, def = select_node(pointed_thing)
|
||||||
return def.on_rightclick(pointed_thing.under, minetest.get_node(pos), placer, itemstack)
|
|
||||||
end
|
|
||||||
|
|
||||||
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
|
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
|
||||||
|
|
||||||
@ -231,12 +235,12 @@ function homedecor.place_banister(itemstack, placer, pointed_thing)
|
|||||||
|
|
||||||
if not (adef and adef.buildable_to) then
|
if not (adef and adef.buildable_to) then
|
||||||
minetest.chat_send_player(placer_name, "Not enough room - the upper space is occupied!" )
|
minetest.chat_send_player(placer_name, "Not enough room - the upper space is occupied!" )
|
||||||
return
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
if minetest.is_protected(abovepos, placer_name) then
|
if minetest.is_protected(abovepos, placer_name) then
|
||||||
minetest.chat_send_player(placer_name, "Someone already owns that spot." )
|
minetest.chat_send_player(placer_name, "Someone already owns that spot." )
|
||||||
return
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
local lxd = homedecor.fdir_to_left[fdir+1][1]
|
local lxd = homedecor.fdir_to_left[fdir+1][1]
|
||||||
|
Loading…
Reference in New Issue
Block a user