lava_cooling.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. -- Renew mod for Minetest
  2. -- Copyright © 2018 Alex Yst <https://y.st./>
  3. -- This program is free software; you can redistribute it and/or
  4. -- modify it under the terms of the GNU Lesser General Public
  5. -- License as published by the Free Software Foundation; either
  6. -- version 2.1 of the License, or (at your option) any later version.
  7. -- This software is distributed in the hope that it will be useful,
  8. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. -- Lesser General Public License for more details.
  11. -- You should have received a copy of the GNU Lesser General Public
  12. -- License along with this program. If not, see
  13. -- <https://www.gnu.org./licenses/>.
  14. if minetest.settings:get_bool("enable_lavacooling") ~= false then
  15. local lava_cooling_abm
  16. for _, ABM in next, minetest.registered_abms do
  17. if ABM.mod_origin == "default" and ABM.label == "Lava cooling" then
  18. lava_cooling_abm = ABM
  19. end
  20. end
  21. local function spawn_coal(y)
  22. if y >= 1025 and y <= 31000 then
  23. if math.random(8 * 8 * 8) <= 9 then
  24. return true
  25. end
  26. end
  27. if y >= -31000 and y <= 64 then
  28. if math.random(8 * 8 * 8) <= 8 then
  29. return true
  30. end
  31. end
  32. if y >= -31000 and y <= 0 then
  33. if math.random(24 * 24 * 24) <= 27 then
  34. return true
  35. end
  36. end
  37. end
  38. local function spawn_iron(y)
  39. if y >= 1025 and y <= 31000 then
  40. if math.random(9 * 9 * 9) <= 12 then
  41. return true
  42. end
  43. end
  44. if y >= -31000 and y <= 0 then
  45. if math.random(7 * 7 * 7) <= 5 then
  46. return true
  47. end
  48. end
  49. if y >= -31000 and y <= -64 then
  50. if math.random(24 * 24 * 24) <= 27 then
  51. return true
  52. end
  53. end
  54. end
  55. local function spawn_copper(y)
  56. if y >= 1025 and y <= 31000 then
  57. if math.random(9 * 9 * 9) <= 5 then
  58. return true
  59. end
  60. end
  61. if y >= -63 and y <= -16 then
  62. if math.random(12 * 12 * 12) <= 4 then
  63. return true
  64. end
  65. end
  66. if y >= -31000 and y <= -64 then
  67. if math.random(9 * 9 * 9) <= 5 then
  68. return true
  69. end
  70. end
  71. end
  72. local function spawn_tin(y)
  73. if y >= 1025 and y <= 31000 then
  74. if math.random(10 * 10 * 10) <= 5 then
  75. return true
  76. end
  77. end
  78. if y >= -127 and y <= -32 then
  79. if math.random(13 * 13 * 13) <= 4 then
  80. return true
  81. end
  82. end
  83. if y >= -31000 and y <= -128 then
  84. if math.random(10 * 10 * 10) <= 5 then
  85. return true
  86. end
  87. end
  88. end
  89. local function spawn_gold(y)
  90. if y >= 1025 and y <= 31000 then
  91. if math.random(13 * 13 * 13) <= 5 then
  92. return true
  93. end
  94. end
  95. if y >= -255 and y <= -64 then
  96. if math.random(15 * 15 * 15) <= 3 then
  97. return true
  98. end
  99. end
  100. if y >= -31000 and y <= -256 then
  101. if math.random(13 * 13 * 13) <= 5 then
  102. return true
  103. end
  104. end
  105. end
  106. local function spawn_mese(y)
  107. if y >= 1025 and y <= 31000 then
  108. if math.random(14 * 14 * 14) <= 5 then
  109. return true
  110. end
  111. end
  112. if y >= -255 and y <= -64 then
  113. if math.random(18 * 18 * 18) <= 3 then
  114. return true
  115. end
  116. end
  117. if y >= -31000 and y <= -256 then
  118. if math.random(14 * 14 * 14) <= 5 then
  119. return true
  120. end
  121. end
  122. end
  123. local function spawn_diamond(y)
  124. if y >= 1025 and y <= 31000 then
  125. if math.random(15 * 15 * 15) <= 4 then
  126. return true
  127. end
  128. end
  129. if y >= -255 and y <= -128 then
  130. if math.random(17 * 17 * 17) <= 4 then
  131. return true
  132. end
  133. end
  134. if y >= -3100 and y <= -256 then
  135. if math.random(15 * 15 * 15) <= 4 then
  136. return true
  137. end
  138. end
  139. end
  140. function lava_cooling_abm.action(pos)
  141. if spawn_coal(pos.y) then
  142. minetest.set_node(pos, {name = "default:stone_with_coal"})
  143. elseif spawn_iron(pos.y) then
  144. minetest.set_node(pos, {name = "default:stone_with_iron"})
  145. elseif spawn_copper(pos.y) then
  146. minetest.set_node(pos, {name = "default:stone_with_copper"})
  147. elseif spawn_tin(pos.y) then
  148. minetest.set_node(pos, {name = "default:stone_with_tin"})
  149. elseif spawn_gold(pos.y) then
  150. minetest.set_node(pos, {name = "default:stone_with_gold"})
  151. elseif spawn_mese(pos.y) then
  152. minetest.set_node(pos, {name = "default:stone_with_mese"})
  153. elseif spawn_diamond(pos.y) then
  154. minetest.set_node(pos, {name = "default:stone_with_diamond"})
  155. elseif spawn_diamond(pos.y) then
  156. minetest.set_node(pos, {name = "renew:obsidian_shard"})
  157. else
  158. minetest.set_node(pos, {name = "default:stone"})
  159. end
  160. minetest.sound_play("default_cool_lava", {pos = pos, max_hear_distance = 16, gain = 0.25})
  161. end
  162. end