From 06342cbd867549eaedf02258642a12e4dc1b84b3 Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Wed, 22 Feb 2017 16:38:19 -0500 Subject: [PATCH] make sofas and coffee table place with long axis left-to-right (e.g. front of sofa faces you) --- lrfurn/coffeetable.lua | 112 ++++++++++++++--------------------------- lrfurn/init.lua | 18 +++++-- lrfurn/longsofas.lua | 4 +- lrfurn/sofas.lua | 4 +- 4 files changed, 56 insertions(+), 82 deletions(-) diff --git a/lrfurn/coffeetable.lua b/lrfurn/coffeetable.lua index 506a5bf9..399d9400 100644 --- a/lrfurn/coffeetable.lua +++ b/lrfurn/coffeetable.lua @@ -1,7 +1,36 @@ local S = homedecor_i18n.gettext -minetest.register_node("lrfurn:coffeetable_back", { +--[[ + local node = minetest.get_node(pos) + local yaw = placer:get_look_yaw() + local dir = minetest.yaw_to_dir(yaw-1.5) + local fdir = minetest.dir_to_facedir(dir) + + print(placer:get_look_yaw(), yaw) + print(node.param2, fdir) + + if lrfurn.check_right(pos, fdir, false, placer) then + local pos2 = find_coffee_table_second_node(pos, fdir) +]]-- + +local function find_second_node(pos, param2) + if param2 == 0 then + pos.z = pos.z+1 + elseif param2 == 1 then + pos.x = pos.x+1 + elseif param2 == 2 then + pos.z = pos.z-1 + elseif param2 == 3 then + pos.x = pos.x-1 + end + return pos +end + +minetest.register_alias("lrfurn:coffeetable_back", "lrfurn:coffeetable") +minetest.register_alias("lrfurn:coffeetable_front", "air") + +minetest.register_node("lrfurn:coffeetable", { description = S("Coffee Table"), drawtype = "nodebox", tiles = {"lrfurn_coffeetable_back.png", "lrfurn_coffeetable_back.png", "lrfurn_coffeetable_back.png", "lrfurn_coffeetable_back.png", "lrfurn_coffeetable_back.png", "lrfurn_coffeetable_back.png"}, @@ -13,11 +42,12 @@ minetest.register_node("lrfurn:coffeetable_back", { type = "fixed", fixed = { --legs - {-0.375, -0.5, -0.375, -0.3125, -0.0625, -0.3125}, - {0.3125, -0.5, -0.375, 0.375, -0.0625, -0.3125}, - + { -0.375, -0.5, -0.375, -0.3125, -0.0625, -0.3125 }, + { 0.3125, -0.5, -0.375, 0.375, -0.0625, -0.3125 }, + { -0.375, -0.5, 1.3125, -0.3125, -0.0625, 1.375 }, + { 0.3125, -0.5, 1.3125, 0.375, -0.0625, 1.375 }, --tabletop - {-0.4375, -0.0625, -0.4375, 0.4375, 0, 0.5}, + {-0.4375, -0.0625, -0.4375, 0.4375, 0, 1.4375}, } }, selection_box = { @@ -30,83 +60,19 @@ minetest.register_node("lrfurn:coffeetable_back", { after_place_node = function(pos, placer, itemstack, pointed_thing) if minetest.is_protected(pos, placer:get_player_name()) then return true end local node = minetest.get_node(pos) - local param2 = node.param2 + local fdir = node.param2 - local fdir = minetest.dir_to_facedir(placer:get_look_dir(), false) - - if lrfurn.check_forward(pos, fdir, false, placer) then - - node.name = "lrfurn:coffeetable_front" - if param2 == 0 then - pos.z = pos.z+1 - elseif param2 == 1 then - pos.x = pos.x+1 - elseif param2 == 2 then - pos.z = pos.z-1 - elseif param2 == 3 then - pos.x = pos.x-1 - end - minetest.set_node(pos, node) + if lrfurn.check_right(pos, fdir, false, placer) then + minetest.set_node(pos, { name = node.name, param2 = (fdir + 1) % 4 }) else minetest.chat_send_player(placer:get_player_name(), - S("No room to place the coffee table!")) + S("No room to place the coffee table!")) minetest.set_node(pos, {name = "air"}) return true end - - end, - - after_dig_node = function(pos, oldnode, oldmetadata, digger) - if minetest.is_protected(pos, digger:get_player_name()) then return true end - - local param2 = oldnode.param2 - if param2 == 0 then - pos.z = pos.z+1 - elseif param2 == 1 then - pos.x = pos.x+1 - elseif param2 == 2 then - pos.z = pos.z-1 - elseif param2 == 3 then - pos.x = pos.x-1 - end - - if minetest.is_protected(pos, digger:get_player_name()) then return true end - - if (minetest.get_node({x=pos.x, y=pos.y, z=pos.z}).name == "lrfurn:coffeetable_front") - and (minetest.get_node({x=pos.x, y=pos.y, z=pos.z}).param2 == param2) then - minetest.remove_node(pos) - end end, }) -minetest.register_node("lrfurn:coffeetable_front", { - drawtype = "nodebox", - tiles = {"lrfurn_coffeetable_front.png", "lrfurn_coffeetable_front.png", "lrfurn_coffeetable_front.png", "lrfurn_coffeetable_front.png", "lrfurn_coffeetable_front.png", "lrfurn_coffeetable_front.png"}, - paramtype = "light", - paramtype2 = "facedir", - groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3}, - sounds = default.node_sound_wood_defaults(), - node_box = { - type = "fixed", - fixed = { - --legs - {-0.375, -0.5, 0.3125, -0.3125, -0.0625, 0.375}, - {0.3125, -0.5, 0.3125, 0.375, -0.0625, 0.375}, - - --tabletop - {-0.4375, -0.0625, -0.5, 0.4375, 0, 0.4375}, - } - }, - selection_box = { - type = "fixed", - fixed = { - {0, 0, 0, 0, 0, 0}, - } - }, -}) - -minetest.register_alias("lrfurn:coffeetable", "lrfurn:coffeetable_back") - minetest.register_craft({ output = "lrfurn:coffeetable", recipe = { diff --git a/lrfurn/init.lua b/lrfurn/init.lua index b529b632..e8b234ae 100644 --- a/lrfurn/init.lua +++ b/lrfurn/init.lua @@ -2,11 +2,11 @@ lrfurn = {} screwdriver = screwdriver or {} -lrfurn.fdir_to_fwd = { - { 0, 1 }, +lrfurn.fdir_to_right = { { 1, 0 }, { 0, -1 }, { -1, 0 }, + { 0, 1 }, } lrfurn.colors = { @@ -27,11 +27,11 @@ lrfurn.colors = { "yellow", } -function lrfurn.check_forward(pos, fdir, long, placer) +function lrfurn.check_right(pos, fdir, long, placer) 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 pos2 = { x = pos.x + lrfurn.fdir_to_right[fdir+1][1], y=pos.y, z = pos.z + lrfurn.fdir_to_right[fdir+1][2] } + local pos3 = { x = pos.x + lrfurn.fdir_to_right[fdir+1][1] * 2, y=pos.y, z = pos.z + lrfurn.fdir_to_right[fdir+1][2] * 2 } local node2 = minetest.get_node(pos2) if node2 and node2.name ~= "air" then @@ -58,6 +58,14 @@ function lrfurn.check_forward(pos, fdir, long, placer) return true end +function lrfurn.fix_sofa_rotation_nsew(pos, placer, itemstack, pointed_thing) + local node = minetest.get_node(pos) + local yaw = placer:get_look_yaw() + local dir = minetest.yaw_to_dir(yaw-1.5) + local fdir = minetest.dir_to_wallmounted(dir) + minetest.swap_node(pos, { name = node.name, param2 = fdir }) +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 f08da4e9..f24be051 100644 --- a/lrfurn/longsofas.lua +++ b/lrfurn/longsofas.lua @@ -24,13 +24,13 @@ minetest.register_node("lrfurn:longsofa", { node_box = longsofa_cbox, on_rotate = screwdriver.disallow, after_place_node = function(pos, placer, itemstack, pointed_thing) - unifieddyes.fix_rotation_nsew(pos, placer, itemstack, pointed_thing) + lrfurn.fix_sofa_rotation_nsew(pos, placer, itemstack, pointed_thing) local playername = placer:get_player_name() if minetest.is_protected(pos, placer:get_player_name()) then return true end local fdir = minetest.dir_to_facedir(placer:get_look_dir(), false) - if lrfurn.check_forward(pos, fdir, true, placer) then + if lrfurn.check_right(pos, fdir, true, placer) then if not creative.is_enabled_for(playername) then itemstack:take_item() end diff --git a/lrfurn/sofas.lua b/lrfurn/sofas.lua index 12c70fa6..16d246fd 100644 --- a/lrfurn/sofas.lua +++ b/lrfurn/sofas.lua @@ -24,13 +24,13 @@ minetest.register_node("lrfurn:sofa", { node_box = sofa_cbox, on_rotate = screwdriver.disallow, after_place_node = function(pos, placer, itemstack, pointed_thing) - unifieddyes.fix_rotation_nsew(pos, placer, itemstack, pointed_thing) + lrfurn.fix_sofa_rotation_nsew(pos, placer, itemstack, pointed_thing) local playername = placer:get_player_name() if minetest.is_protected(pos, placer:get_player_name()) then return true end local fdir = minetest.dir_to_facedir(placer:get_look_dir(), false) - if lrfurn.check_forward(pos, fdir, false, placer) then + if lrfurn.check_right(pos, fdir, false, placer) then if not creative.is_enabled_for(playername) then itemstack:take_item() end