diff --git a/homedecor/tables.lua b/homedecor/tables.lua index 12d0dbf..ac90eec 100644 --- a/homedecor/tables.lua +++ b/homedecor/tables.lua @@ -489,3 +489,110 @@ minetest.register_node('homedecor:utility_table_legs', { }, }) +local function get_nodedef_field(nodename, fieldname) + if not minetest.registered_nodes[nodename] then + return nil + end + return minetest.registered_nodes[nodename][fieldname] +end + +local fdir_to_right = { + { 1, 0 }, + { 0, -1 }, + { -1, 0 }, + { 0, 1 }, +} + +minetest.register_node("homedecor:desk", { + drawtype = "nodebox", + description = "Desk", + tiles = { + "homedecor_desk_top_l.png", + "homedecor_desk_bottom_l.png", + "homedecor_desk_rside_l.png", + "homedecor_desk_lside_l.png", + "homedecor_desk_back_l.png", + "homedecor_desk_front_l.png" + }, + paramtype = "light", + paramtype2 = "facedir", + node_box = { + type = "fixed", + fixed = { + {-0.5, -0.5, -0.4375, 0.375, 0.5, 0.5}, + {-0.5, 0.4375, -0.4375, 0.5, 0.5, 0.5}, + {-0.4375, -0.4375, -0.5, 0.3125, -0.0625, -0.4375}, + {-0.4375, 0, -0.5, 0.3125, 0.375, 0.5}, + {0.3125, -0.375, 0.4375, 0.5, 0.25, 0.5}, + } + }, + selection_box = { + type = "fixed", + fixed = { -0.5, -0.5, -0.5, 1.5, 0.5, 0.5 } + }, + groups = { snappy = 3 }, + on_place = function(itemstack, placer, pointed_thing) + local pos = pointed_thing.under + local pnode = minetest.get_node(pointed_thing.under) + local rnodedef = minetest.registered_nodes[pnode.name] + + if not rnodedef["buildable_to"] then + pos = pointed_thing.above + end + + local fdir = minetest.dir_to_facedir(placer:get_look_dir()) + local pos2 = { x = pos.x + fdir_to_right[fdir+1][1], y=pos.y, z = pos.z + fdir_to_right[fdir+1][2] } + + local tnode = minetest.get_node(pos) + local tnode2 = minetest.get_node(pos2) + + if get_nodedef_field(tnode.name, "buildable_to") + and get_nodedef_field(tnode2.name, "buildable_to") + and not minetest.is_protected(pos, placer:get_player_name()) + and not minetest.is_protected(pos2, placer:get_player_name()) then + minetest.add_node(pos, { name = "homedecor:desk", param2 = fdir }) + minetest.add_node(pos2, { name = "homedecor:desk_r", param2 = fdir }) + if not homedecor.expect_infinite_stacks then + itemstack:take_item() + return itemstack + end + end + end, + after_dig_node = function(pos, oldnode, oldmetadata, digger) + local fdir = oldnode.param2 + local pos2 = { x = pos.x + fdir_to_right[fdir+1][1], y=pos.y, z = pos.z + fdir_to_right[fdir+1][2] } + if minetest.get_node(pos2).name == "homedecor:desk_r" then + minetest.remove_node(pos2) + end + end +}) + +minetest.register_node("homedecor:desk_r", { + drawtype = "nodebox", + tiles = { + "homedecor_desk_top_r.png", + "homedecor_desk_bottom_r.png", + "homedecor_desk_rside_r.png", + "homedecor_desk_lside_r.png", + "homedecor_desk_back_r.png", + "homedecor_desk_front_r.png" + }, + paramtype = "light", + paramtype2 = "facedir", + node_box = { + type = "fixed", + fixed = { + {-0.5, 0.4375, -0.4375, 0.5, 0.5, 0.5}, + {0.375, -0.5, -0.4375, 0.5, 0.5, 0.5}, + {-0.5, 0.3125, -0.4375, 0.5, 0.375, 0.5}, + {-0.5, 0.3125, -0.4375, -0.4375, 0.5, 0.5}, + {-0.5, -0.375, 0.4375, 0.4375, 0.25, 0.5}, + } + }, + selection_box = { + type = "fixed", + fixed = { 0,0,0,0,0,0 } + }, + groups = { snappy = 3, not_in_creative_inventory=1 } +}) + diff --git a/homedecor/textures/homedecor_desk_back_l.png b/homedecor/textures/homedecor_desk_back_l.png new file mode 100644 index 0000000..7e44cea Binary files /dev/null and b/homedecor/textures/homedecor_desk_back_l.png differ diff --git a/homedecor/textures/homedecor_desk_back_r.png b/homedecor/textures/homedecor_desk_back_r.png new file mode 100644 index 0000000..6dffce9 Binary files /dev/null and b/homedecor/textures/homedecor_desk_back_r.png differ diff --git a/homedecor/textures/homedecor_desk_bottom_l.png b/homedecor/textures/homedecor_desk_bottom_l.png new file mode 100644 index 0000000..7e44cea Binary files /dev/null and b/homedecor/textures/homedecor_desk_bottom_l.png differ diff --git a/homedecor/textures/homedecor_desk_bottom_r.png b/homedecor/textures/homedecor_desk_bottom_r.png new file mode 100644 index 0000000..7e44cea Binary files /dev/null and b/homedecor/textures/homedecor_desk_bottom_r.png differ diff --git a/homedecor/textures/homedecor_desk_front_l.png b/homedecor/textures/homedecor_desk_front_l.png new file mode 100644 index 0000000..98c5760 Binary files /dev/null and b/homedecor/textures/homedecor_desk_front_l.png differ diff --git a/homedecor/textures/homedecor_desk_front_r.png b/homedecor/textures/homedecor_desk_front_r.png new file mode 100644 index 0000000..74f2dac Binary files /dev/null and b/homedecor/textures/homedecor_desk_front_r.png differ diff --git a/homedecor/textures/homedecor_desk_lside_l.png b/homedecor/textures/homedecor_desk_lside_l.png new file mode 100644 index 0000000..7e44cea Binary files /dev/null and b/homedecor/textures/homedecor_desk_lside_l.png differ diff --git a/homedecor/textures/homedecor_desk_lside_r.png b/homedecor/textures/homedecor_desk_lside_r.png new file mode 100644 index 0000000..7e44cea Binary files /dev/null and b/homedecor/textures/homedecor_desk_lside_r.png differ diff --git a/homedecor/textures/homedecor_desk_rside_l.png b/homedecor/textures/homedecor_desk_rside_l.png new file mode 100644 index 0000000..7e44cea Binary files /dev/null and b/homedecor/textures/homedecor_desk_rside_l.png differ diff --git a/homedecor/textures/homedecor_desk_rside_r.png b/homedecor/textures/homedecor_desk_rside_r.png new file mode 100644 index 0000000..7e44cea Binary files /dev/null and b/homedecor/textures/homedecor_desk_rside_r.png differ diff --git a/homedecor/textures/homedecor_desk_top_l.png b/homedecor/textures/homedecor_desk_top_l.png new file mode 100644 index 0000000..7e44cea Binary files /dev/null and b/homedecor/textures/homedecor_desk_top_l.png differ diff --git a/homedecor/textures/homedecor_desk_top_r.png b/homedecor/textures/homedecor_desk_top_r.png new file mode 100644 index 0000000..7e44cea Binary files /dev/null and b/homedecor/textures/homedecor_desk_top_r.png differ