mirror of
https://github.com/mt-mods/homedecor_modpack.git
synced 2024-12-23 00:20:17 +01:00
add free-space checking for sofas
This commit is contained in:
parent
2b5d07470a
commit
9a32904b97
@ -1,3 +1,32 @@
|
||||
-- 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
|
||||
|
Loading…
Reference in New Issue
Block a user