init.lua 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. local mn = "rockgen"
  2. local modpath = minetest.get_modpath(mn)
  3. local has_technic = false
  4. if nil ~= minetest.get_modpath("technic") then
  5. has_technic = true
  6. end
  7. local has_moreores = false
  8. if nil ~= minetest.get_modpath("moreores") then
  9. has_moreores = true
  10. end
  11. --dofile(modpath.."/rocks.lua")
  12. local vc = 64
  13. local vc2 = 64
  14. local np_caves = {
  15. offset = 0,
  16. scale = 1,
  17. spread = {x=64, y=64, z=64}, --squash the layers a bit
  18. seed = 54333,
  19. octaves = 3,
  20. persist = 0.67
  21. }
  22. local np_caves2 = {
  23. offset = 0,
  24. scale = 1,
  25. spread = {x=64, y=64, z=64}, --squash the layers a bit
  26. seed = 453467,
  27. octaves = 5,
  28. persist = 0.67
  29. }
  30. local np_stone = {
  31. offset = .5,
  32. scale = 1,
  33. spread = {x=256, y=128, z=256}, --squash the layers a bit
  34. seed = 34033,
  35. octaves = 2,
  36. persist = 0.67
  37. }
  38. local np_terrain1 = {
  39. offset = 0,
  40. scale = 1,
  41. spread = {x=vc, y=vc, z=vc},
  42. seed = 5900033,
  43. octaves = 1,
  44. persist = 0.67
  45. }
  46. local np_terrain2 = {
  47. offset = 0,
  48. scale = 1,
  49. spread = {x=vc, y=vc, z=vc},
  50. seed = 59002,
  51. octaves = 1,
  52. persist = 0.67
  53. }
  54. local np_terrain3 = {
  55. offset = 0,
  56. scale = 1,
  57. spread = {x=vc, y=vc, z=vc},
  58. seed = 5900232,
  59. octaves = 1,
  60. persist = 0.67
  61. }
  62. local np_terrain4 = {
  63. offset = 0,
  64. scale = 1,
  65. spread = {x=vc, y=vc, z=vc},
  66. seed = 334502,
  67. octaves = 1,
  68. persist = 0.67
  69. }
  70. local np_terrain5 = {
  71. offset = 0,
  72. scale = 1,
  73. spread = {x=vc, y=vc, z=vc},
  74. seed = 756742,
  75. octaves = 1,
  76. persist = 0.67
  77. }
  78. local np_abundance1 = {
  79. offset = 0,
  80. scale = 8,
  81. spread = {x=256, y=256, z=256},
  82. seed = 4876,
  83. octaves = 3,
  84. persist = 0.60
  85. }
  86. --[[
  87. minetest.register_node( "mapgen:glowshroom", {
  88. description = "Glowing Mushroom",
  89. tiles = { "default_bookshelf.png" },
  90. is_ground_content = true,
  91. sounds = default.node_sound_wood_defaults(),
  92. groups = {choppy=2,flammable=2},
  93. light_source = LIGHT_MAX-3,
  94. node_box = {
  95. type = "fixed",
  96. fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7},
  97. },
  98. selection_box = {
  99. type = "fixed",
  100. fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7},
  101. },
  102. })]]
  103. --mgv7_np_terrain_base = 4, 120, (1300, 1300, 1300), 82341, 6, 0.7
  104. --mgv7_np_terrain_alt = 4, 70, (1000, 1000, 1000), 5934, 3, 0.6
  105. --[[ weird cool cliff world
  106. mgv7_np_terrain_base = 4, 520, (1300, 1300, 1300), 82341, 3, 0.7
  107. mgv7_np_terrain_alt = 4, 525, (1228, 1228, 1228), 5934, 1, 0.6
  108. mgv7_np_height_select = -1, 100, (1250, 1250, 1250), 4213, 5, 0.7
  109. mgv7_np_mount_height = 400, 700, (500, 500, 500), 72449, 4, 0.6
  110. ]]
  111. -- minetest.register_on_respawnplayer(function(player)
  112. -- player:setpos({x=571, y=50, z=70})
  113. -- return true
  114. -- end)
  115. local scaler = 4
  116. local choose = function(cond, a, b)
  117. if cond then
  118. return a
  119. else
  120. return b
  121. end
  122. end
  123. core.clear_registered_ores()
  124. minetest.register_on_generated(function(minp, maxp, seed)
  125. -- if maxp.y > 0 then
  126. -- return
  127. -- end
  128. local x1 = maxp.x
  129. local y1 = maxp.y
  130. local z1 = maxp.z
  131. local x0 = minp.x
  132. local y0 = minp.y
  133. local z0 = minp.z
  134. local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
  135. local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
  136. local data = vm:get_data()
  137. -- general
  138. local c_water = minetest.get_content_id("default:water_source")
  139. local c_water = minetest.get_content_id("default:river_water_source")
  140. local c_stone = minetest.get_content_id("default:stone")
  141. local c_desertstone = minetest.get_content_id("default:desert_stone")
  142. local c_sandstone = minetest.get_content_id("default:sandstone")
  143. local c_air = minetest.get_content_id("air")
  144. local c_wood = minetest.get_content_id("default:wood")
  145. local c_glass = minetest.get_content_id("default:glass")
  146. local c_dirt = minetest.get_content_id("default:dirt")
  147. local c_lava = minetest.get_content_id("default:lava_source")
  148. local c_mossycobble = minetest.get_content_id("default:mossycobble")
  149. -- ores
  150. local c_mese = minetest.get_content_id("default:stone_with_mese")
  151. local c_iron = minetest.get_content_id("default:stone_with_iron")
  152. local c_coal = minetest.get_content_id("default:stone_with_coal")
  153. local c_coalblock = minetest.get_content_id("default:coalblock")
  154. local c_copper = minetest.get_content_id("default:stone_with_copper")
  155. local c_diamond = minetest.get_content_id("default:stone_with_diamond")
  156. local c_gold = minetest.get_content_id("default:stone_with_gold")
  157. local c_tin = minetest.get_content_id("default:stone_with_tin")
  158. local c_hematite = minetest.get_content_id("geology:hematite")
  159. local c_uranium
  160. local c_chromium
  161. local c_zinc
  162. local c_silver
  163. local c_mithril
  164. if has_technic == true then
  165. c_uranium = minetest.get_content_id("technic:mineral_uranium")
  166. c_chromium = minetest.get_content_id("technic:mineral_chromium")
  167. c_zinc = minetest.get_content_id("technic:mineral_zinc")
  168. else
  169. c_uranium = minetest.get_content_id("default:obsidian_glass")
  170. c_chromium = minetest.get_content_id("default:stone_with_copper")
  171. c_zinc = minetest.get_content_id("default:stone_with_tin")
  172. end
  173. if has_moreores == true then
  174. c_silver = minetest.get_content_id("moreores:mineral_silver")
  175. c_mithril = minetest.get_content_id("moreores:mineral_mithril")
  176. else
  177. c_silver = minetest.get_content_id("default:stone_with_gold")
  178. c_mithril = minetest.get_content_id("default:stone_with_mese")
  179. end
  180. -- geologic
  181. local c_obglass = minetest.get_content_id("default:obsidian_glass")
  182. local c_sandstone = minetest.get_content_id("default:sandstone")
  183. local c_gravel = minetest.get_content_id("default:gravel")
  184. local c_desertstone = minetest.get_content_id("default:desert_stone")
  185. local c_granite = minetest.get_content_id("geology:granite")
  186. local c_marble = minetest.get_content_id("geology:marble")
  187. local c_slate = minetest.get_content_id("geology:slate")
  188. local c_gneiss = minetest.get_content_id("geology:gneiss")
  189. local c_basalt = minetest.get_content_id("geology:basalt")
  190. local c_schist = minetest.get_content_id("geology:schist")
  191. local c_chalk = minetest.get_content_id("geology:chalk")
  192. local c_shale = minetest.get_content_id("geology:shale")
  193. local c_ors = minetest.get_content_id("geology:ors")
  194. local c_jade = minetest.get_content_id("geology:jade")
  195. local c_serpentine = minetest.get_content_id("geology:serpentine")
  196. local c_anthracite = minetest.get_content_id("geology:anthracite")
  197. local c_clay = minetest.get_content_id("default:clay")
  198. local c_torch = minetest.get_content_id("default:torch")
  199. --local c_shroom = minetest.get_content_id("mapgen:glowshroom")
  200. -- local c_lava = minetest.get_content_id("default:lava_source")
  201. local sidelen = x1 - x0 + 1
  202. local chulens = {x=sidelen, y=sidelen, z=sidelen}
  203. local minposxyz = {x=x0, y=y0, z=z0}
  204. local minposxz = {x=x0, y=z0}
  205. -- local nvals_caves = minetest.get_perlin_map(np_caves, chulens):get3dMap_flat(minposxyz)
  206. -- local nvals_caves2 = minetest.get_perlin_map(np_caves2, chulens):get3dMap_flat(minposxyz)
  207. local nvals_terrain_s = minetest.get_perlin_map(np_stone, chulens):get3dMap_flat(minposxyz)
  208. local nvals_terrain1 = minetest.get_perlin_map(np_terrain1, chulens):get3dMap_flat(minposxyz)
  209. local nvals_terrain2 = minetest.get_perlin_map(np_terrain2, chulens):get3dMap_flat(minposxyz)
  210. local nvals_terrain3 = minetest.get_perlin_map(np_terrain3, chulens):get3dMap_flat(minposxyz)
  211. local nvals_terrain4 = minetest.get_perlin_map(np_terrain4, chulens):get3dMap_flat(minposxyz)
  212. local nvals_terrain5 = minetest.get_perlin_map(np_terrain5, chulens):get3dMap_flat(minposxyz)
  213. local nvals_abundance1 = minetest.get_perlin_map(np_abundance1, chulens):get3dMap_flat(minposxyz)
  214. --[[
  215. .008 # holy fuck way too much
  216. .005 # thick consistent vein a few nodes in diameter
  217. .003 # continuous one node thick vein, occasinoally skips a node or becomes 2 thick
  218. .0015 # ores are spaced several nodes apart. easy to lose but easy to find again.
  219. ]]
  220. local thickness_abundant = .0025*scaler
  221. local thickness_normal = .0020*scaler
  222. local thickness_scarce = .0016*scaler
  223. local thickness_rare = .0011*scaler
  224. local nixyz = 1 -- 3D noise index
  225. for z = z0, z1 do -- for each xy plane progressing northwards
  226. for y = y0, y1 do -- for each x row progressing upwards
  227. local vi = area:index(x0, y, z)
  228. for x = x0, x1 do -- for each node do
  229. -- -- cave stuff
  230. -- local cave_density = math.abs(nvals_caves[nixyz])
  231. -- local cave_density2 = math.abs(nvals_caves2[nixyz])
  232. -- local cave_density = nvals_caves[nixyz]
  233. -- --local cave_density2 = nvals_caves2[nixyz]
  234. --
  235. -- if data[vi] == c_air
  236. -- and cave_density > .7
  237. -- and cave_density2 > .7
  238. -- then
  239. -- data[vi] = c_schist
  240. -- end
  241. if data[vi] == c_air and y < 0 then
  242. if math.random() < 0.1 and (data[vi-1] == c_mossycobble) then
  243. data[vi] = c_torch
  244. end
  245. end
  246. local dy_limit = 2500
  247. local dy_ratio = .5
  248. local da_ratio = .5
  249. local dc2 = (x * x) + (z * z)
  250. local dc_scale = .5 + ((dc2 / (200 * 200)) * .5)
  251. local dy_scale = math.max(0, math.min(dy_ratio + ((-y / dy_limit) * (1 - dy_ratio)), 1))
  252. local abundance1 = math.max(0, math.min(math.abs(nvals_abundance1[nixyz]), 1))
  253. local da_scale = math.max(0, math.min(da_ratio + (abundance1 * (1 - da_ratio)), 1))
  254. --print(abundance1)
  255. local thickness_abundant = .0025*scaler * dy_scale * da_scale
  256. local thickness_normal = .0020*scaler * dy_scale * da_scale
  257. local thickness_scarce = .0016*scaler * dy_scale * da_scale
  258. local thickness_rare = .0011*scaler * dy_scale * da_scale
  259. local on = data[vi]
  260. if on == c_stone or on == c_desertstone or on == c_sandstone
  261. -- or on == c_air or on == c_sand -- debug
  262. then
  263. --if on == c_air then
  264. local density_s = nvals_terrain_s[nixyz]
  265. --local density1_f = math.abs(nvals_terrain1[nixyz])
  266. local density1 = math.abs(nvals_terrain1[nixyz])
  267. local density2 = math.abs(nvals_terrain2[nixyz])
  268. local density3 = math.abs(nvals_terrain3[nixyz])
  269. local density4 = math.abs(nvals_terrain4[nixyz])
  270. local density5 = math.abs(nvals_terrain5[nixyz])
  271. --print(dc_scale)
  272. -- ore veins first
  273. if density1 < thickness_normal and density2 < thickness_normal then
  274. data[vi] = choose(dc2 > 5000*5000, c_mese, c_tin)
  275. elseif density1 < thickness_abundant and density3 < thickness_abundant then
  276. data[vi] = choose(dc2 > 1000*1000, c_iron, c_tin)
  277. elseif density1 < thickness_normal and density4 < thickness_normal then
  278. data[vi] = c_copper
  279. elseif density1 < thickness_rare and density5 < thickness_rare then
  280. data[vi] = choose(dc2 > 10000*10000, c_mithril, c_iron)
  281. elseif density2 < thickness_rare and density3 < thickness_rare then
  282. data[vi] = choose(dc2 > 2000*2000, c_diamond, c_mese)
  283. elseif density2 < thickness_scarce and density4 < thickness_scarce then
  284. data[vi] = choose(dc2 > 500*500, c_silver, c_copper)
  285. elseif density2 < thickness_normal and density5 < thickness_normal then
  286. data[vi] = c_tin
  287. elseif density3 < thickness_scarce and density4 < thickness_scarce then
  288. data[vi] = choose(y < 500, c_silver, c_copper)
  289. elseif density3 < thickness_normal and density5 < thickness_normal then
  290. data[vi] = choose(dc2 > 750*750, c_chromium, c_tin)
  291. elseif density4 < thickness_normal and density5 < thickness_normal then
  292. data[vi] = choose(dc2 > 500*500, c_zinc, c_tin)
  293. -- then ore pockets
  294. elseif density2 > 0.92 then
  295. data[vi] = c_uranium
  296. -- elseif true == true then data[vi] = c_air -- debug
  297. -- normal rocks
  298. elseif density_s > 1.25 then
  299. data[vi] = c_jade
  300. elseif density_s > 1.10 then
  301. data[vi] = c_serpentine
  302. elseif density_s > 1.00 then
  303. data[vi] = c_shale
  304. elseif density_s > 0.90 then
  305. data[vi] = c_granite
  306. elseif density_s > 0.89 then
  307. if density1 < thickness_normal or density2 < thickness_rare or density3 < thickness_rare or density4 < thickness_rare then
  308. data[vi] = c_gold
  309. else
  310. data[vi] = c_granite
  311. end
  312. elseif density_s > 0.80 then
  313. data[vi] = c_basalt
  314. elseif density_s > 0.702 then
  315. data[vi] = c_slate
  316. elseif density_s > 0.70 then
  317. data[vi] = c_anthracite
  318. elseif density_s > 0.60 then
  319. data[vi] = c_marble
  320. elseif density_s > 0.505 then
  321. data[vi] = c_gneiss
  322. elseif density_s > 0.40 and density2 > .7 then
  323. data[vi] = c_hematite
  324. elseif density_s > 0.40 then
  325. data[vi] = c_desertstone
  326. elseif density_s > 0.30 then
  327. data[vi] = c_sandstone
  328. elseif density_s > 0.202 then
  329. data[vi] = c_schist
  330. elseif density_s > 0.20 then
  331. data[vi] = c_gravel
  332. elseif density_s > 0.19 then
  333. data[vi] = c_coalblock
  334. elseif density_s > 0.188 then
  335. data[vi] = c_gravel
  336. elseif density_s > 0.10 then
  337. data[vi] = c_chalk
  338. elseif density_s > 0.00 then
  339. data[vi] = c_clay
  340. elseif density_s > -0.10 then
  341. data[vi] = c_ors
  342. else
  343. data[vi] = c_stone
  344. end
  345. --]]
  346. end
  347. nixyz = nixyz + 1 -- increment 3D noise index
  348. vi = vi + 1
  349. end
  350. end
  351. end
  352. vm:set_data(data)
  353. vm:set_lighting({day=0, night=0})
  354. vm:calc_lighting()
  355. vm:write_to_map(data)
  356. end)