1 -- mods/default/mapgen.lua
4 -- Aliases for map generator outputs
7 minetest.register_alias("mapgen_stone", "default:stone")
8 minetest.register_alias("mapgen_tree", "default:tree")
9 minetest.register_alias("mapgen_leaves", "default:leaves")
10 minetest.register_alias("mapgen_jungletree", "default:jungletree")
11 minetest.register_alias("mapgen_jungleleaves", "default:jungleleaves")
12 minetest.register_alias("mapgen_apple", "default:apple")
13 minetest.register_alias("mapgen_water_source", "default:water_source")
14 minetest.register_alias("mapgen_dirt", "default:dirt")
15 minetest.register_alias("mapgen_sand", "default:sand")
16 minetest.register_alias("mapgen_gravel", "default:gravel")
17 minetest.register_alias("mapgen_clay", "default:clay")
18 minetest.register_alias("mapgen_lava_source", "default:lava_source")
19 minetest.register_alias("mapgen_cobble", "default:cobble")
20 minetest.register_alias("mapgen_mossycobble", "default:mossycobble")
21 minetest.register_alias("mapgen_dirt_with_grass", "default:dirt_with_grass")
22 minetest.register_alias("mapgen_junglegrass", "default:junglegrass")
23 minetest.register_alias("mapgen_stone_with_coal", "default:stone_with_coal")
24 minetest.register_alias("mapgen_stone_with_iron", "default:stone_with_iron")
25 minetest.register_alias("mapgen_mese", "default:mese")
26 minetest.register_alias("mapgen_desert_sand", "default:desert_sand")
27 minetest.register_alias("mapgen_desert_stone", "default:desert_stone")
28 minetest.register_alias("mapgen_stair_cobble", "stairs:stair_cobble")
34 minetest.register_ore({
36 ore = "default:stone_with_coal",
37 wherein = "default:stone",
38 clust_scarcity = 8*8*8,
45 minetest.register_ore({
47 ore = "default:stone_with_coal",
48 wherein = "default:stone",
49 clust_scarcity = 24*24*24,
57 minetest.register_ore({
59 ore = "default:stone_with_iron",
60 wherein = "default:stone",
61 clust_scarcity = 12*12*12,
68 minetest.register_ore({
70 ore = "default:stone_with_iron",
71 wherein = "default:stone",
72 clust_scarcity = 9*9*9,
79 minetest.register_ore({
81 ore = "default:stone_with_iron",
82 wherein = "default:stone",
83 clust_scarcity = 7*7*7,
91 minetest.register_ore({
93 ore = "default:stone_with_iron",
94 wherein = "default:stone",
95 clust_scarcity = 24*24*24,
103 minetest.register_ore({
104 ore_type = "scatter",
105 ore = "default:stone_with_mese",
106 wherein = "default:stone",
107 clust_scarcity = 18*18*18,
115 minetest.register_ore({
116 ore_type = "scatter",
117 ore = "default:stone_with_mese",
118 wherein = "default:stone",
119 clust_scarcity = 14*14*14,
127 minetest.register_ore({
128 ore_type = "scatter",
129 ore = "default:mese",
130 wherein = "default:stone",
131 clust_scarcity = 36*36*36,
139 minetest.register_ore({
140 ore_type = "scatter",
141 ore = "default:stone_with_gold",
142 wherein = "default:stone",
143 clust_scarcity = 15*15*15,
151 minetest.register_ore({
152 ore_type = "scatter",
153 ore = "default:stone_with_gold",
154 wherein = "default:stone",
155 clust_scarcity = 13*13*13,
163 minetest.register_ore({
164 ore_type = "scatter",
165 ore = "default:stone_with_diamond",
166 wherein = "default:stone",
167 clust_scarcity = 17*17*17,
175 minetest.register_ore({
176 ore_type = "scatter",
177 ore = "default:stone_with_diamond",
178 wherein = "default:stone",
179 clust_scarcity = 15*15*15,
187 minetest.register_ore({
188 ore_type = "scatter",
189 ore = "default:stone_with_copper",
190 wherein = "default:stone",
191 clust_scarcity = 12*12*12,
198 minetest.register_ore({
199 ore_type = "scatter",
200 ore = "default:stone_with_copper",
201 wherein = "default:stone",
202 clust_scarcity = 9*9*9,
210 minetest.register_ore({
211 ore_type = "scatter",
212 ore = "default:clay",
213 wherein = "default:sand",
214 clust_scarcity = 15*15*15,
221 function default.generate_ore(name, wherein, minp, maxp, seed, chunks_per_volume, chunk_size, ore_per_chunk, height_min, height_max)
222 minetest.log('action', "WARNING: default.generate_ore is deprecated")
224 if maxp.y < height_min or minp.y > height_max then
227 local y_min = math.max(minp.y, height_min)
228 local y_max = math.min(maxp.y, height_max)
229 if chunk_size >= y_max - y_min + 1 then
232 local volume = (maxp.x-minp.x+1)*(y_max-y_min+1)*(maxp.z-minp.z+1)
233 local pr = PseudoRandom(seed)
234 local num_chunks = math.floor(chunks_per_volume * volume)
235 local inverse_chance = math.floor(chunk_size*chunk_size*chunk_size / ore_per_chunk)
236 --print("generate_ore num_chunks: "..dump(num_chunks))
237 for i=1,num_chunks do
238 local y0 = pr:next(y_min, y_max-chunk_size+1)
239 if y0 >= height_min and y0 <= height_max then
240 local x0 = pr:next(minp.x, maxp.x-chunk_size+1)
241 local z0 = pr:next(minp.z, maxp.z-chunk_size+1)
242 local p0 = {x=x0, y=y0, z=z0}
243 for x1=0,chunk_size-1 do
244 for y1=0,chunk_size-1 do
245 for z1=0,chunk_size-1 do
246 if pr:next(1,inverse_chance) == 1 then
250 local p2 = {x=x2, y=y2, z=z2}
251 if minetest.get_node(p2).name == wherein then
252 minetest.set_node(p2, {name=name})
260 --print("generate_ore done")
264 -- Mgv6 papyrus, cactus, long grasses
267 function default.mgv6_ongen(minp, maxp, seed)
269 function default.make_papyrus(pos, size)
271 local p = {x=pos.x, y=pos.y+y, z=pos.z}
272 local nn = minetest.get_node(p).name
273 if minetest.registered_nodes[nn] and
274 minetest.registered_nodes[nn].buildable_to then
275 minetest.set_node(p, {name="default:papyrus"})
282 function default.make_cactus(pos, size)
284 local p = {x=pos.x, y=pos.y+y, z=pos.z}
285 local nn = minetest.get_node(p).name
286 if minetest.registered_nodes[nn] and
287 minetest.registered_nodes[nn].buildable_to then
288 minetest.set_node(p, {name="default:cactus"})
295 if maxp.y >= 2 and minp.y <= 0 then
297 local perlin1 = minetest.get_perlin(354, 3, 0.7, 100)
298 -- Assume X and Z lengths are equal
300 local divs = (maxp.x-minp.x)/divlen+1;
303 local x0 = minp.x + math.floor((divx+0)*divlen)
304 local z0 = minp.z + math.floor((divz+0)*divlen)
305 local x1 = minp.x + math.floor((divx+1)*divlen)
306 local z1 = minp.z + math.floor((divz+1)*divlen)
307 -- Determine papyrus amount from perlin noise
308 local papyrus_amount = math.floor(perlin1:get2d({x=x0, y=z0}) * 45 - 20)
309 -- Find random positions for papyrus based on this random
310 local pr = PseudoRandom(seed+1)
311 for i=0,papyrus_amount do
312 local x = pr:next(x0, x1)
313 local z = pr:next(z0, z1)
314 if minetest.get_node({x=x,y=1,z=z}).name == "default:dirt_with_grass" and
315 minetest.find_node_near({x=x,y=1,z=z}, 1, "default:water_source") then
316 default.make_papyrus({x=x,y=2,z=z}, pr:next(2, 4))
322 local perlin1 = minetest.get_perlin(230, 3, 0.6, 100)
323 -- Assume X and Z lengths are equal
325 local divs = (maxp.x-minp.x)/divlen+1;
328 local x0 = minp.x + math.floor((divx+0)*divlen)
329 local z0 = minp.z + math.floor((divz+0)*divlen)
330 local x1 = minp.x + math.floor((divx+1)*divlen)
331 local z1 = minp.z + math.floor((divz+1)*divlen)
332 -- Determine cactus amount from perlin noise
333 local cactus_amount = math.floor(perlin1:get2d({x=x0, y=z0}) * 6 - 3)
334 -- Find random positions for cactus based on this random
335 local pr = PseudoRandom(seed+1)
336 for i=0,cactus_amount do
337 local x = pr:next(x0, x1)
338 local z = pr:next(z0, z1)
339 -- Find ground level (0...15)
342 if minetest.get_node({x=x,y=y,z=z}).name ~= "air" then
347 -- If desert sand, make cactus
348 if ground_y and minetest.get_node({x=x,y=ground_y,z=z}).name == "default:desert_sand" then
349 default.make_cactus({x=x,y=ground_y+1,z=z}, pr:next(3, 4))
355 local perlin1 = minetest.get_perlin(329, 3, 0.6, 100)
356 -- Assume X and Z lengths are equal
358 local divs = (maxp.x-minp.x)/divlen+1;
361 local x0 = minp.x + math.floor((divx+0)*divlen)
362 local z0 = minp.z + math.floor((divz+0)*divlen)
363 local x1 = minp.x + math.floor((divx+1)*divlen)
364 local z1 = minp.z + math.floor((divz+1)*divlen)
365 -- Determine grass amount from perlin noise
366 local grass_amount = math.floor(perlin1:get2d({x=x0, y=z0}) ^ 3 * 9)
367 -- Find random positions for grass based on this random
368 local pr = PseudoRandom(seed+1)
369 for i=0,grass_amount do
370 local x = pr:next(x0, x1)
371 local z = pr:next(z0, z1)
372 -- Find ground level (0...15)
375 if minetest.get_node({x=x,y=y,z=z}).name ~= "air" then
382 local p = {x=x,y=ground_y+1,z=z}
383 local nn = minetest.get_node(p).name
384 -- Check if the node can be replaced
385 if minetest.registered_nodes[nn] and
386 minetest.registered_nodes[nn].buildable_to then
387 nn = minetest.get_node({x=x,y=ground_y,z=z}).name
388 -- If desert sand, add dry shrub
389 if nn == "default:desert_sand" then
390 minetest.set_node(p,{name="default:dry_shrub"})
392 -- If dirt with grass, add grass
393 elseif nn == "default:dirt_with_grass" then
394 minetest.set_node(p,{name="default:grass_"..pr:next(1, 5)})
406 -- Detect mapgen and register suitable on-generated function
409 minetest.register_on_mapgen_init(function(mg_params)
410 if mg_params.mgname == "v6" then
411 minetest.register_on_generated(default.mgv6_ongen)
416 -- Generate nyan cats in all mapgens
419 -- facedir: 0/1/2/3 (head node facedir value)
420 -- length: length of rainbow tail
421 function default.make_nyancat(pos, facedir, length)
422 local tailvec = {x=0, y=0, z=0}
425 elseif facedir == 1 then
427 elseif facedir == 2 then
429 elseif facedir == 3 then
432 --print("default.make_nyancat(): Invalid facedir: "+dump(facedir))
436 local p = {x=pos.x, y=pos.y, z=pos.z}
437 minetest.set_node(p, {name="default:nyancat", param2=facedir})
439 p.x = p.x + tailvec.x
440 p.z = p.z + tailvec.z
441 minetest.set_node(p, {name="default:nyancat_rainbow", param2=facedir})
445 function default.generate_nyancats(minp, maxp, seed)
446 local height_min = -31000
447 local height_max = -32
448 if maxp.y < height_min or minp.y > height_max then
451 local y_min = math.max(minp.y, height_min)
452 local y_max = math.min(maxp.y, height_max)
453 local volume = (maxp.x-minp.x+1)*(y_max-y_min+1)*(maxp.z-minp.z+1)
454 local pr = PseudoRandom(seed + 9324342)
455 local max_num_nyancats = math.floor(volume / (16*16*16))
456 for i=1,max_num_nyancats do
457 if pr:next(0, 1000) == 0 then
458 local x0 = pr:next(minp.x, maxp.x)
459 local y0 = pr:next(minp.y, maxp.y)
460 local z0 = pr:next(minp.z, maxp.z)
461 local p0 = {x=x0, y=y0, z=z0}
462 default.make_nyancat(p0, pr:next(0,3), pr:next(3,15))
467 minetest.register_on_generated(default.generate_nyancats)