init.lua 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. -- function to safely remove climbable air
  2. local function remove_air(pos, oldnode)
  3. local dir = minetest.facedir_to_dir(oldnode.param2)
  4. local airpos = vector.subtract(pos, dir)
  5. local north_node = minetest.get_node({x = airpos.x, y = airpos.y, z = airpos.z+1})
  6. local south_node = minetest.get_node({x = airpos.x, y = airpos.y, z = airpos.z-1})
  7. local east_node = minetest.get_node({x = airpos.x+1, y = airpos.y, z = airpos.z})
  8. local west_node = minetest.get_node({x = airpos.x-1, y = airpos.y, z = airpos.z})
  9. local keep_air =
  10. (minetest.get_item_group(north_node.name, "handholds") == 1 and
  11. north_node.param2 == 0) or
  12. (minetest.get_item_group(south_node.name, "handholds") == 1 and
  13. south_node.param2 == 2) or
  14. (minetest.get_item_group(east_node.name, "handholds") == 1 and
  15. east_node.param2 == 1) or
  16. (minetest.get_item_group(west_node.name, "handholds") == 1 and
  17. west_node.param2 == 3)
  18. if not keep_air then
  19. minetest.add_node(airpos, {name = "air"})
  20. end
  21. end
  22. -- remove handholds from nodes buried under falling nodes
  23. local function remove_handholds(pos)
  24. local north_pos = {x = pos.x, y = pos.y, z = pos.z+1}
  25. local south_pos = {x = pos.x, y = pos.y, z = pos.z-1}
  26. local east_pos = {x = pos.x+1, y = pos.y, z = pos.z}
  27. local west_pos = {x = pos.x-1, y = pos.y, z = pos.z}
  28. local north_node = minetest.get_node(north_pos)
  29. local south_node = minetest.get_node(south_pos)
  30. local east_node = minetest.get_node(east_pos)
  31. local west_node = minetest.get_node(west_pos)
  32. local node_pos
  33. if minetest.get_item_group(north_node.name, "handholds") == 1 and
  34. north_node.param2 == 0 then
  35. node_pos = north_pos
  36. elseif minetest.get_item_group(south_node.name, "handholds") == 1 and
  37. south_node.param2 == 2 then
  38. node_pos = south_pos
  39. elseif minetest.get_item_group(east_node.name, "handholds") == 1 and
  40. east_node.param2 == 1 then
  41. node_pos = east_pos
  42. elseif minetest.get_item_group(west_node.name, "handholds") == 1 and
  43. west_node.param2 == 3 then
  44. node_pos = west_pos
  45. end
  46. if node_pos then
  47. --local handholds_node = string.split(minetest.get_node(node_pos).name, ":")
  48. local nn = minetest.get_node(node_pos).name
  49. local def = minetest.registered_items[nn]
  50. if def and def._handholds_original then
  51. minetest.add_node(node_pos, {name = def._handholds_original})
  52. end
  53. end
  54. end
  55. -- climbable air!
  56. minetest.register_node("handholds:climbable_air", {
  57. description = "Air!",
  58. drawtype = "airlike",
  59. paramtype = "light",
  60. sunlight_propagates = true,
  61. walkable = false,
  62. pointable = false,
  63. diggable = false,
  64. climbable = true,
  65. buildable_to = true,
  66. floodable = true,
  67. drop = "",
  68. groups = {not_in_creative_inventory = 1},
  69. sounds = default.node_sound_stone_defaults(),
  70. on_destruct = function(pos)
  71. remove_handholds(pos)
  72. end,
  73. on_flood = function(pos)
  74. remove_handholds(pos)
  75. end,
  76. -- Player should not be able to obtain node.
  77. on_finish_collapse = function(pos, node)
  78. minetest.remove_node(pos)
  79. end,
  80. on_collapse_to_entity = function(pos, node)
  81. -- Do nothing.
  82. end,
  83. })
  84. -- handholds nodes
  85. minetest.register_node("handholds:stone", {
  86. description = "Stone Handholds",
  87. tiles = {
  88. "default_stone.png", "default_stone.png",
  89. "default_stone.png", "default_stone.png",
  90. "default_stone.png", "default_stone.png^handholds_holds.png"
  91. },
  92. paramtype2 = "facedir",
  93. on_rotate = function()
  94. return false
  95. end,
  96. groups = utility.dig_groups("stone", {not_in_creative_inventory = 1, handholds = 1}),
  97. drop = 'default:cobble',
  98. sounds = default.node_sound_stone_defaults(),
  99. after_destruct = function(pos, oldnode)
  100. remove_air(pos, oldnode)
  101. end,
  102. _handholds_original = "default:stone",
  103. })
  104. minetest.register_node("handholds:desert_stone", {
  105. description = "Desert Stone Handholds",
  106. tiles = {
  107. "default_desert_stone.png", "default_desert_stone.png",
  108. "default_desert_stone.png", "default_desert_stone.png",
  109. "default_desert_stone.png", "default_desert_stone.png^handholds_holds.png"
  110. },
  111. paramtype2 = "facedir",
  112. on_rotate = function()
  113. return false
  114. end,
  115. groups = utility.dig_groups("stone", {not_in_creative_inventory = 1, handholds = 1}),
  116. drop = 'default:desert_cobble2',
  117. sounds = default.node_sound_stone_defaults(),
  118. after_destruct = function(pos, oldnode)
  119. remove_air(pos, oldnode)
  120. end,
  121. _handholds_original = "default:desert_stone",
  122. })
  123. minetest.register_node("handholds:sandstone", {
  124. description = "Sandstone Handholds",
  125. tiles = {
  126. "default_sandstone.png", "default_sandstone.png",
  127. "default_sandstone.png", "default_sandstone.png",
  128. "default_sandstone.png", "default_sandstone.png^handholds_holds.png"
  129. },
  130. paramtype2 = "facedir",
  131. on_rotate = function()
  132. return false
  133. end,
  134. groups = utility.dig_groups("softstone", {not_in_creative_inventory = 1, handholds = 1}),
  135. drop = 'default:sandstone',
  136. sounds = default.node_sound_stone_defaults(),
  137. after_destruct = function(pos, oldnode)
  138. remove_air(pos, oldnode)
  139. end,
  140. _handholds_original = "default:sandstone",
  141. })
  142. minetest.register_node("handholds:ice", {
  143. description = "Ice Handholds",
  144. tiles = {
  145. "default_ice.png", "default_ice.png",
  146. "default_ice.png", "default_ice.png",
  147. "default_ice.png", "default_ice.png^handholds_holds.png"
  148. },
  149. paramtype2 = "facedir",
  150. on_rotate = function()
  151. return false
  152. end,
  153. groups = utility.dig_groups("ice", {
  154. puts_out_fire = 1, cools_lava = 1,
  155. not_in_creative_inventory = 1, handholds = 1
  156. }),
  157. drop = 'default:ice',
  158. sounds = default.node_sound_glass_defaults(),
  159. after_destruct = function(pos, oldnode)
  160. remove_air(pos, oldnode)
  161. end,
  162. _handholds_original = "default:ice",
  163. on_construct = function(pos)
  164. if rc.ice_melts_at_pos(pos) then
  165. minetest.get_node_timer(pos):start(math.random(ice.minmax_time()))
  166. end
  167. end,
  168. on_timer = function(pos, elapsed)
  169. if rc.ice_melts_at_pos(pos) then
  170. minetest.add_node(pos, {name="default:water_flowing"})
  171. end
  172. end,
  173. })
  174. minetest.register_node("handholds:rackstone", {
  175. description = "Rackstone Handholds",
  176. tiles = {
  177. "rackstone_rackstone.png", "rackstone_rackstone.png",
  178. "rackstone_rackstone.png", "rackstone_rackstone.png",
  179. "rackstone_rackstone.png", "rackstone_rackstone.png^handholds_holds_dark.png"
  180. },
  181. paramtype2 = "facedir",
  182. groups = utility.dig_groups("stone", {handholds=1}),
  183. sounds = default.node_sound_stone_defaults(),
  184. drop = 'rackstone:rackstone',
  185. on_rotate = function()
  186. return false
  187. end,
  188. after_destruct = function(pos, oldnode)
  189. remove_air(pos, oldnode)
  190. rackstone.destabilize_dauthsand(pos)
  191. end,
  192. _handholds_original = "rackstone:rackstone",
  193. })
  194. minetest.register_node("handholds:redrack", {
  195. description = "Netherack Handholds",
  196. tiles = {
  197. "rackstone_redrack.png", "rackstone_redrack.png",
  198. "rackstone_redrack.png", "rackstone_redrack.png",
  199. "rackstone_redrack.png", "rackstone_redrack.png^handholds_holds_very_dark.png"
  200. },
  201. paramtype2 = "facedir",
  202. groups = utility.dig_groups("netherack", {handholds=1}),
  203. sounds = rackstone.rackstone_sounds(),
  204. drop = 'rackstone:redrack',
  205. on_rotate = function()
  206. return false
  207. end,
  208. after_destruct = function(pos, oldnode)
  209. remove_air(pos, oldnode)
  210. rackstone.after_redrack_remove(pos, oldnode)
  211. rackstone.destabilize_dauthsand(pos, oldnode)
  212. end,
  213. on_construct = function(pos)
  214. rackstone.on_redrack_place(pos)
  215. end,
  216. _handholds_original = "rackstone:redrack",
  217. })
  218. -- handholds tool
  219. minetest.register_tool("handholds:climbing_pick", {
  220. description = "Climbing Pick",
  221. inventory_image = "handholds_tool.png",
  222. sound = {breaks = "default_tool_breaks"},
  223. on_use = function(itemstack, player, pointed_thing)
  224. if not pointed_thing or
  225. pointed_thing.type ~= "node" or
  226. minetest.is_protected(pointed_thing.under, player:get_player_name()) or
  227. minetest.is_protected(pointed_thing.above, player:get_player_name()) or
  228. pointed_thing.under.y + 1 == pointed_thing.above.y or
  229. pointed_thing.under.y - 1 == pointed_thing.above.y then
  230. return
  231. end
  232. local node_def =
  233. minetest.reg_ns_nodes[minetest.get_node(pointed_thing.above).name]
  234. if not node_def or not node_def.buildable_to then
  235. return
  236. end
  237. local node_name = minetest.get_node(pointed_thing.under).name
  238. local rotation = minetest.dir_to_facedir(
  239. vector.subtract(pointed_thing.under, pointed_thing.above))
  240. if node_name == "default:stone" then
  241. minetest.add_node(pointed_thing.under,
  242. {name = "handholds:stone", param2 = rotation})
  243. elseif node_name == "default:desert_stone" then
  244. minetest.add_node(pointed_thing.under,
  245. {name = "handholds:desert_stone", param2 = rotation})
  246. elseif node_name == "default:sandstone" then
  247. minetest.add_node(pointed_thing.under,
  248. {name = "handholds:sandstone", param2 = rotation})
  249. elseif node_name == "default:ice" then
  250. minetest.add_node(pointed_thing.under,
  251. {name = "handholds:ice", param2 = rotation})
  252. elseif node_name == "rackstone:rackstone" or node_name == "rackstone:mg_rackstone" then
  253. minetest.add_node(pointed_thing.under,
  254. {name = "handholds:rackstone", param2 = rotation})
  255. elseif node_name == "rackstone:redrack" or node_name == "rackstone:mg_redrack" then
  256. minetest.add_node(pointed_thing.under,
  257. {name = "handholds:redrack", param2 = rotation})
  258. else
  259. return
  260. end
  261. minetest.add_node(pointed_thing.above, {name = "handholds:climbable_air"})
  262. ambiance.sound_play("default_dig_cracky", pointed_thing.above, 0.5, 30)
  263. if not minetest.setting_getbool("creative_mode") then
  264. local wdef = itemstack:get_definition()
  265. itemstack:add_wear(256)
  266. if itemstack:get_count() == 0 and wdef.sound and wdef.sound.breaks then
  267. minetest.sound_play(wdef.sound.breaks,
  268. {pos = pointed_thing.above, gain = 0.5})
  269. end
  270. return itemstack
  271. end
  272. end
  273. })
  274. minetest.register_craft({
  275. output = "handholds:climbing_pick",
  276. recipe = {
  277. {'default:diamond', 'default:diamond', 'default:diamond'},
  278. {'group:stick', '', ''},
  279. {'group:stick', '', ''},
  280. },
  281. })