init.lua 4.9 KB

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