diff --git a/homedecor/crafts.lua b/homedecor/crafts.lua index 0c647bb0..9d548551 100644 --- a/homedecor/crafts.lua +++ b/homedecor/crafts.lua @@ -2748,4 +2748,29 @@ minetest.register_craft({ }, }) +minetest.register_craft({ + output = "homedecor:swing", + recipe = { + { "farming:string","","farming:string" }, + { "farming:string","","farming:string" }, + { "farming:string","stairs:slab_wood","farming:string" } + }, +}) +minetest.register_craft({ + output = "homedecor:swing", + recipe = { + { "farming:string","","farming:string" }, + { "farming:string","","farming:string" }, + { "farming:string","moreblocks:slab_wood","farming:string" } + }, +}) + +minetest.register_craft({ + output = "homedecor:swing", + recipe = { + { "farming:string","","farming:string" }, + { "farming:string","","farming:string" }, + { "farming:string","moreblocks:panel_wood_1","farming:string" } + }, +}) diff --git a/homedecor/init.lua b/homedecor/init.lua index d964a8d4..7413c554 100644 --- a/homedecor/init.lua +++ b/homedecor/init.lua @@ -146,6 +146,54 @@ function homedecor.stack_sideways(itemstack, placer, pointed_thing, node1, node2 end end +-- Determine if the item being pointed at is the underside of a node (e.g a ceiling) + +function homedecor.find_ceiling(itemstack, placer, pointed_thing) + -- most of this is copied from the rotate-and-place function in builtin + local unode = core.get_node_or_nil(pointed_thing.under) + if not unode then + return + end + local undef = core.registered_nodes[unode.name] + if undef and undef.on_rightclick then + undef.on_rightclick(pointed_thing.under, unode, placer, + itemstack, pointed_thing) + return + end + local pitch = placer:get_look_pitch() + local fdir = core.dir_to_facedir(placer:get_look_dir()) + local wield_name = itemstack:get_name() + + local above = pointed_thing.above + local under = pointed_thing.under + local iswall = (above.y == under.y) + local isceiling = not iswall and (above.y < under.y) + local anode = core.get_node_or_nil(above) + if not anode then + return + end + local pos = pointed_thing.above + local node = anode + + if undef and undef.buildable_to then + pos = pointed_thing.under + node = unode + iswall = false + end + + if core.is_protected(pos, placer:get_player_name()) then + core.record_protection_violation(pos, + placer:get_player_name()) + return + end + + local ndef = core.registered_nodes[node.name] + if not ndef or not ndef.buildable_to then + return + end + return isceiling, pos +end + -- load various other components dofile(homedecor.modpath.."/misc-nodes.lua") -- the catch-all for all misc nodes diff --git a/homedecor/misc-nodes.lua b/homedecor/misc-nodes.lua index 506b5a21..51d0a1f5 100644 --- a/homedecor/misc-nodes.lua +++ b/homedecor/misc-nodes.lua @@ -1788,6 +1788,7 @@ minetest.register_node("homedecor:swing", { "homedecor_swing_bottom.png", "homedecor_swing_sides.png" }, + inventory_image = "homedecor_swing_inv.png", drawtype = "nodebox", paramtype = "light", paramtype2 = "facedir", @@ -1795,19 +1796,62 @@ minetest.register_node("homedecor:swing", { node_box = { type = "fixed", fixed = { - {-0.3125, 0.33, -0.125, 0.3125, 0.376, 0.1875}, -- NodeBox1 - {-0.3125, 0.376, 0.025, -0.3, 0.5, 0.0375}, -- NodeBox2 - {0.3, 0.376, 0.025, 0.3125, 0.5, 0.0375}, -- NodeBox3 + {-0.3125, 0.33, -0.125, 0.3125, 0.376, 0.1875}, -- NodeBox1 + {-0.3125, 0.376, 0.025, -0.3, 0.5, 0.0375}, -- NodeBox2 + { 0.3, 0.376, 0.025, 0.3125, 0.5, 0.0375}, -- NodeBox3 } }, + selection_box = { + type = "fixed", + fixed = { -0.3125, 0.33, -0.125, 0.3125, 0.5, 0.1875 } + }, on_place = function(itemstack, placer, pointed_thing) - return homedecor.stack_vertically(itemstack, placer, pointed_thing, - "homedecor:swing", "homedecor:swing_rope") + isceiling, pos = homedecor.find_ceiling(itemstack, placer, pointed_thing) + if isceiling then + local height = 0 + + for i = 0, 4 do -- search up to 5 spaces downward from the ceiling for the first non-buildable-to node... + height = i + local testpos = { x=pos.x, y=pos.y-i-1, z=pos.z } + local testnode = minetest.get_node(testpos) + local testreg = core.registered_nodes[testnode.name] + + if not testreg.buildable_to then + if i < 1 then + minetest.chat_send_player(placer:get_player_name(), "No room under there to hang a swing.") + return + else + break + end + end + end + + for j = 0, height do -- then fill that space with ropes... + local testpos = { x=pos.x, y=pos.y-j, z=pos.z } + local testnode = minetest.get_node(testpos) + local testreg = core.registered_nodes[testnode.name] + minetest.set_node(testpos, { name = "homedecor:swing_rope", param2 = fdir }) + end + + minetest.set_node({ x=pos.x, y=pos.y-height, z=pos.z }, { name = "homedecor:swing", param2 = fdir }) + + if not homedecor.expect_infinite_stacks then + itemstack:take_item() + return itemstack + end + + else + minetest.chat_send_player(placer:get_player_name(), "You have to point at the bottom side of an overhanging object to place a swing.") + end end, after_dig_node = function(pos, oldnode, oldmetadata, digger) - local pos2 = { x = pos.x, y=pos.y + 1, z = pos.z } - if minetest.get_node(pos2).name == "homedecor:swing_rope" then - minetest.remove_node(pos2) + for i = 0, 4 do + local testpos = { x=pos.x, y=pos.y+i+1, z=pos.z } + if minetest.get_node(testpos).name == "homedecor:swing_rope" then + minetest.remove_node(testpos) + else + return + end end end }) @@ -1819,12 +1863,16 @@ minetest.register_node("homedecor:swing_rope", { drawtype = "nodebox", paramtype = "light", paramtype2 = "facedir", - groups = { snappy=3, not_in_creative_inventory=1 }, + groups = { not_in_creative_inventory=1 }, node_box = { type = "fixed", fixed = { {-0.3125, -0.5, 0.025, -0.3, 0.5, 0.0375}, -- NodeBox1 {0.3, -0.5, 0.025, 0.3125, 0.5, 0.0375}, -- NodeBox2 } + }, + selection_box = { + type = "fixed", + fixed = { 0, 0, 0, 0, 0, 0 } } }) diff --git a/homedecor/textures/homedecor_swing_bottom.png b/homedecor/textures/homedecor_swing_bottom.png new file mode 100644 index 00000000..68d30b0a Binary files /dev/null and b/homedecor/textures/homedecor_swing_bottom.png differ diff --git a/homedecor/textures/homedecor_swing_inv.png b/homedecor/textures/homedecor_swing_inv.png new file mode 100644 index 00000000..295c34c2 Binary files /dev/null and b/homedecor/textures/homedecor_swing_inv.png differ diff --git a/homedecor/textures/homedecor_swing_sides.png b/homedecor/textures/homedecor_swing_sides.png new file mode 100644 index 00000000..1a82832b Binary files /dev/null and b/homedecor/textures/homedecor_swing_sides.png differ diff --git a/homedecor/textures/homedecor_swing_top.png b/homedecor/textures/homedecor_swing_top.png new file mode 100644 index 00000000..dc829e2f Binary files /dev/null and b/homedecor/textures/homedecor_swing_top.png differ diff --git a/homedecor/textures/homedecor_swingrope_sides.png b/homedecor/textures/homedecor_swingrope_sides.png new file mode 100644 index 00000000..314fb50c Binary files /dev/null and b/homedecor/textures/homedecor_swingrope_sides.png differ