ropeladder.lua 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. if ropes.ropeLadderLength == 0 and not ropes.create_all_definitions then
  2. return
  3. end
  4. -- internationalization boilerplate
  5. local MP = minetest.get_modpath(minetest.get_current_modname())
  6. local S, NS = dofile(MP.."/intllib.lua")
  7. if ropes.ropeLadderLength > 0 then
  8. minetest.register_craft({
  9. output = "ropes:ropeladder_top",
  10. recipe = {
  11. {'','group:stick',''},
  12. {'group:vines','group:stick','group:vines'},
  13. {'','group:stick',''},
  14. }
  15. })
  16. end
  17. minetest.register_craft({
  18. type = "fuel",
  19. recipe = "ropes:ropeladder_top",
  20. burntime = ropes.ladder_burn_time,
  21. })
  22. local rope_ladder_top_def = {
  23. description = S("Rope Ladder"),
  24. _doc_items_longdesc = ropes.doc.ropeladder_longdesc,
  25. _doc_items_usagehelp = ropes.doc.ropeladder_usage,
  26. drawtype = "signlike",
  27. tiles = {"default_ladder_wood.png^ropes_ropeladder_top.png"},
  28. is_ground_content = false,
  29. inventory_image = "default_ladder_wood.png^ropes_ropeladder_top.png",
  30. wield_image = "default_ladder_wood.png^ropes_ropeladder_top.png",
  31. paramtype = "light",
  32. paramtype2 = "wallmounted",
  33. walkable = false,
  34. climbable = true,
  35. sunlight_propagates = true,
  36. selection_box = {
  37. type = "wallmounted",
  38. --wall_top = = <default>
  39. --wall_bottom = = <default>
  40. --wall_side = = <default>
  41. },
  42. groups = { choppy=2, oddly_breakable_by_hand=1,flammable=2},
  43. sounds = default.node_sound_wood_defaults(),
  44. on_place = function(itemstack, placer, pointed_thing)
  45. if pointed_thing.type == "node" then
  46. local target_node = minetest.get_node(pointed_thing.under)
  47. local target_def = minetest.registered_nodes[target_node.name]
  48. if target_def.walkable == false then
  49. return itemstack
  50. end
  51. end
  52. return minetest.item_place(itemstack, placer, pointed_thing)
  53. end,
  54. after_place_node = function(pos, placer)
  55. local pos_below = {x=pos.x, y=pos.y-1, z=pos.z}
  56. local node_below = minetest.get_node(pos_below)
  57. local this_node = minetest.get_node(pos)
  58. local placer_name = placer:get_player_name()
  59. -- param2 holds the facing direction of this node. If it's 0 or 1 the node is "flat" and we don't want the ladder to extend.
  60. if ropes.can_place_rope_in_node(node_below.name) and this_node.param2 > 1
  61. and (not minetest.is_protected(pos_below, placer_name)
  62. or minetest.check_player_privs(placer_name, "protection_bypass")) then
  63. minetest.add_node(pos_below, {name="ropes:ropeladder_bottom", param2=this_node.param2})
  64. local meta = minetest.get_meta(pos_below)
  65. meta:set_int("length_remaining", ropes.ropeLadderLength)
  66. meta:set_string("placer", placer_name)
  67. end
  68. end,
  69. after_destruct = function(pos)
  70. local pos_below = {x=pos.x, y=pos.y-1, z=pos.z}
  71. ropes.destroy_rope(pos_below, {"ropes:ropeladder", "ropes:ropeladder_bottom", "ropes:ropeladder_falling"})
  72. end,
  73. }
  74. if ropes.ropeLadderLength == 0 then
  75. rope_ladder_top_def.groups.not_in_creative_inventory = 1
  76. end
  77. minetest.register_node("ropes:ropeladder_top", rope_ladder_top_def)
  78. minetest.register_node("ropes:ropeladder", {
  79. description = S("Rope Ladder"),
  80. _doc_items_create_entry = false,
  81. drop = "",
  82. drawtype = "signlike",
  83. tiles = {"default_ladder_wood.png^ropes_ropeladder.png"},
  84. is_ground_content = false,
  85. inventory_image = "default_ladder_wood.png^ropes_ropeladder.png",
  86. wield_image = "default_ladder_wood.png^ropes_ropeladder.png",
  87. paramtype = "light",
  88. paramtype2 = "wallmounted",
  89. walkable = false,
  90. climbable = true,
  91. sunlight_propagates = true,
  92. selection_box = {
  93. type = "wallmounted",
  94. --wall_top = = <default>
  95. --wall_bottom = = <default>
  96. --wall_side = = <default>
  97. },
  98. groups = {choppy=2, flammable=2, not_in_creative_inventory=1},
  99. sounds = default.node_sound_wood_defaults(),
  100. after_destruct = function(pos)
  101. ropes.hanging_after_destruct(pos, "ropes:ropeladder_falling", "ropes:ropeladder", "ropes:ropeladder_bottom")
  102. end,
  103. })
  104. local ladder_extender = ropes.make_rope_on_timer("ropes:ropeladder")
  105. minetest.register_node("ropes:ropeladder_bottom", {
  106. description = S("Rope Ladder"),
  107. _doc_items_create_entry = false,
  108. drop = "",
  109. drawtype = "signlike",
  110. tiles = {"default_ladder_wood.png^ropes_ropeladder_bottom.png"},
  111. is_ground_content = false,
  112. inventory_image = "default_ladder_wood.png^ropes_ropeladder_bottom.png",
  113. wield_image = "default_ladder_wood.png^ropes_ropeladder_bottom.png",
  114. paramtype = "light",
  115. paramtype2 = "wallmounted",
  116. walkable = false,
  117. climbable = true,
  118. sunlight_propagates = true,
  119. selection_box = {
  120. type = "wallmounted",
  121. --wall_top = = <default>
  122. --wall_bottom = = <default>
  123. --wall_side = = <default>
  124. },
  125. groups = {choppy=2, flammable=2, not_in_creative_inventory=1},
  126. sounds = default.node_sound_wood_defaults(),
  127. on_construct = function( pos )
  128. local timer = minetest.get_node_timer( pos )
  129. timer:start( 1 )
  130. end,
  131. on_timer = ladder_extender,
  132. after_destruct = function(pos)
  133. ropes.hanging_after_destruct(pos, "ropes:ropeladder_falling", "ropes:ropeladder", "ropes:ropeladder_bottom")
  134. end,
  135. })
  136. minetest.register_node("ropes:ropeladder_falling", {
  137. description = S("Rope Ladder"),
  138. _doc_items_create_entry = false,
  139. drop = "",
  140. drawtype = "signlike",
  141. tiles = {"default_ladder_wood.png^ropes_ropeladder.png"},
  142. is_ground_content = false,
  143. inventory_image = "default_ladder_wood.png^ropes_ropeladder.png",
  144. wield_image = "default_ladder_wood.png^ropes_ropeladder.png",
  145. paramtype = "light",
  146. paramtype2 = "wallmounted",
  147. walkable = false,
  148. climbable = true,
  149. sunlight_propagates = true,
  150. selection_box = {
  151. type = "wallmounted",
  152. --wall_top = = <default>
  153. --wall_bottom = = <default>
  154. --wall_side = = <default>
  155. },
  156. groups = {flammable=2, not_in_creative_inventory=1},
  157. sounds = default.node_sound_wood_defaults(),
  158. on_construct = function( pos )
  159. local timer = minetest.get_node_timer( pos )
  160. timer:start( 1 )
  161. end,
  162. on_timer = function( pos, elapsed )
  163. local pos_below = {x=pos.x, y=pos.y-1, z=pos.z}
  164. local node_below = minetest.get_node(pos_below)
  165. if (node_below.name ~= "ignore") then
  166. ropes.destroy_rope(pos_below, {'ropes:ropeladder', 'ropes:ropeladder_bottom', 'ropes:ropeladder_falling'})
  167. minetest.swap_node(pos, {name="air"})
  168. else
  169. local timer = minetest.get_node_timer( pos )
  170. timer:start( 1 )
  171. end
  172. end
  173. })