mapgen.lua 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. -- mods/default/mapgen.lua
  2. local mapgen_name = minetest.get_mapgen_setting("mg_name")
  3. local lott_v6 = minetest.setting_getbool("lott_v6") or false
  4. if mapgen_name == "singlenode" or (mapgen_name == "v6" and lott_v6 ~= true) then
  5. minetest.set_mapgen_setting("mg_name", "v7", true)
  6. end
  7. local flags = minetest.get_mapgen_setting("mgv7_spflags")
  8. if flags ~= nil then
  9. local c1, c2 = flags:find("floatlands")
  10. if c1 and c2 and not flags:find("nofloatlands") then
  11. minetest.set_mapgen_setting("mgv7_spflags",
  12. flags:sub(1, c1-1) .. flags:sub(c2+1), true)
  13. end
  14. end
  15. --
  16. -- Aliases for map generator outputs
  17. --
  18. -- stone replecment node
  19. minetest.register_node("default:mapgen_stone", {
  20. description = "Mapgen Stone",
  21. tiles = {"default_stone.png"},
  22. is_ground_content = true,
  23. groups = {cracky=3, stone=1, not_in_creative_inventory=1},
  24. drop = 'default:cobble',
  25. legacy_mineral = true,
  26. sounds = default.node_sound_stone_defaults(),
  27. })
  28. minetest.register_alias("mapgen_stone", "default:stone")
  29. minetest.register_alias("mapgen_tree", "air")
  30. minetest.register_alias("mapgen_leaves", "air")
  31. minetest.register_alias("mapgen_jungletree", "air")
  32. minetest.register_alias("mapgen_jungleleaves", "air")
  33. minetest.register_alias("mapgen_apple", "air")
  34. minetest.register_alias("mapgen_water_source", "default:water_source")
  35. minetest.register_alias("mapgen_river_water_source", "default:river_water_source")
  36. minetest.register_alias("mapgen_dirt", "default:mapgen_stone")
  37. minetest.register_alias("mapgen_gravel", "default:gravel")
  38. minetest.register_alias("mapgen_clay", "default:mapgen_stone")
  39. minetest.register_alias("mapgen_lava_source", "default:lava_source")
  40. minetest.register_alias("mapgen_cobble", "default:cobble")
  41. minetest.register_alias("mapgen_mossycobble", "default:mossycobble")
  42. minetest.register_alias("mapgen_dirt_with_grass", "default:mapgen_stone")
  43. minetest.register_alias("mapgen_junglegrass", "air")
  44. minetest.register_alias("mapgen_stone_with_coal", "default:stone_with_coal")
  45. minetest.register_alias("mapgen_stone_with_iron", "default:stone_with_iron")
  46. minetest.register_alias("mapgen_mese", "default:mese")
  47. minetest.register_alias("mapgen_sand", "default:stone")
  48. minetest.register_alias("mapgen_sandstone", "default:sandstone")
  49. minetest.register_alias("mapgen_desert_sand", "default:mapgen_stone")
  50. -- This is needed because we don't want desert stone in v6, in desert areas,
  51. -- and in other mapgens, it messes dungeon gen up. Mapgen madness!
  52. if mapgen_name == "v6" then
  53. minetest.register_alias("mapgen_desert_stone", "default:stone")
  54. else
  55. minetest.register_alias("mapgen_desert_stone", "default:desert_stone")
  56. end
  57. minetest.register_alias("mapgen_stair_cobble", "stairs:stair_cobble")
  58. minetest.register_alias("mapgen_sandstonebrick", "default:cobble")
  59. minetest.register_alias("mapgen_stair_sandstonebrick", "stairs:stair_cobble")
  60. --
  61. -- Ore generation
  62. --
  63. local wl = tonumber(minetest.get_mapgen_setting("water_level")) or 1
  64. minetest.register_ore({
  65. ore_type = "scatter",
  66. ore = "default:stone_with_coal",
  67. wherein = "default:stone",
  68. clust_scarcity = 8*8*8,
  69. clust_num_ores = 8,
  70. clust_size = 3,
  71. y_min = wl - 31000,
  72. y_max = wl + 64,
  73. })
  74. minetest.register_ore({
  75. ore_type = "scatter",
  76. ore = "default:stone_with_coal",
  77. wherein = "default:stone",
  78. clust_scarcity = 24*24*24,
  79. clust_num_ores = 27,
  80. clust_size = 6,
  81. y_min = wl - 31000,
  82. y_max = wl,
  83. })
  84. minetest.register_ore({
  85. ore_type = "scatter",
  86. ore = "default:stone_with_iron",
  87. wherein = "default:stone",
  88. clust_scarcity = 12*12*12,
  89. clust_num_ores = 3,
  90. clust_size = 2,
  91. y_min = wl - 15,
  92. y_max = wl + 2,
  93. })
  94. minetest.register_ore({
  95. ore_type = "scatter",
  96. ore = "default:stone_with_iron",
  97. wherein = "default:stone",
  98. clust_scarcity = 9*9*9,
  99. clust_num_ores = 5,
  100. clust_size = 3,
  101. y_min = wl - 63,
  102. y_max = wl - 16,
  103. })
  104. minetest.register_ore({
  105. ore_type = "scatter",
  106. ore = "default:stone_with_iron",
  107. wherein = "default:stone",
  108. clust_scarcity = 7*7*7,
  109. clust_num_ores = 5,
  110. clust_size = 3,
  111. y_min = wl - 31000,
  112. y_max = wl - 64,
  113. })
  114. minetest.register_ore({
  115. ore_type = "scatter",
  116. ore = "default:stone_with_iron",
  117. wherein = "default:stone",
  118. clust_scarcity = 24*24*24,
  119. clust_num_ores = 27,
  120. clust_size = 6,
  121. y_min = wl - 31000,
  122. y_max = wl - 64,
  123. })
  124. --[[
  125. minetest.register_ore({
  126. ore_type = "scatter",
  127. ore = "default:stone_with_mese",
  128. wherein = "default:stone",
  129. clust_scarcity = 18*18*18,
  130. clust_num_ores = 3,
  131. clust_size = 2,
  132. y_min = wl - 255,
  133. y_max = wl - 64,
  134. })
  135. minetest.register_ore({
  136. ore_type = "scatter",
  137. ore = "default:stone_with_mese",
  138. wherein = "default:stone",
  139. clust_scarcity = 14*14*14,
  140. clust_num_ores = 5,
  141. clust_size = 3,
  142. y_min = wl - 31000,
  143. y_max = wl - 256,
  144. })
  145. minetest.register_ore({
  146. ore_type = "scatter",
  147. ore = "default:mese",
  148. wherein = "default:stone",
  149. clust_scarcity = 36*36*36,
  150. clust_num_ores = 3,
  151. clust_size = 2,
  152. y_min = wl - 31000,
  153. y_max = wl- 1024,
  154. })
  155. ]]
  156. minetest.register_ore({
  157. ore_type = "scatter",
  158. ore = "default:stone_with_gold",
  159. wherein = "default:stone",
  160. clust_scarcity = 15*15*15,
  161. clust_num_ores = 3,
  162. clust_size = 2,
  163. y_min = wl - 255,
  164. y_max = wl - 64,
  165. })
  166. minetest.register_ore({
  167. ore_type = "scatter",
  168. ore = "default:stone_with_gold",
  169. wherein = "default:stone",
  170. clust_scarcity = 13*13*13,
  171. clust_num_ores = 5,
  172. clust_size = 3,
  173. y_min = wl - 31000,
  174. y_max = wl - 256,
  175. })
  176. minetest.register_ore({
  177. ore_type = "scatter",
  178. ore = "default:stone_with_copper",
  179. wherein = "default:stone",
  180. clust_scarcity = 12*12*12,
  181. clust_num_ores = 4,
  182. clust_size = 3,
  183. y_min = wl - 63,
  184. y_max = wl - 16,
  185. })
  186. minetest.register_ore({
  187. ore_type = "scatter",
  188. ore = "default:stone_with_copper",
  189. wherein = "default:stone",
  190. clust_scarcity = 9*9*9,
  191. clust_num_ores = 5,
  192. clust_size = 3,
  193. y_min = wl - 31000,
  194. y_max = wl - 64,
  195. })
  196. minetest.register_ore({
  197. ore_type = "scatter",
  198. ore = "default:clay",
  199. wherein = "default:sand",
  200. clust_scarcity = 15*15*15,
  201. clust_num_ores = 64,
  202. clust_size = 5,
  203. y_max = wl,
  204. y_min = wl - 10,
  205. })
  206. function default.generate_ore(name, wherein, minp, maxp, seed, chunks_per_volume, chunk_size, ore_per_chunk, y_min, y_max)
  207. minetest.log('action', "WARNING: default.generate_ore is deprecated")
  208. if maxp.y < y_min or minp.y > y_max then
  209. return
  210. end
  211. local y_min = math.max(minp.y, y_min)
  212. local y_max = math.min(maxp.y, y_max)
  213. if chunk_size >= y_max - y_min + 1 then
  214. return
  215. end
  216. local volume = (maxp.x-minp.x+1)*(y_max-y_min+1)*(maxp.z-minp.z+1)
  217. local pr = PseudoRandom(seed)
  218. local num_chunks = math.floor(chunks_per_volume * volume)
  219. local inverse_chance = math.floor(chunk_size*chunk_size*chunk_size / ore_per_chunk)
  220. --print("generate_ore num_chunks: "..dump(num_chunks))
  221. for i=1,num_chunks do
  222. local y0 = pr:next(y_min, y_max-chunk_size+1)
  223. if y0 >= y_min and y0 <= y_max then
  224. local x0 = pr:next(minp.x, maxp.x-chunk_size+1)
  225. local z0 = pr:next(minp.z, maxp.z-chunk_size+1)
  226. local p0 = {x=x0, y=y0, z=z0}
  227. for x1=0,chunk_size-1 do
  228. for y1=0,chunk_size-1 do
  229. for z1=0,chunk_size-1 do
  230. if pr:next(1,inverse_chance) == 1 then
  231. local x2 = x0+x1
  232. local y2 = y0+y1
  233. local z2 = z0+z1
  234. local p2 = {x=x2, y=y2, z=z2}
  235. if minetest.get_node(p2).name == wherein then
  236. minetest.set_node(p2, {name=name})
  237. end
  238. end
  239. end
  240. end
  241. end
  242. end
  243. end
  244. --print("generate_ore done")
  245. end