diff --git a/lrfurn/init.lua b/lrfurn/init.lua index a54b9233..81a765f6 100644 --- a/lrfurn/init.lua +++ b/lrfurn/init.lua @@ -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") diff --git a/lrfurn/longsofas.lua b/lrfurn/longsofas.lua index f93928f8..bede23ad 100644 --- a/lrfurn/longsofas.lua +++ b/lrfurn/longsofas.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 diff --git a/lrfurn/sofas.lua b/lrfurn/sofas.lua index c423bea7..243078f4 100644 --- a/lrfurn/sofas.lua +++ b/lrfurn/sofas.lua @@ -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