Skip to content
Snippets Groups Projects
Commit 9a32904b authored by Vanessa Ezekowitz's avatar Vanessa Ezekowitz
Browse files

add free-space checking for sofas

parent 2b5d0747
No related branches found
No related tags found
No related merge requests found
-- LRfurn mod by thefamilygrog66
lrfurn = {}
lrfurn.fdir_to_fwd = {
{ 0, 1 },
{ 1, 0 },
{ 0, -1 },
{ -1, 0 },
}
function lrfurn.check_forward(pos, fdir, long)
if not fdir or fdir > 3 then fdir = 0 end
local pos2 = { x = pos.x + lrfurn.fdir_to_fwd[fdir+1][1], y=pos.y, z = pos.z + lrfurn.fdir_to_fwd[fdir+1][2] }
local pos3 = { x = pos.x + lrfurn.fdir_to_fwd[fdir+1][1] * 2, y=pos.y, z = pos.z + lrfurn.fdir_to_fwd[fdir+1][2] * 2 }
local node2 = minetest.get_node(pos2)
if node2 and node2.name ~= "air" then return false end
if long then
local node3 = minetest.get_node(pos3)
if node3 and node3.name ~= "air" then return false end
end
return true
end
dofile(minetest.get_modpath("lrfurn").."/longsofas.lua")
dofile(minetest.get_modpath("lrfurn").."/sofas.lua")
dofile(minetest.get_modpath("lrfurn").."/armchairs.lua")
......
......@@ -32,6 +32,18 @@ for i in ipairs(longsofas_list) do
{-0.5, -0.5, -0.5, 0.5, 0.5, 2.5},
}
},
on_place = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.above
local fdir = minetest.dir_to_facedir(placer:get_look_dir(), false)
if lrfurn.check_forward(pos, fdir, true) then
minetest.set_node(pos, {name = "lrfurn:longsofa_"..colour, param2 = fdir})
itemstack:take_item()
else
minetest.chat_send_player(placer:get_player_name(), "No room to place the sofa!")
end
return itemstack
end,
on_rightclick = function(pos, node, clicker)
if not clicker:is_player() then
return
......
......@@ -29,10 +29,21 @@ for i in ipairs(sofas_list) do
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0.5, 1.5},
}
{-0.5, -0.5, -0.5, 0.5, 0.5, 1.5},
}
},
on_place = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.above
local fdir = minetest.dir_to_facedir(placer:get_look_dir(), false)
if lrfurn.check_forward(pos, fdir, true) then
minetest.set_node(pos, {name = "lrfurn:sofa_"..colour, param2 = fdir})
itemstack:take_item()
else
minetest.chat_send_player(placer:get_player_name(), "No room to place the sofa!")
end
return itemstack
end,
on_rightclick = function(pos, node, clicker)
if not clicker:is_player() then
return
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment