functions.lua 10 KB

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