init.lua 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. if not minetest.global_exists("stoneworld") then stoneworld = {} end
  2. stoneworld.modpath = minetest.get_modpath("stoneworld")
  3. -- These match values in the realm-control mod.
  4. stoneworld.REALM_START = 5150
  5. stoneworld.REALM_END = 8150
  6. -- Content IDs used with the voxel manipulator.
  7. local c_air = minetest.get_content_id("air")
  8. local c_ignore = minetest.get_content_id("ignore")
  9. local c_stone = minetest.get_content_id("darkage:basaltic")
  10. local c_cobble = minetest.get_content_id("darkage:basaltic_rubble")
  11. local c_bedrock = minetest.get_content_id("bedrock:bedrock")
  12. local c_lava = minetest.get_content_id("lbrim:lava_source")
  13. local c_lava2 = minetest.get_content_id("default:lava_source")
  14. local c_melt = minetest.get_content_id("cavestuff:cobble_with_rockmelt")
  15. local c_glow = minetest.get_content_id("glowstone:cobble")
  16. local c_obsidian = minetest.get_content_id("cavestuff:dark_obsidian")
  17. local c_obsidian2 = minetest.get_content_id("default:obsidian")
  18. local c_worm = minetest.get_content_id("cavestuff:glow_worm")
  19. local c_fungus = minetest.get_content_id("cavestuff:glow_fungus")
  20. local c_adamant = minetest.get_content_id("default:adamant")
  21. -- Externally located tables for performance.
  22. local vm_data = {}
  23. local vm_light = {}
  24. local noisemap1 = {}
  25. local noisemap3 = {}
  26. local noisemap4 = {}
  27. local noisemap5 = {}
  28. local noisemap6 = {}
  29. local perlin1
  30. local perlin3
  31. local perlin4
  32. local perlin5
  33. local perlin6
  34. --------------------------------------------------------------------------------
  35. stoneworld.caveseed = PseudoRandom(357)
  36. stoneworld.caveroutenoise = {
  37. offset = 0,
  38. scale = 1,
  39. spread = {x=75, y=75, z=75},
  40. seed = 0,
  41. octaves = 10,
  42. persist = 0.5,
  43. lacunarity = 1.6,
  44. }
  45. stoneworld.caveheightnoise = {
  46. offset = 0,
  47. scale = 1,
  48. spread = {x=256, y=256, z=256},
  49. seed = 0,
  50. octaves = 4,
  51. persist = 0.5,
  52. lacunarity = 2.0,
  53. }
  54. stoneworld.caves = stoneworld.caves or {}
  55. if not stoneworld.registered then
  56. -- Construct a few cave levels every 50 meters for 3000 meters height.
  57. -- Multiple overlapping cave networks ensures a probability of intersection.
  58. for k = 1, 60 do
  59. -- Cave network 1.
  60. stoneworld.caves[#stoneworld.caves + 1] = {}
  61. stoneworld.caves[#stoneworld.caves].y_level = k * 50 - 10
  62. -- Cave network 2.
  63. stoneworld.caves[#stoneworld.caves + 1] = {}
  64. stoneworld.caves[#stoneworld.caves].y_level = k * 50
  65. -- Cave network 3.
  66. stoneworld.caves[#stoneworld.caves + 1] = {}
  67. stoneworld.caves[#stoneworld.caves].y_level = k * 50 + 10
  68. end
  69. for k, v in ipairs(stoneworld.caves) do
  70. v.noise_route = table.copy(stoneworld.caveroutenoise)
  71. v.noise_route.seed = stoneworld.caveseed:next()
  72. v.route_map = {} -- Storage for bulk noise data.
  73. v.noise_height = table.copy(stoneworld.caveheightnoise)
  74. v.noise_height.seed = stoneworld.caveseed:next()
  75. v.height_map = {} -- Storage for bulk noise data.
  76. end
  77. end
  78. --------------------------------------------------------------------------------
  79. stoneworld.cavernseed = PseudoRandom(548)
  80. stoneworld.cavernceilingnoise = {
  81. offset = 0,
  82. scale = 1,
  83. spread = {x=64, y=64, z=64},
  84. seed = 0,
  85. octaves = 7,
  86. persist = 0.5,
  87. lacunarity = 1.6,
  88. }
  89. stoneworld.cavernfloornoise = {
  90. offset = 0,
  91. scale = 1,
  92. spread = {x=64, y=64, z=64},
  93. seed = 0,
  94. octaves = 7,
  95. persist = 0.5,
  96. lacunarity = 1.6,
  97. }
  98. stoneworld.cavernlevelnoise = {
  99. offset = 0,
  100. scale = 1,
  101. spread = {x=512, y=512, z=512},
  102. seed = 0,
  103. octaves = 3,
  104. persist = 0.5,
  105. lacunarity = 2.0,
  106. }
  107. stoneworld.caverns = stoneworld.caverns or {}
  108. if not stoneworld.registered then
  109. -- Construct a cavern level every 500 meters for 3000 meters height.
  110. for k = 1, 5 do
  111. stoneworld.caverns[#stoneworld.caverns + 1] = {}
  112. stoneworld.caverns[#stoneworld.caverns].y_level = k * 500
  113. end
  114. for k, v in ipairs(stoneworld.caverns) do
  115. v.noise_ceiling = table.copy(stoneworld.cavernceilingnoise)
  116. v.noise_ceiling.seed = stoneworld.cavernseed:next()
  117. v.ceiling_map = {} -- Storage for bulk noise data.
  118. v.noise_floor = table.copy(stoneworld.cavernfloornoise)
  119. v.noise_floor.seed = stoneworld.cavernseed:next()
  120. v.floor_map = {} -- Storage for bulk noise data.
  121. v.noise_level = table.copy(stoneworld.cavernlevelnoise)
  122. v.noise_level.seed = stoneworld.cavernseed:next()
  123. v.level_map = {} -- Storage for bulk noise data.
  124. end
  125. end
  126. --------------------------------------------------------------------------------
  127. -- Bedrock layer thickness variation.
  128. stoneworld.noise1param2d = {
  129. offset = 0,
  130. scale = 1,
  131. spread = {x=64, y=64, z=64},
  132. seed = 2721,
  133. octaves = 4,
  134. persist = 0.7,
  135. lacunarity = 2.1,
  136. }
  137. stoneworld.noise3param2d = {
  138. offset = 0,
  139. scale = 1,
  140. spread = {x=64, y=64, z=64},
  141. seed = 1248,
  142. octaves = 4,
  143. persist = 0.7,
  144. lacunarity = 1.5,
  145. }
  146. stoneworld.noise4param3d = {
  147. offset = 0,
  148. scale = 1,
  149. spread = {x=64, y=64, z=64},
  150. seed = 1762,
  151. octaves = 5,
  152. persist = 0.7,
  153. lacunarity = 1.5,
  154. }
  155. -- Used to limit where lava fortresses may spawn.
  156. stoneworld.noise5param3d = {
  157. offset = 0,
  158. scale = 1,
  159. spread = {x=1024, y=128, z=1024},
  160. seed = 7218,
  161. octaves = 4,
  162. persist = 0.5,
  163. lacunarity = 2.0,
  164. }
  165. -- Adamantine spires.
  166. stoneworld.noise6param2d = {
  167. -- Applying offset makes the spires rare, without messing with their size,
  168. -- as adjusting 'spread' would do.
  169. offset = -0.200,
  170. scale = 1,
  171. spread = {x=128, y=128, z=128},
  172. seed = 17355,
  173. octaves = 7,
  174. persist = 0.5,
  175. lacunarity = 1.9,
  176. }
  177. --------------------------------------------------------------------------------
  178. stoneworld.generate_realm = function(minp, maxp, seed)
  179. local nbeg = stoneworld.REALM_START
  180. local nend = stoneworld.REALM_END
  181. -- Don't run for out-of-bounds mapchunks.
  182. if minp.y > nend or maxp.y < nbeg then
  183. return
  184. end
  185. -- Grab the voxel manipulator.
  186. -- Read current map data.
  187. local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
  188. vm:get_data(vm_data)
  189. vm:get_light_data(vm_light)
  190. -- Actual emerged area should be bigger than the chunk we're generating!
  191. assert(emin.y < minp.y and emin.x < minp.x and emin.z < minp.z)
  192. assert(emax.y > maxp.y and emax.x > maxp.x and emax.z > maxp.z)
  193. -- Start out by overgenerating by 1 node.
  194. local x1 = maxp.x + 1
  195. local y1 = maxp.y + 1
  196. local z1 = maxp.z + 1
  197. local x0 = minp.x - 1
  198. local y0 = minp.y - 1
  199. local z0 = minp.z - 1
  200. local max_area = VoxelArea:new {MinEdge=emin, MaxEdge=emax}
  201. local min_area = VoxelArea:new {MinEdge={x=x0, y=y0, z=z0}, MaxEdge={x=x1, y=y1, z=z1}}
  202. -- Compute side lengths.
  203. local side_len_x = ((x1-x0)+1)
  204. local side_len_y = ((y1-y0)+1)
  205. local side_len_z = ((z1-z0)+1)
  206. local sides2D = {x=side_len_x, y=side_len_z}
  207. local sides3D = {x=side_len_x, y=side_len_z, z=side_len_y}
  208. local bp2d = {x=x0, y=z0}
  209. local bp3d = {x=x0, y=y0, z=z0}
  210. local pr = PseudoRandom(seed + 7114)
  211. ------------------------------------------------------------------------------
  212. -- Initialize cave perlin noise objects.
  213. for k, v in ipairs(stoneworld.caves) do
  214. v.perlin_route = v.perlin_route or minetest.get_perlin_map(v.noise_route, sides2D)
  215. v.perlin_height = v.perlin_height or minetest.get_perlin_map(v.noise_height, sides2D)
  216. end
  217. -- Calculate bulk perlin noise for caves.
  218. for k, v in ipairs(stoneworld.caves) do
  219. -- Optimization: each cave network only goes up or down not more than 70
  220. -- nodes, so we can skip calculating the noise for cave networks which won't
  221. -- get used. We do need to set a flag so we know which ones are "good".
  222. local good = true
  223. if minp.y > (nbeg + v.y_level + 70) or maxp.y < (nbeg + v.y_level - 70) then
  224. good = false
  225. end
  226. if good then
  227. v.perlin_route:get_2d_map_flat(bp2d, v.route_map)
  228. v.perlin_height:get_2d_map_flat(bp2d, v.height_map)
  229. v.good = true
  230. else
  231. v.good = false
  232. end
  233. end
  234. ------------------------------------------------------------------------------
  235. -- Initialize cavern perlin noise objects.
  236. for k, v in ipairs(stoneworld.caverns) do
  237. v.perlin_ceiling = v.perlin_ceiling or minetest.get_perlin_map(v.noise_ceiling, sides2D)
  238. v.perlin_floor = v.perlin_floor or minetest.get_perlin_map(v.noise_floor, sides2D)
  239. v.perlin_level = v.perlin_level or minetest.get_perlin_map(v.noise_level, sides2D)
  240. end
  241. -- Calculate bulk perlin noise for caverns
  242. for k, v in ipairs(stoneworld.caverns) do
  243. -- Optimization: each cavern network only goes up or down not more than 150
  244. -- nodes, so we can skip calculating the noise for cave networks which won't
  245. -- get used. We do need to set a flag so we know which ones are "good".
  246. local good = true
  247. if minp.y > (nbeg + v.y_level + 150) or maxp.y < (nbeg + v.y_level - 150) then
  248. good = false
  249. end
  250. if good then
  251. v.perlin_ceiling:get_2d_map_flat(bp2d, v.ceiling_map)
  252. v.perlin_floor:get_2d_map_flat(bp2d, v.floor_map)
  253. v.perlin_level:get_2d_map_flat(bp2d, v.level_map)
  254. v.good = true
  255. else
  256. v.good = false
  257. end
  258. end
  259. ------------------------------------------------------------------------------
  260. -- Get noisemaps.
  261. perlin1 = perlin1 or minetest.get_perlin_map(stoneworld.noise1param2d, sides2D)
  262. perlin1:get_2d_map_flat(bp2d, noisemap1)
  263. perlin3 = perlin3 or minetest.get_perlin_map(stoneworld.noise3param2d, sides2D)
  264. perlin3:get_2d_map_flat(bp2d, noisemap3)
  265. perlin4 = perlin4 or minetest.get_perlin_map(stoneworld.noise4param3d, sides3D)
  266. perlin4:get_3d_map_flat(bp3d, noisemap4)
  267. perlin5 = perlin5 or minetest.get_perlin_map(stoneworld.noise5param3d, sides3D)
  268. perlin5:get_3d_map_flat(bp3d, noisemap5)
  269. perlin6 = perlin6 or minetest.get_perlin_map(stoneworld.noise6param2d, sides2D)
  270. perlin6:get_2d_map_flat(bp2d, noisemap6)
  271. -- Localize commonly used functions for speed.
  272. local floor = math.floor
  273. local ceil = math.ceil
  274. local abs = math.abs
  275. local min = math.min
  276. local max = math.max
  277. -- Flat set if we are to spawn a fortress in this mapchunk.
  278. -- Note: fortress WILL extend outside the mapchunk!
  279. local spawn_fortress = false
  280. local fortress_y = 0
  281. -- First mapgen pass. Generate stone, passages, caverns, lava, and bedrock.
  282. -- Use slightly overgenerated coordinates to generate material 1 node outside
  283. -- the normal minp/maxp bounds. This makes it possible for the second mapgen
  284. -- pass (decorations) to get what is at the edge of a neighbor chunk.
  285. for z = z0, z1 do
  286. for x = x0, x1 do
  287. -- Get index into 2D noise arrays.
  288. local nx = (x - x0)
  289. local nz = (z - z0)
  290. local n2d = (side_len_z*nz+nx)
  291. -- Lua arrays start indexing at 1, not 0. Urrrrgh.
  292. n2d = n2d + 1
  293. local miny = y0
  294. local maxy = y1
  295. -- Clamp realm end/start Y-values.
  296. miny = max(miny, nbeg)
  297. maxy = min(maxy, nend)
  298. -- Get 2D noise values.
  299. local n1 = noisemap1[n2d]
  300. local n2 = noisemap3[n2d]
  301. local n6 = noisemap6[n2d]
  302. -- Pass through column.
  303. for y = miny, maxy do
  304. local vp = max_area:index(x, y, z)
  305. local cid = vm_data[vp]
  306. local nid = c_stone
  307. -- Don't overwrite previously existing stuff (non-ignore, non-air).
  308. -- This avoids ruining schematics that were previously placed, or other
  309. -- mapchunks.
  310. if (cid == c_air or cid == c_ignore) then
  311. -- Get index into 3D noise arrays.
  312. local n3d = min_area:index(x, y, z)
  313. local n3 = noisemap5[n3d]
  314. local n4 = noisemap4[n3d]
  315. -- Carve long winding caves.
  316. local caves = stoneworld.caves
  317. for k = 1, #caves do
  318. -- Skip caves which aren't part of this map chunk.
  319. if caves[k].good then
  320. -- Initial cave noise values.
  321. local c1 = caves[k].route_map[n2d]
  322. local c2 = caves[k].height_map[n2d]
  323. local yl = caves[k].y_level
  324. -- Basic cave parameters: Y-level, passage height.
  325. local cnoise1 = abs(c1)
  326. local cnoise2 = c1
  327. local clevel = (nbeg + yl + floor(c2 * 50)) + floor(n1 * 2)
  328. local cheight = 5 + abs(floor(n1 * 3))
  329. -- Modify cave height.
  330. cheight = cheight + floor(n4 * 2)
  331. -- Modifiers for roughening the rounding and making it less predictable.
  332. local z1 = abs(floor(n1))
  333. local z2 = abs(floor(n2))
  334. -- Limit determines the thickness of the cave passages.
  335. local limit = 0.10
  336. local cnoise
  337. local go = false
  338. if cnoise1 <= limit then
  339. cnoise = cnoise1
  340. go = true
  341. end
  342. if go then
  343. -- This bit of math is just to round off the sharp edges of the
  344. -- cave passages. Calculate cave top/bottom Y-values.
  345. local n = abs(floor((cnoise / limit) * (cheight / 2)))
  346. local bot = (clevel + n + z1)
  347. local top = (clevel + cheight - n - z2)
  348. if y >= bot and y <= top then
  349. nid = c_air
  350. end
  351. end
  352. end
  353. end
  354. -- Adamantine noise-level trigger.
  355. local spn = n6 + (n4 / 15)
  356. local spire_start = 1.080
  357. -- Carve caverns.
  358. local caverns = stoneworld.caverns
  359. for k = 1, #caverns do
  360. -- Skip caverns which aren't part of this map chunk.
  361. if caverns[k].good then
  362. -- Initial cavern noise values.
  363. local c1 = caverns[k].ceiling_map[n2d]
  364. local c2 = caverns[k].floor_map[n2d]
  365. local c3 = caverns[k].level_map[n2d]
  366. local yl = caverns[k].y_level
  367. -- Basic cavern parameters.
  368. local clevel = (nbeg + yl + floor(c3 * 40))
  369. local bot = floor(clevel - 15 + (c2 * 5) + n2 * 6)
  370. local top = floor(clevel + 15 + (c1 * 15) + n1 * 6)
  371. local lava = (nbeg + yl - 30)
  372. -- Pinch together floor and ceiling in the vicinity of spires.
  373. local shell_start = (spire_start - 0.200)
  374. if spn > shell_start then
  375. local tpinch = (spn - shell_start) * 50
  376. local bpinch = (spn - shell_start) * 70
  377. top = top - tpinch
  378. bot = bot + bpinch
  379. end
  380. -- If ceiling is far enough up, and bottom is below the lava
  381. -- ocean, then we have a chance to spawn a lava fortress here.
  382. if not spawn_fortress then
  383. if (top - bot) >= 50 and bot <= (lava - 5) then
  384. -- Use perlin noise to limit fortress spawning to regions.
  385. -- Using abs() will cause fortresses to spawn in winding strings.
  386. if abs(n3) < 0.1 then
  387. -- Only for the mapchunk intersecting the lava ocean.
  388. -- If we didn't do this check, it would be possible that the
  389. -- mapchunk ABOVE (or below) could also cause a fortress to
  390. -- spawn, causing a high probability of overlapping fortresses.
  391. if y == lava then
  392. spawn_fortress = true
  393. fortress_y = lava + 10
  394. end
  395. end
  396. end
  397. end
  398. -- Raise cavern ceiling over the lava ocean.
  399. -- Need to make room for the fortress spawner.
  400. local expanse_y = (lava + 15)
  401. if bot < expanse_y then
  402. top = top + (expanse_y - bot) * 2
  403. end
  404. if y >= bot and y <= top then
  405. nid = c_air
  406. end
  407. if y >= bot and y <= lava then
  408. nid = c_lava
  409. end
  410. end
  411. end
  412. -- Lava pools sometimes between rubble and basalt.
  413. if y <= (nbeg + 3) or y >= (nend - 3) then
  414. nid = c_lava
  415. end
  416. local l1 = ceil(abs(n1) * 6)
  417. local l2 = ceil(abs(n2) * 6)
  418. -- Rubble layer between bedrock and basalt.
  419. if y <= (nbeg + l1 + l2) or y >= (nend - l1 - l2) then
  420. nid = c_cobble
  421. end
  422. -- Adamantine spires.
  423. if spn > (spire_start + 0.070) then
  424. local m = floor(y + n4 * 6) % 10
  425. if m >= 0 and m <= 2 then
  426. nid = c_adamant
  427. elseif m == 3 then
  428. nid = c_lava2
  429. else
  430. nid = c_air
  431. end
  432. elseif spn > (spire_start + 0.040) then
  433. nid = c_adamant
  434. elseif spn > (spire_start + 0.020) then
  435. nid = c_obsidian2
  436. elseif spn > (spire_start + 0.000) then
  437. nid = c_obsidian
  438. end
  439. -- Generate bedrock floor and ceiling. Highest priority.
  440. if y <= (nbeg + l1) or y >= (nend - l1) then
  441. nid = c_bedrock
  442. end
  443. -- Write content ID.
  444. vm_data[vp] = nid
  445. end
  446. end -- End column loop.
  447. end
  448. end
  449. -- Second mapgen pass. Add context-specific modifications and decorations.
  450. -- No overgeneration, stay within minp/maxp bounds.
  451. for z = z0 + 1, z1 - 1 do
  452. for x = x0 + 1, x1 - 1 do
  453. local miny = (y0 + 1)
  454. local maxy = (y1 - 1)
  455. -- Clamp realm end/start Y-values.
  456. miny = max(miny, nbeg)
  457. maxy = min(maxy, nend)
  458. local worm = pr:next(1, 100) < 15
  459. local fungus = pr:next(1, 100) < 15
  460. for y = miny, maxy do
  461. local vd = max_area:index(x, y - 1, z)
  462. local vp = max_area:index(x, y, z)
  463. local vu = max_area:index(x, y + 1, z)
  464. local vn = max_area:index(x, y, z + 1)
  465. local vs = max_area:index(x, y, z - 1)
  466. local vw = max_area:index(x - 1, y, z)
  467. local ve = max_area:index(x + 1, y, z)
  468. local vne = max_area:index(x + 1, y, z + 1)
  469. local vnw = max_area:index(x - 1, y, z + 1)
  470. local vse = max_area:index(x + 1, y, z - 1)
  471. local vsw = max_area:index(x - 1, y, z - 1)
  472. -- Get what's here already.
  473. local cd = vm_data[vd]
  474. local cp = vm_data[vp]
  475. local cu = vm_data[vu]
  476. local cn = vm_data[vn]
  477. local cs = vm_data[vs]
  478. local cw = vm_data[vw]
  479. local ce = vm_data[ve]
  480. local cne = vm_data[vne]
  481. local cnw = vm_data[vnw]
  482. local cse = vm_data[vse]
  483. local csw = vm_data[vsw]
  484. local nid = cp
  485. -- Stone with air both above and below becomes air.
  486. if cp == c_stone and cu == c_air and cd == c_air then
  487. nid = c_air
  488. end
  489. -- Stone next to lava becomes obsidian, but requires stone below.
  490. if cp == c_stone and cd == c_stone and (cn == c_lava or cs == c_lava or
  491. cw == c_lava or ce == c_lava or cnw == c_lava or cne == c_lava or
  492. csw == c_lava or cse == c_lava or cu == c_lava) then
  493. nid = c_obsidian
  494. end
  495. -- Stone with air above and more stone below becomes rubble.
  496. -- But not if already turned to obsidian.
  497. if nid ~= c_obsidian then
  498. if cp == c_stone and cu == c_air and cd == c_stone then
  499. nid = c_cobble
  500. -- Sometimes place sunstone.
  501. if pr:next(1, 300) == 1 then
  502. nid = c_glow
  503. end
  504. end
  505. end
  506. -- Place glow worms on ceilings.
  507. if worm then
  508. if cp == c_air and cu == c_stone then
  509. nid = c_worm
  510. end
  511. end
  512. -- Place fungus on floors.
  513. if fungus then
  514. if cp == c_air and (cd == c_stone or cd == c_cobble) then
  515. nid = c_fungus
  516. end
  517. end
  518. -- Write content ID.
  519. vm_data[vp] = nid
  520. end
  521. end
  522. end
  523. -- Lighting pass. Set everything dark.
  524. for z = emin.z, emax.z do
  525. for x = emin.x, emax.x do
  526. for y = emin.y, emax.y do
  527. local vp = max_area:index(x, y, z)
  528. vm_light[vp] = 0
  529. end
  530. end
  531. end
  532. -- Finalize voxel manipulator.
  533. vm:set_data(vm_data)
  534. minetest.generate_ores(vm)
  535. vm:set_light_data(vm_light)
  536. vm:calc_lighting({x=emin.x, y=emin.y, z=emin.z}, {x=emax.x, y=maxp.y, z=emax.z}, true)
  537. vm:write_to_map()
  538. vm:update_liquids()
  539. -- A chance to spawn a fortress. Do NOT spawn a fortress in every mapchunk
  540. -- that's eligible, that will crowd everything else out!
  541. if spawn_fortress and pr:next(1, 5) == 1 then
  542. local p = vector.round({
  543. x = floor((x0 + x1) / 2),
  544. y = fortress_y,
  545. z = floor((z0 + z1) / 2),
  546. })
  547. -- Lock X,Z coords to values divisible by 11. This is the fortress step size
  548. -- for "default". Doing this ensures fortresses in adjacent chunks line up.
  549. p.x = p.x - (p.x % 11)
  550. p.z = p.z - (p.z % 11)
  551. minetest.after(0, function()
  552. fortress.generate(p, "default")
  553. end)
  554. end
  555. end
  556. --------------------------------------------------------------------------------
  557. if not stoneworld.registered then
  558. -- Register the mapgen callback.
  559. minetest.register_on_generated(function(...)
  560. stoneworld.generate_realm(...)
  561. end)
  562. dofile(stoneworld.modpath .. "/nodes.lua")
  563. dofile(stoneworld.modpath .. "/ores.lua")
  564. dofile(stoneworld.modpath .. "/items.lua")
  565. local c = "stoneworld:core"
  566. local f = stoneworld.modpath .. "/init.lua"
  567. reload.register_file(c, f, false)
  568. stoneworld.registered = true
  569. end