From 763d8fa2009e4f0927f7368a7a5a83f968878b7e Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Thu, 18 Sep 2014 16:29:28 -0400 Subject: [PATCH] Add a tree swing model and textures by jp To place, point at the underside of a node, e.g. a ceiling or the bottom side of tree leaves or something. It will automatically stretch downward trying to find the ground (well, anything that isn't buildable_to anyway), down to a maximum of 4 meters' worth of rope. To remove, dig the swing itself and it'll take the rope with it. --- homedecor/crafts.lua | 25 +++++++ homedecor/init.lua | 48 +++++++++++++ homedecor/misc-nodes.lua | 66 +++++++++++++++--- homedecor/textures/homedecor_swing_bottom.png | Bin 0 -> 272 bytes homedecor/textures/homedecor_swing_inv.png | Bin 0 -> 2556 bytes homedecor/textures/homedecor_swing_sides.png | Bin 0 -> 293 bytes homedecor/textures/homedecor_swing_top.png | Bin 0 -> 279 bytes .../textures/homedecor_swingrope_sides.png | Bin 0 -> 144 bytes 8 files changed, 130 insertions(+), 9 deletions(-) create mode 100644 homedecor/textures/homedecor_swing_bottom.png create mode 100644 homedecor/textures/homedecor_swing_inv.png create mode 100644 homedecor/textures/homedecor_swing_sides.png create mode 100644 homedecor/textures/homedecor_swing_top.png create mode 100644 homedecor/textures/homedecor_swingrope_sides.png 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 0000000000000000000000000000000000000000..68d30b0ad896723e41d25f715a7b34c07b8d0ae8 GIT binary patch literal 272 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmPqrw|7(mq*8&LZHxGPZ!4!i_^&o609Q3ZW798Jf}W9 zf4`mw1a!{$@bvWjFkN@2T6&R~?;rb>VuyJ@Yz$2M@%y{{;l|DV5+P4oB~y-6N=p1Q zHrP}39jMhlDdxb569>*6JM~eyE7m-qn+{!G z12le9(w>5U=k5PX$nF2dQ-1RQ|Nn-(Hwr$Oc{W;bt>9pIuA_I-JK>ux(4h>Tu6{1- HoD!M<=&5CX literal 0 HcmV?d00001 diff --git a/homedecor/textures/homedecor_swing_inv.png b/homedecor/textures/homedecor_swing_inv.png new file mode 100644 index 0000000000000000000000000000000000000000..295c34c26f81d36377fa590fb0fe28307a5cb698 GIT binary patch literal 2556 zcmVI07c}G{gX-G zUh$2S8>xbA;@lkoSATngP6-yVH3U~G`hxQO$aE`a?Ho1W9UGLflxP3g(jTLJG3kEKxHAUAIRJ>Chv_oH9iN^3??N+rA6 z>)#WIW7h^KXWbq<4hJ})CSbI-#xuvB`mN<*ox4KDS=$C$Imf6-lNInjFJMu$)!zeP z93;U}E{8)lwygoc^G#WyW;G}c&L~jjFd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vTwI&Tc!o?WAn?G6paG=~eO)OIIjE2QdeS&2SP`N~$QH_s79+F*tw3o_N7`p3 zSEdwMZ0s1^HA0~jQz}Pvb#{|XBzbe!PEaZ?mt~%3c;Q#S-}Wa}Sgwx8wD&jtOmLEuPl+ zo1Jr@$c3@J9yHG^QNbs-1K^}r2%{Z zhFP_)-&Q}TfG+@71BZ%KWUiG$Yef(kG*SzHq?0~x50}XnN_*BnJJ@^TylKIcn+C#` zSHOqCsG3NwdVe{v4Bq>Wky4suLgQ)8?!5)V$hs#t4NUl%LsI~Jh>09oHIah>Pk_oV z!$JaW=03h@+h+b>M-@ixbLRBpW?pi}@iU+O@-Z{q7w1jC6ySu};GUxPRZ&>U?7ZAlPugr6y;JiZU>Sn@94@;8@ZEbUlNotDnm{r-UW|>q~0^ literal 0 HcmV?d00001 diff --git a/homedecor/textures/homedecor_swing_top.png b/homedecor/textures/homedecor_swing_top.png new file mode 100644 index 0000000000000000000000000000000000000000..dc829e2f6b918fdb78055c6a0819e0471d8cc063 GIT binary patch literal 279 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmPqrw|9PxOQK|3ZT#uPZ!4!i_>o>7;+tQ5O9ruR5nR# zfmm0sW%~opHG3BCU7L`Yy)XT_P9n%66+}nkaFE{k(d{;PbQ33$LE%T9stz zZE%gV;Z+OE!RNc5TCqBWPX1|^DWq}Ko2Y*JH>{`vZ`YmVj-s82aEM>liE3R4=5dAmM|EIsj VuVPQ$bf9|~JYD@<);T3K0RXdsY2p9? literal 0 HcmV?d00001 diff --git a/homedecor/textures/homedecor_swingrope_sides.png b/homedecor/textures/homedecor_swingrope_sides.png new file mode 100644 index 0000000000000000000000000000000000000000..314fb50cbd0f666e6e10cb95414ec1891c724b72 GIT binary patch literal 144 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmPqrx1sX!QEJ~%RnJnPZ!4!i_^(5H-tXVZ)7@f#6eNQ iG~r4^ATwJxBSYF-rUe;V9S4C589ZJ6T-G@yGywolEhWPM literal 0 HcmV?d00001