init.lua 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. if not minetest.global_exists("lavacooling") then lavacooling = {} end
  2. lavacooling.modpath = minetest.get_modpath("lavacooling")
  3. local fire_node = {name="fire:basic_flame"}
  4. local obsidian_node = {name="default:obsidian"}
  5. local cobble_node = {name="default:cobble"}
  6. local dead_obsidian_node = {name="cavestuff:dark_obsidian"}
  7. local rockmelt_node = {name="cavestuff:cobble_with_rockmelt"}
  8. local air_node = {name="air"}
  9. local basalt_node = {name="gloopblocks:basalt"}
  10. local basaltic_node = {name="darkage:basaltic_rubble"}
  11. local pumice_node = {name="gloopblocks:pumice"}
  12. local find = string.find
  13. local findn = minetest.find_node_near
  14. local random = math.random
  15. local math_random = math.random
  16. local setn = minetest.add_node
  17. local getn = minetest.get_node
  18. local play = minetest.sound_play
  19. local allnodes = minetest.registered_nodes
  20. -- Nodename groups.
  21. local lava_sources = {"default:lava_source", "lbrim:lava_source"}
  22. local flowing_lava = {"default:lava_flowing", "lbrim:lava_flowing"}
  23. local water_sources = {"default:water_source", "default:river_water_source", "cw:water_source"}
  24. local flowing_water = {"default:water_flowing", "default:river_water_flowing", "cw:water_flowing"}
  25. local water_group = {
  26. "default:water_source",
  27. "default:water_flowing",
  28. "default:river_water_source",
  29. "default:river_water_flowing",
  30. "cw:water_source",
  31. "cw:water_flowing",
  32. }
  33. local lava_group = {
  34. "default:lava_source",
  35. "default:lava_flowing",
  36. "lbrim:lava_source",
  37. "lbrim:lava_flowing",
  38. }
  39. local melt_group = "group:melts"
  40. local flammable_group = "group:flammable"
  41. -- Melt stuff around lava.
  42. local function do_lava_melting(pos, node)
  43. ambiance.sound_play("lava", pos, 1.0, 32)
  44. local mpos = findn(pos, 1, melt_group)
  45. if mpos then
  46. local def = allnodes[getn(mpos).name] or {}
  47. if def._melts_to then
  48. setn(mpos, {name=def._melts_to})
  49. if math_random(1, 10) == 1 then
  50. sfn.drop_node(mpos)
  51. end
  52. elseif def.on_melt then
  53. def.on_melt(mpos, pos)
  54. else
  55. setn(mpos, rockmelt_node)
  56. -- Rockmelt has special falling code, so only trigger a fall if it actually could fall.
  57. if minetest.get_node({x=mpos.x, y=mpos.y-1, z=mpos.z}).name == "air" then
  58. sfn.drop_node(mpos)
  59. end
  60. end
  61. end
  62. end
  63. -- Remove flammable nodes around lava.
  64. local function do_lava_flammables(pos, node)
  65. -- Consume anything flammable.
  66. local fpos = findn(pos, 1, flammable_group)
  67. if fpos then
  68. setn(fpos, fire_node)
  69. end
  70. end
  71. -- Cool lava sources to regular obsidian.
  72. local function do_lavasource_cooling(pos, node)
  73. setn(pos, obsidian_node)
  74. if math_random(1, 10) == 1 then
  75. sfn.drop_node(pos)
  76. end
  77. play("default_cool_lava", {pos=pos, max_hear_distance=16, gain=0.25}, true)
  78. -- Add flames above cooled lava.
  79. pos.y = pos.y + 1
  80. if getn(pos).name == "air" then
  81. setn(pos, fire_node)
  82. end
  83. end
  84. -- Flowing lava + flowing water = basalt.
  85. local function do_flowinglava_flowingwater_cooling(pos, node)
  86. setn(pos, basalt_node)
  87. if math_random(1, 10) == 1 then
  88. sfn.drop_node(pos)
  89. end
  90. play("default_cool_lava", {pos=pos, max_hear_distance=16, gain=0.25}, true)
  91. -- Add flames above cooled lava.
  92. pos.y = pos.y + 1
  93. if getn(pos).name == "air" then
  94. setn(pos, fire_node)
  95. end
  96. end
  97. -- Flowing lava + water source = pumice.
  98. local function do_flowinglava_watersource_cooling(pos, node)
  99. setn(pos, pumice_node)
  100. if math_random(1, 10) == 1 then
  101. sfn.drop_node(pos)
  102. end
  103. play("default_cool_lava", {pos=pos, max_hear_distance=16, gain=0.25}, true)
  104. -- Add flames above cooled lava.
  105. pos.y = pos.y + 1
  106. if getn(pos).name == "air" then
  107. setn(pos, fire_node)
  108. end
  109. end
  110. -- Cool rockmelt to basalt rubble.
  111. local function do_rockmelt_cooling(pos, node)
  112. setn(pos, basaltic_node)
  113. if math_random(1, 10) == 1 then
  114. sfn.drop_node(pos)
  115. end
  116. end
  117. local speedmult = 0.25
  118. minetest.register_abm({
  119. label = "Lava Melting",
  120. nodenames = lava_group,
  121. neighbors = melt_group,
  122. interval = 13,
  123. chance = 256, -- Don't multiply melting speed.
  124. catch_up = false,
  125. action = do_lava_melting,
  126. })
  127. minetest.register_abm({
  128. label = "Lava Burn Flammable Nodes",
  129. nodenames = lava_group,
  130. neighbors = flammable_group,
  131. interval = 4,
  132. chance = 256*speedmult,
  133. catch_up = false,
  134. action = do_lava_flammables,
  135. })
  136. minetest.register_abm({
  137. label = "Lavasource Cooling",
  138. nodenames = lava_sources,
  139. neighbors = water_group,
  140. interval = 7,
  141. chance = 256*speedmult,
  142. catch_up = false,
  143. action = do_lavasource_cooling,
  144. })
  145. minetest.register_abm({
  146. label = "Flowinglava - Flowingwater Cooling",
  147. nodenames = flowing_lava,
  148. neighbors = flowing_water,
  149. interval = 9,
  150. chance = 256*speedmult,
  151. catch_up = false,
  152. action = do_flowinglava_flowingwater_cooling,
  153. })
  154. minetest.register_abm({
  155. label = "Flowinglava - Watersource Cooling",
  156. nodenames = flowing_lava,
  157. neighbors = water_sources,
  158. interval = 11,
  159. chance = 256*speedmult,
  160. catch_up = false,
  161. action = do_flowinglava_watersource_cooling,
  162. })
  163. minetest.register_abm({
  164. label = "Rockmelt Cooling",
  165. nodenames = {"cavestuff:cobble_with_rockmelt"},
  166. neighbors = water_group,
  167. interval = 3,
  168. chance = 256*speedmult,
  169. catch_up = false,
  170. action = do_rockmelt_cooling,
  171. })