diff --git a/decor_api/common_helpers.lua b/decor_api/common_helpers.lua index a97a10b..6060be2 100644 --- a/decor_api/common_helpers.lua +++ b/decor_api/common_helpers.lua @@ -9,6 +9,7 @@ function helpers.get_dir(pos) local dir = def.paramtype2 == "facedir" and vector.copy(minetest.facedir_to_dir(node.param2)) or def.paramtype2 == "wallmounted" and vector.copy(minetest.wallmounted_to_dir(node.param2)) dir = dir*-1 + return dir end diff --git a/decor_api/connecting.lua b/decor_api/connecting.lua index 392fc32..00e533c 100644 --- a/decor_api/connecting.lua +++ b/decor_api/connecting.lua @@ -30,11 +30,10 @@ function connecting.replace_node_to(pos, disconnect) local add_props = minetest.registered_nodes[node_name].add_properties local modname = node_name:find("multidecor:") - --minetest.debug("3") if not modname or not add_props or not add_props.common_name then return end - --minetest.debug("4") + local target_node = "" local rel_rot = 0 @@ -42,12 +41,12 @@ function connecting.replace_node_to(pos, disconnect) target_node = "edge" rel_rot = 180 end - --minetest.debug("5") + if connecting.are_nodes_identical(ord_shifts[2], pos) then target_node = target_node == "edge" and "corner" or "edge" rel_rot = 90 end - --minetest.debug("6") + if connecting.are_nodes_identical(ord_shifts[3], pos) then if target_node == "corner" then target_node = "edge_middle" @@ -58,7 +57,7 @@ function connecting.replace_node_to(pos, disconnect) end rel_rot = 0 end - --minetest.debug("7") + if connecting.are_nodes_identical(ord_shifts[4], pos) then if target_node == "edge_middle" then target_node = "off_edge" @@ -66,15 +65,6 @@ function connecting.replace_node_to(pos, disconnect) elseif target_node == "edge" then target_node = (rel_rot == 180 or rel_rot == 0) and "corner" or "middle" rel_rot = rel_rot == 0 and -90 or rel_rot - --[[if rel_rot == 180 then - target_node = "corner" - rel_rot = 180 - elseif rel_rot == 90 then - target_node = "middle" - rel_rot = 90 - else - target_node = "corner" - rel_rot = -90]] elseif target_node == "corner" then target_node = "edge_middle" rel_rot = rel_rot == 0 and -90 or rel_rot @@ -86,27 +76,92 @@ function connecting.replace_node_to(pos, disconnect) rel_rot = -90 end end - target_node = target_node ~= "" and "_" .. target_node or "" minetest.debug("target_node: " .. target_node) + target_node = target_node ~= "" and "_" .. target_node or "" if not disconnect and target_node == "" then return end local param2 = minetest.dir_to_facedir(vector.rotate_around_axis({x=0, y=0, z=1}, {x=0, y=1, z=0}, math.rad(rel_rot))*-1) - --minetest.debug("8") - --minetest.debug("name:" .. dump(minetest.registered_nodes["multidecor:" .. add_props.common_name .. "_" .. target_node])) minetest.set_node(pos, {name="multidecor:" .. add_props.common_name .. target_node, param2=param2}) - --minetest.debug("9") +end + +function connecting.directional_replace_node_to(pos, dir, side, disconnect) + local node = minetest.get_node(pos) + local def = minetest.registered_nodes[node.name] + local add_props = def.add_properties + + local modname = node.name:find("multidecor:") + + if not modname or not add_props or not add_props.common_name then + return + end + + local left_dir + local right_dir + + local dir_rot = math.deg(vector.dir_to_rotation(dir).y) + local dir_rot2 = math.deg(vector.dir_to_rotation(helpers.get_dir(pos)).y) + + minetest.debug("side: " .. dump(side)) + minetest.debug("dir_rot: " .. dir_rot) + minetest.debug("dir_rot2: " .. dir_rot2) + local is_left_corner = add_props.connect_parts.left_side == def.mesh and side == "right" and + dir_rot-math.pi/2 == dir_rot2 + local is_right_corner = add_props.connect_parts.right_side == def.mesh and side == "left" and + dir_rot+math.pi/2 == dir_rot2 + if is_left_corner then + --minetest.debug("left corner") + right_dir = dir + elseif is_right_corner then + --minetest.debug("right corner") + left_dir = dir + end + + left_dir = left_dir or vector.rotate_around_axis(dir, {x=0, y=1, z=0}, -math.pi/2) + right_dir = right_dir or vector.rotate_around_axis(dir, {x=0, y=1, z=0}, math.pi/2) + + local left_pos = pos+left_dir + local right_pos = pos+right_dir + + local target_node = "" + local rel_rot = 0 + + if connecting.are_nodes_identical(left_pos, pos) then + if is_left_corner then + target_node = "corner" + rel_rot = -math.pi/2 + else + target_node = "right_side" + end + end + + if connecting.are_nodes_identical(right_pos, pos) then + if target_node == "" then + target_node = "left_side" + elseif target_node == "right_side" then + target_node = "middle" + elseif is_right_corner then + target_node = "corner" + end + end + minetest.debug("target_node: " .. target_node) + target_node = target_node ~= "" and "_" .. target_node or "" + + if not disconnect and target_node == "" then + return + end + local param2 = minetest.dir_to_facedir(vector.rotate_around_axis(dir, {x=0, y=1, z=0}, rel_rot)*-1) + minetest.set_node(pos, {name="multidecor:" .. add_props.common_name .. target_node, param2=param2}) end -- Connects or disconnects adjacent nodes around 'pos' position. -- If the identical table node was set at 'pos' as surrounding, connect them. On destroying it, disconnect. -- *type* can be "horizontal", "vertical", "pair", "sofa" function connecting.update_adjacent_nodes_connection(pos, type, disconnect, old_node) + local node = minetest.get_node(pos) + minetest.debug("update_adjacent_nodes_connection()") if not disconnect then - --minetest.debug("1") - - local node = minetest.get_node(pos) local add_props = minetest.registered_nodes[node.name].add_properties local modname = node.name:find("multidecor:") local cmn_name = add_props and add_props.common_name @@ -114,7 +169,6 @@ function connecting.update_adjacent_nodes_connection(pos, type, disconnect, old_ if not modname or not cmn_name then return end - --minetest.debug("2") end if type == "horizontal" then @@ -134,10 +188,9 @@ function connecting.update_adjacent_nodes_connection(pos, type, disconnect, old_ end elseif type == "pair" then if not disconnect then - local node = minetest.get_node(pos) - local dir = minetest.facedir_to_dir(node.param2) - local left = pos+vector.rotate_around_axis(dir, {x=0, y=1, z=0}, math.pi/2) - local right = pos+vector.rotate_around_axis(dir, {x=0, y=1, z=0}, -math.pi/2) + local dir = helpers.get_dir(pos) + local left = pos+vector.rotate_around_axis(dir, {x=0, y=1, z=0}, -math.pi/2) + local right = pos+vector.rotate_around_axis(dir, {x=0, y=1, z=0}, math.pi/2) local lnode = minetest.get_node(left) local rnode = minetest.get_node(right) @@ -155,14 +208,31 @@ function connecting.update_adjacent_nodes_connection(pos, type, disconnect, old_ return end - minetest.set_node(place_pos, {name="multidecor:" .. add_props.common_name .. "_double", param2=minetest.dir_to_facedir(dir)}) - minetest.remove_node(place_pos+vector.rotate_around_axis(dir, {x=0, y=1, z=0}, -math.pi/2)) + minetest.set_node(place_pos, {name="multidecor:" .. add_props.common_name .. "_double", param2=minetest.dir_to_facedir(dir*-1)}) + minetest.remove_node(place_pos+vector.rotate_around_axis(dir, {x=0, y=1, z=0}, math.pi/2)) else local dir = minetest.facedir_to_dir(old_node.param2) local right = pos+vector.rotate_around_axis(dir, {x=0, y=1, z=0}, -math.pi/2) local add_props = minetest.registered_nodes[old_node.name].add_properties minetest.set_node(right, {name="multidecor:" .. add_props.common_name, param2=minetest.dir_to_facedir(dir)}) end + elseif type == "directional" then + local dir + + if disconnect then + dir = minetest.facedir_to_dir(old_node.param2)*-1 + else + dir = helpers.get_dir(pos) + end + local left = pos+vector.rotate_around_axis(dir, {x=0, y=1, z=0}, -math.pi/2) + local right = pos+vector.rotate_around_axis(dir, {x=0, y=1, z=0}, math.pi/2) + + connecting.directional_replace_node_to(left, dir, "left", disconnect) + connecting.directional_replace_node_to(right, dir, "right", disconnect) + + if not disconnect then + connecting.directional_replace_node_to(pos, dir, nil) + end end end @@ -178,15 +248,8 @@ function connecting.register_connect_parts(def) c_def.groups = {not_in_creative_inventory=1} end - for cb_name, _ in pairs(c_def.callbacks) do - if cb_name ~= "after_destruct" and cb_name ~= "after_dig_node" then - c_def[cb_name] = nil - end - end - - c_def.callbacks = nil + c_def.callbacks.on_construct = nil register.register_furniture_unit(def.add_properties.common_name .. "_" .. name, c_def) - --minetest.register_node(":multidecor:" .. def.add_properties.common_name .. "_" .. name, c_def) end end diff --git a/decor_api/seat.lua b/decor_api/seat.lua index 5f916f6..b74c9e8 100644 --- a/decor_api/seat.lua +++ b/decor_api/seat.lua @@ -57,4 +57,8 @@ function register.register_seat(name, base_def, add_def, craft_def) end register.register_furniture_unit(name, def, craft_def) + + if def.add_properties and def.add_properties.connect_parts then + connecting.register_connect_parts(def) + end end diff --git a/decor_api/sitting.lua b/decor_api/sitting.lua index 8306921..08fedd1 100644 --- a/decor_api/sitting.lua +++ b/decor_api/sitting.lua @@ -27,12 +27,11 @@ end function sitting.detach_player_from_node(detacher, prev_pdata) if not prev_pdata then - minetest.debug("3") return end - minetest.debug("prev_pdata.physics: " .. dump(prev_pdata.physics)) + detacher:set_physics_override(prev_pdata.physics) - + if prev_pdata.mesh and prev_pdata.anim then detacher:set_properties({mesh = prev_pdata.mesh}) detacher:set_animation(prev_pdata.anim.range, prev_pdata.anim.speed, prev_pdata.anim.blend, prev_pdata.anim.loop) @@ -41,13 +40,13 @@ end function sitting.is_player_attached_to_anything(player) local prev_pdata = player:get_meta():get_string("previous_player_data") - + return prev_pdata ~= "" end function sitting.is_seat_busy(node_pos) local is_busy = minetest.get_meta(node_pos):get_string("is_busy") - + return is_busy ~= "" end @@ -67,25 +66,25 @@ function sitting.sit_player(player, node_pos) end local physics = player:get_physics_override() - + local prev_pdata = { physics = {speed = physics.speed, jump = physics.jump} } local node = minetest.get_node(node_pos) local seat_data = minetest.registered_nodes[node.name].add_properties.seat_data - + local rand_model if seat_data.models then local range, speed, blend, loop = player:get_animation() - + prev_pdata.mesh = player:get_properties().mesh prev_pdata.anim = {range = range, speed = speed, blend = blend, loop = loop} - + rand_model = seat_data.models[math.random(1, #seat_data.models)] end - + player:get_meta():set_string("previous_player_data", minetest.serialize(prev_pdata)) - + local dir_rot = vector.dir_to_rotation(minetest.facedir_to_dir(node.param2)) sitting.attach_player_to_node(player, {pos = vector.add(node_pos, seat_data.pos), rot = vector.add(dir_rot, seat_data.rot), model = rand_model}) @@ -96,13 +95,11 @@ end function sitting.standup_player(player, node_pos) if not player then - minetest.debug("1") return end local meta = minetest.get_meta(node_pos) if player:get_player_name() ~= meta:get_string("is_busy") then - minetest.debug("2") return false end diff --git a/modern/bedroom.lua b/modern/bedroom.lua index e7a215b..fb59d81 100644 --- a/modern/bedroom.lua +++ b/modern/bedroom.lua @@ -13,9 +13,6 @@ register.register_bed("jungle_bed", { on_construct = function(pos) connecting.update_adjacent_nodes_connection(pos, "pair") end, - after_destruct = function(pos, oldnode) - connecting.update_adjacent_nodes_connection(pos, "pair", true, oldnode) - end, after_dig_node = function(pos, oldnode) connecting.update_adjacent_nodes_connection(pos, "pair", true, oldnode) end diff --git a/modern/chairs.lua b/modern/chairs.lua index 41d4096..f8b851c 100644 --- a/modern/chairs.lua +++ b/modern/chairs.lua @@ -199,9 +199,24 @@ register.register_seat("sofa", { {-0.5, -0.5, -0.325, -0.4, 0.2, 0.225}, {0.4, -0.5, -0.325, 0.5, 0.2, 0.225}, {-0.5, -0.5, 0.225, 0.5, 0.6, 0.5} + }, + callbacks = { + on_construct = function(pos) + connecting.update_adjacent_nodes_connection(pos, "directional") + end, + after_dig_node = function(pos, old_node) + connecting.update_adjacent_nodes_connection(pos, "directional", true, old_node) + end } }, { + common_name = "sofa", + connect_parts = { + ["left_side"] = "multidecor_modern_sofa_1.b3d", + ["right_side"] = "multidecor_modern_sofa_2.b3d", + ["middle"] = "multidecor_modern_sofa_3.b3d", + ["corner"] = "multidecor_modern_sofa_4.b3d" + }, seat_data = { pos = {x=0.0, y=0.1, z=0.0}, rot = {x=0, y=0, z=0}, diff --git a/modern/models/multidecor_modern_sofa_1.b3d b/modern/models/multidecor_modern_sofa_1.b3d new file mode 100644 index 0000000..a230054 Binary files /dev/null and b/modern/models/multidecor_modern_sofa_1.b3d differ diff --git a/modern/models/multidecor_modern_sofa_1.blend b/modern/models/multidecor_modern_sofa_1.blend new file mode 100644 index 0000000..8133978 Binary files /dev/null and b/modern/models/multidecor_modern_sofa_1.blend differ diff --git a/modern/models/multidecor_modern_sofa_1.blend1 b/modern/models/multidecor_modern_sofa_1.blend1 new file mode 100644 index 0000000..8dca057 Binary files /dev/null and b/modern/models/multidecor_modern_sofa_1.blend1 differ diff --git a/modern/models/multidecor_modern_sofa_2.b3d b/modern/models/multidecor_modern_sofa_2.b3d new file mode 100644 index 0000000..9d1818d Binary files /dev/null and b/modern/models/multidecor_modern_sofa_2.b3d differ diff --git a/modern/models/multidecor_modern_sofa_2.blend b/modern/models/multidecor_modern_sofa_2.blend new file mode 100644 index 0000000..9625ad8 Binary files /dev/null and b/modern/models/multidecor_modern_sofa_2.blend differ diff --git a/modern/models/multidecor_modern_sofa_2.blend1 b/modern/models/multidecor_modern_sofa_2.blend1 new file mode 100644 index 0000000..e41a36f Binary files /dev/null and b/modern/models/multidecor_modern_sofa_2.blend1 differ diff --git a/modern/models/multidecor_modern_sofa_3.b3d b/modern/models/multidecor_modern_sofa_3.b3d new file mode 100644 index 0000000..5142d7a Binary files /dev/null and b/modern/models/multidecor_modern_sofa_3.b3d differ diff --git a/modern/models/multidecor_modern_sofa_3.blend b/modern/models/multidecor_modern_sofa_3.blend new file mode 100644 index 0000000..917f153 Binary files /dev/null and b/modern/models/multidecor_modern_sofa_3.blend differ diff --git a/modern/models/multidecor_modern_sofa_3.blend1 b/modern/models/multidecor_modern_sofa_3.blend1 new file mode 100644 index 0000000..9625ad8 Binary files /dev/null and b/modern/models/multidecor_modern_sofa_3.blend1 differ diff --git a/modern/models/multidecor_modern_sofa_4.b3d b/modern/models/multidecor_modern_sofa_4.b3d new file mode 100644 index 0000000..6d9fa71 Binary files /dev/null and b/modern/models/multidecor_modern_sofa_4.b3d differ diff --git a/modern/models/multidecor_modern_sofa_4.blend b/modern/models/multidecor_modern_sofa_4.blend new file mode 100644 index 0000000..2ae968e Binary files /dev/null and b/modern/models/multidecor_modern_sofa_4.blend differ diff --git a/modern/models/multidecor_modern_sofa_4.blend1 b/modern/models/multidecor_modern_sofa_4.blend1 new file mode 100644 index 0000000..a4398ed Binary files /dev/null and b/modern/models/multidecor_modern_sofa_4.blend1 differ diff --git a/modern/tables.lua b/modern/tables.lua index 8f4ac1a..f05240d 100644 --- a/modern/tables.lua +++ b/modern/tables.lua @@ -12,6 +12,7 @@ register.register_table("kitchen_modern_wooden_table", { connecting.update_adjacent_nodes_connection(pos, "horizontal") end, after_dig_node = function(pos) + minetest.debug("1.2") connecting.update_adjacent_nodes_connection(pos, "horizontal", true) end } diff --git a/modern/textures/multidecor_cloth.png b/modern/textures/multidecor_cloth.png index eb566e9..8382204 100644 Binary files a/modern/textures/multidecor_cloth.png and b/modern/textures/multidecor_cloth.png differ