1
0
mirror of https://github.com/mt-mods/homedecor_modpack.git synced 2024-12-23 00:20:17 +01:00

make sofas and coffee table place with long axis left-to-right

(e.g. front of sofa faces you)
This commit is contained in:
Vanessa Ezekowitz 2017-02-22 16:38:19 -05:00
parent f32fdad4ff
commit 06342cbd86
4 changed files with 56 additions and 82 deletions

View File

@ -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!"))
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 = {

View File

@ -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")

View File

@ -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

View File

@ -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