functions.lua 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. cavestuff = cavestuff or {}
  2. cavestuff.modpath = minetest.get_modpath("cavestuff")
  3. -- Localize for performance.
  4. local math_random = math.random
  5. -- Hot cobble functions.
  6. cavestuff.hotcobble = cavestuff.hotcobble or {}
  7. function cavestuff.hotcobble.after_place_node(pos, placer, itemstack, pointed_thing)
  8. if not placer or not placer:is_player() then
  9. return
  10. end
  11. -- Prevent players from placing hot cobble.
  12. if not heatdamage.is_immune(placer:get_player_name()) then
  13. placer:set_hp(placer:get_hp() - 2)
  14. end
  15. minetest.sound_play("default_cool_lava", {pos=pos, max_hear_distance=16, gain=0.25}, true)
  16. if pos.y < -20 then
  17. -- Underground, placing hot cobble is the same as placing a lava source.
  18. -- The action of placing it destabilizes it enough to become fully melted.
  19. minetest.add_node(pos, {name="default:lava_flowing"})
  20. else
  21. -- Don't allow hot cobble to be placed above surface level.
  22. minetest.add_node(pos, {name="default:cobble"})
  23. end
  24. end
  25. function cavestuff.hotcobble.after_dig_node(pos, oldnode, oldmetadata, digger)
  26. if not digger or not digger:is_player() then
  27. return
  28. end
  29. -- Damage player when digging.
  30. if not heatdamage.is_immune(digger:get_player_name()) then
  31. digger:set_hp(digger:get_hp() - 2)
  32. end
  33. minetest.sound_play("default_cool_lava", {pos=pos, max_hear_distance=16, gain=0.25}, true)
  34. -- Rockmelt always turns back to lava when dug if there is lava beside it.
  35. -- This makes it possible to farm lava above -20.
  36. local positions = {
  37. {x=pos.x+1, y=pos.y, z=pos.z},
  38. {x=pos.x-1, y=pos.y, z=pos.z},
  39. {x=pos.x, y=pos.y, z=pos.z+1},
  40. {x=pos.x, y=pos.y, z=pos.z-1},
  41. }
  42. for k, v in ipairs(positions) do
  43. local node = minetest.get_node(v)
  44. if string.find(node.name, ":lava_") then
  45. minetest.add_node(pos, {name="default:lava_source"})
  46. return
  47. end
  48. end
  49. if pos.y < -20 then
  50. -- Underground, digging hot cobble is enough to destabilize it and turn it into a lava source.
  51. minetest.add_node(pos, {name="default:lava_source"})
  52. else
  53. -- To prevent lava griefs of buildings on the surface, don't convert hot cobble to lava when dug.
  54. minetest.add_node(pos, {name="default:cobble"})
  55. end
  56. end
  57. function cavestuff.hotcobble.on_player_walk_over(pos, player)
  58. -- Damage players who walk on hot cobble.
  59. if not heatdamage.is_immune(player:get_player_name()) then
  60. player:set_hp(player:get_hp() - 1)
  61. end
  62. end
  63. function cavestuff.hotcobble.on_finish_collapse(pos, node)
  64. if pos.y < -10 then
  65. if math_random(1, 10) > 8 then
  66. minetest.swap_node(pos, {name="default:lava_source"})
  67. elseif math_random(1, 75) == 1 then
  68. minetest.remove_node(pos)
  69. -- Detonate some TNT!
  70. -- Warning: this causes fatal lava tunneling which can ruin the map!
  71. -- (And player's fun.)
  72. -- Increased chance from 2 in 10 to 1 in 75. Let us see how it goes.
  73. --[[
  74. tnt.boom(pos, {
  75. radius = 5,
  76. ignore_protection = false,
  77. ignore_on_blast = false,
  78. damage_radius = 10,
  79. disable_drops = true,
  80. make_sound = false, -- The TNT boom sound wrecks the ambiance.
  81. })
  82. --]]
  83. else
  84. -- Do nothing.
  85. end
  86. else
  87. minetest.swap_node(pos, {name="default:cobble"})
  88. end
  89. end
  90. if not cavestuff.run_once then
  91. local c = "cavestuff:core"
  92. local f = cavestuff.modpath .. "/functions.lua"
  93. reload.register_file(c, f, false)
  94. cavestuff.run_once = true
  95. end