functions.lua 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. local H_LAG = caverealms.config.h_lag --15 --max height for stalagmites
  2. local H_LAC = caverealms.config.h_lac --20 --...stalactites
  3. local H_CRY = caverealms.config.h_cry --9 --max height of glow crystals
  4. local H_CLAC = caverealms.config.h_clac --13 --max height of glow crystal stalactites
  5. -- Contend ID's --
  6. local c_air = minetest.get_content_id("air")
  7. local c_stone = minetest.get_content_id("default:stone")
  8. local c_ice = minetest.get_content_id("default:ice")
  9. local c_meseore = minetest.get_content_id("default:stone_with_mese")
  10. local c_salt = minetest.get_content_id("caverealms:salt_crystal")
  11. local c_crystal = minetest.get_content_id("caverealms:glow_crystal")
  12. local c_crystore = minetest.get_content_id("caverealms:glow_ore")
  13. local c_emerald = minetest.get_content_id("caverealms:glow_emerald")
  14. local c_emore = minetest.get_content_id("caverealms:glow_emerald_ore")
  15. local c_mesecry = minetest.get_content_id("caverealms:glow_mese")
  16. local c_ruby = minetest.get_content_id("caverealms:glow_ruby")
  17. local c_rubore = minetest.get_content_id("caverealms:glow_ruby_ore")
  18. local c_ameth = minetest.get_content_id("caverealms:glow_amethyst")
  19. local c_amethore = minetest.get_content_id("caverealms:glow_amethyst_ore")
  20. local c_thinice = minetest.get_content_id("caverealms:thin_ice")
  21. local c_gills = minetest.get_content_id("caverealms:mushroom_gills")
  22. local c_stem
  23. local c_cap
  24. if minetest.get_modpath("ethereal") then
  25. c_stem = minetest.get_content_id("ethereal:mushroom_trunk")
  26. c_cap = minetest.get_content_id("ethereal:mushroom")
  27. else
  28. c_stem = minetest.get_content_id("caverealms:mushroom_stem")
  29. c_cap = minetest.get_content_id("caverealms:mushroom_cap")
  30. end
  31. -- FUNCTIONS --
  32. function caverealms:above_solid(x, y, z, area, data)
  33. local ai = area:index(x, y + 1, z - 3)
  34. if data[ai] == c_air then
  35. return false
  36. end
  37. return true
  38. end
  39. function caverealms:below_solid(x, y, z, area, data)
  40. local ai = area:index(x, y - 1, z - 3)
  41. if data[ai] == c_air then
  42. return false
  43. end
  44. return true
  45. end
  46. local random = math.random
  47. local abs = math.abs
  48. --stalagmite spawner
  49. function caverealms:stalagmite(x, y, z, area, data)
  50. if not caverealms:below_solid(x, y, z, area, data) then
  51. return
  52. end
  53. local top = random(6, H_LAG) --random height for the stalagmite
  54. local vi
  55. for j = 0, top do --y
  56. for k = -3, 3 do
  57. for l = -3, 3 do
  58. if j == 0 then
  59. if k * k + l * l <= 9 then
  60. vi = area:index(x + k, y + j, z + l - 3)
  61. data[vi] = c_stone
  62. end
  63. elseif j <= top/5 then
  64. if k * k + l * l <= 4 then
  65. vi = area:index(x + k, y + j, z + l - 3)
  66. data[vi] = c_stone
  67. end
  68. elseif j <= top / 5 * 3 then
  69. if k * k + l * l <= 1 then
  70. vi = area:index(x + k, y + j, z + l - 3)
  71. data[vi] = c_stone
  72. end
  73. else
  74. vi = area:index(x, y + j, z - 3)
  75. data[vi] = c_stone
  76. end
  77. end
  78. end
  79. end
  80. end
  81. --stalactite spawner
  82. function caverealms:stalactite(x, y, z, area, data)
  83. if not caverealms:above_solid(x, y, z, area, data) then
  84. return
  85. end
  86. local bot = random(-H_LAC, -6) -- random height for the stalagmite
  87. local vi
  88. for j = bot, 0 do --y
  89. for k = -3, 3 do
  90. for l = -3, 3 do
  91. if j >= -1 then
  92. if k * k + l * l <= 9 then
  93. vi = area:index(x + k, y + j, z + l - 3)
  94. data[vi] = c_stone
  95. end
  96. elseif j >= bot / 5 then
  97. if k * k + l * l <= 4 then
  98. vi = area:index(x + k, y + j, z + l - 3)
  99. data[vi] = c_stone
  100. end
  101. elseif j >= bot / 5 * 3 then
  102. if k * k + l * l <= 1 then
  103. vi = area:index(x + k, y + j, z + l - 3)
  104. data[vi] = c_stone
  105. end
  106. else
  107. vi = area:index(x, y + j, z - 3)
  108. data[vi] = c_stone
  109. end
  110. end
  111. end
  112. end
  113. end
  114. --glowing crystal stalagmite spawner
  115. function caverealms:crystal_stalagmite(x, y, z, area, data, biome)
  116. if not caverealms:below_solid(x, y, z, area, data) then
  117. return
  118. end
  119. --for randomness
  120. local mode = 1
  121. if random(15) == 1 then
  122. mode = 2
  123. end
  124. if biome == 3 then
  125. if random(25) == 1 then
  126. mode = 2
  127. else
  128. mode = 1
  129. end
  130. end
  131. if biome == 4 or biome == 5 then
  132. if random(3) == 1 then
  133. mode = 2
  134. end
  135. end
  136. local stalids = {
  137. {{c_crystore, c_crystal}, {c_emore, c_emerald}},
  138. {{c_emore, c_emerald}, {c_crystore, c_crystal}},
  139. {{c_emore, c_emerald}, {c_meseore, c_mesecry}},
  140. {{c_ice, c_thinice}, {c_crystore, c_crystal}},
  141. {{c_ice, c_thinice}, {c_crystore, c_crystal}},
  142. {{c_rubore, c_ruby}, {c_meseore, c_mesecry}},
  143. {{c_crystore, c_crystal}, {c_rubore, c_ruby}},
  144. {{c_rubore, c_ruby}, {c_emore, c_emerald}},
  145. {{c_amethore, c_ameth}, {c_meseore, c_mesecry}}
  146. }
  147. local nid_a
  148. local nid_b
  149. local nid_s = c_stone --stone base, will be rewritten to ice in certain biomes
  150. if biome > 3 and biome < 6 then
  151. if mode == 1 then
  152. nid_a = c_ice
  153. nid_b = c_thinice
  154. nid_s = c_ice
  155. else
  156. nid_a = c_crystore
  157. nid_b = c_crystal
  158. end
  159. elseif mode == 1 then
  160. nid_a = stalids[biome][1][1]
  161. nid_b = stalids[biome][1][2]
  162. else
  163. nid_a = stalids[biome][2][1]
  164. nid_b = stalids[biome][2][2]
  165. end
  166. local top = random(5, H_CRY) --random height for the stalagmite
  167. local vi
  168. for j = 0, top do --y
  169. for k = -3, 3 do
  170. for l = -3, 3 do
  171. if j == 0 then
  172. if k * k + l * l <= 9 then
  173. vi = area:index(x + k, y + j, z + l - 3)
  174. data[vi] = nid_s
  175. end
  176. elseif j <= top / 5 then
  177. if k * k + l * l <= 4 then
  178. vi = area:index(x + k, y + j, z + l - 3)
  179. data[vi] = nid_a
  180. end
  181. elseif j <= top / 5 * 3 then
  182. if k * k + l * l <= 1 then
  183. vi = area:index(x + k, y + j, z + l - 3)
  184. data[vi] = nid_b
  185. end
  186. else
  187. vi = area:index(x, y + j, z - 3)
  188. data[vi] = nid_b
  189. end
  190. end
  191. end
  192. end
  193. end
  194. --crystal stalactite spawner
  195. function caverealms:crystal_stalactite(x, y, z, area, data, biome)
  196. if not caverealms:above_solid(x, y, z, area, data) then
  197. return
  198. end
  199. --for randomness
  200. local mode = 1
  201. if random(15) == 1 then
  202. mode = 2
  203. end
  204. if biome == 3 then
  205. if random(25) == 1 then
  206. mode = 2
  207. else
  208. mode = 1
  209. end
  210. end
  211. if biome == 4 or biome == 5 then
  212. if random(3) == 1 then
  213. mode = 2
  214. end
  215. end
  216. local stalids = {
  217. {{c_crystore, c_crystal}, {c_emore, c_emerald}},
  218. {{c_emore, c_emerald}, {c_crystore, c_crystal}},
  219. {{c_emore, c_emerald}, {c_meseore, c_mesecry}},
  220. {{c_ice, c_thinice}, {c_crystore, c_crystal}},
  221. {{c_ice, c_thinice}, {c_crystore, c_crystal}},
  222. {{c_rubore, c_ruby}, {c_meseore, c_mesecry}},
  223. {{c_crystore, c_crystal}, {c_rubore, c_ruby}},
  224. {{c_rubore, c_ruby}, {c_emore, c_emerald}},
  225. {{c_amethore, c_ameth}, {c_meseore, c_mesecry}}
  226. }
  227. local nid_a
  228. local nid_b
  229. local nid_s = c_stone --stone base, will be rewritten to ice in certain biomes
  230. if biome > 3 and biome < 6 then
  231. if mode == 1 then
  232. nid_a = c_ice
  233. nid_b = c_thinice
  234. nid_s = c_ice
  235. else
  236. nid_a = c_crystore
  237. nid_b = c_crystal
  238. end
  239. elseif mode == 1 then
  240. nid_a = stalids[biome][1][1]
  241. nid_b = stalids[biome][1][2]
  242. else
  243. nid_a = stalids[biome][2][1]
  244. nid_b = stalids[biome][2][2]
  245. end
  246. local bot = random(-H_CLAC, -6) --random height for the stalagmite
  247. local vi
  248. for j = bot, 0 do --y
  249. for k = -3, 3 do
  250. for l = -3, 3 do
  251. if j >= -1 then
  252. if k * k + l * l <= 9 then
  253. vi = area:index(x + k, y + j, z + l - 3)
  254. data[vi] = nid_s
  255. end
  256. elseif j >= bot / 5 then
  257. if k * k + l * l <= 4 then
  258. vi = area:index(x + k, y + j, z + l - 3)
  259. data[vi] = nid_a
  260. end
  261. elseif j >= bot / 5 * 3 then
  262. if k * k + l * l <= 1 then
  263. vi = area:index(x + k, y + j, z + l - 3)
  264. data[vi] = nid_b
  265. end
  266. else
  267. vi = area:index(x, y + j, z - 3)
  268. data[vi] = nid_b
  269. end
  270. end
  271. end
  272. end
  273. end
  274. --glowing crystal stalagmite spawner
  275. function caverealms:salt_stalagmite(x, y, z, area, data, biome)
  276. if not caverealms:below_solid(x, y, z, area, data) then
  277. return
  278. end
  279. local scale = random(2, 4)
  280. local vi
  281. if scale == 2 then
  282. for j = -3, 3 do
  283. for k = -3, 3 do
  284. vi = area:index(x + j, y, z + k)
  285. data[vi] = c_stone
  286. if abs(j) ~= 3 and abs(k) ~= 3 then
  287. vi = area:index(x + j, y + 1, z + k)
  288. data[vi] = c_stone
  289. end
  290. end
  291. end
  292. else
  293. for j = -4, 4 do
  294. for k = -4, 4 do
  295. vi = area:index(x + j, y, z + k)
  296. data[vi] = c_stone
  297. if abs(j) ~= 4 and abs(k) ~= 4 then
  298. vi = area:index(x + j, y + 1, z + k)
  299. data[vi] = c_stone
  300. end
  301. end
  302. end
  303. end
  304. for j = 2, scale + 2 do --y
  305. for k = -2, scale - 2 do
  306. for l = -2, scale - 2 do
  307. vi = area:index(x + k, y + j, z + l)
  308. data[vi] = c_salt -- make cube
  309. end
  310. end
  311. end
  312. end
  313. --function to create giant 'shrooms
  314. function caverealms:giant_shroom(x, y, z, area, data)
  315. if not caverealms:below_solid(x, y, z, area, data) then
  316. return
  317. end
  318. z = z - 5
  319. local vi
  320. --cap
  321. for k = -5, 5 do
  322. for l = -5, 5 do
  323. if k * k + l * l <= 25 then
  324. vi = area:index(x + k, y + 5, z + l)
  325. data[vi] = c_cap
  326. end
  327. if k * k + l * l <= 16 then
  328. vi = area:index(x + k, y + 6, z + l)
  329. data[vi] = c_cap
  330. vi = area:index(x + k, y + 5, z + l)
  331. data[vi] = c_gills
  332. end
  333. if k * k + l * l <= 9 then
  334. vi = area:index(x + k, y + 7, z + l)
  335. data[vi] = c_cap
  336. end
  337. if k * k + l * l <= 4 then
  338. vi = area:index(x + k, y + 8, z + l)
  339. data[vi] = c_cap
  340. end
  341. end
  342. end
  343. local ai
  344. --stem
  345. for j = 0, 5 do
  346. for k = -1, 1 do
  347. vi = area:index(x + k, y + j, z)
  348. data[vi] = c_stem
  349. if k == 0 then
  350. ai = area:index(x, y + j, z + 1)
  351. data[ai] = c_stem
  352. ai = area:index(x, y + j, z - 1)
  353. data[ai] = c_stem
  354. end
  355. end
  356. end
  357. end