18c523174ba6990e7d73d6df0880fb2482cc6158
[oweals/minetest_game.git] / mods / default / mapgen.lua
1 --
2 -- Aliases for map generator outputs
3 --
4
5
6 minetest.register_alias("mapgen_stone", "default:stone")
7 minetest.register_alias("mapgen_dirt", "default:dirt")
8 minetest.register_alias("mapgen_dirt_with_grass", "default:dirt_with_grass")
9 minetest.register_alias("mapgen_sand", "default:sand")
10 minetest.register_alias("mapgen_water_source", "default:water_source")
11 minetest.register_alias("mapgen_river_water_source", "default:river_water_source")
12 minetest.register_alias("mapgen_lava_source", "default:lava_source")
13 minetest.register_alias("mapgen_gravel", "default:gravel")
14 minetest.register_alias("mapgen_desert_stone", "default:desert_stone")
15 minetest.register_alias("mapgen_desert_sand", "default:desert_sand")
16 minetest.register_alias("mapgen_dirt_with_snow", "default:dirt_with_snow")
17 minetest.register_alias("mapgen_snow", "default:snow")
18 minetest.register_alias("mapgen_snowblock", "default:snowblock")
19 minetest.register_alias("mapgen_ice", "default:ice")
20
21 minetest.register_alias("mapgen_tree", "default:tree")
22 minetest.register_alias("mapgen_leaves", "default:leaves")
23 minetest.register_alias("mapgen_apple", "default:apple")
24 minetest.register_alias("mapgen_jungletree", "default:jungletree")
25 minetest.register_alias("mapgen_jungleleaves", "default:jungleleaves")
26 minetest.register_alias("mapgen_junglegrass", "default:junglegrass")
27 minetest.register_alias("mapgen_pinetree", "default:pinetree")
28 minetest.register_alias("mapgen_pine_needles", "default:pine_needles")
29
30 minetest.register_alias("mapgen_cobble", "default:cobble")
31 minetest.register_alias("mapgen_stair_cobble", "stairs:stair_cobble")
32 minetest.register_alias("mapgen_mossycobble", "default:mossycobble")
33
34
35 --
36 -- Register ores
37 --
38
39
40 -- Blob ore first to avoid other ores inside blobs
41
42 function default.register_ores()
43         minetest.register_ore({ 
44                 ore_type         = "blob",
45                 ore              = "default:clay",
46                 wherein          = {"default:sand"},
47                 clust_scarcity   = 24*24*24,
48                 clust_size       = 7,
49                 y_min            = -15,
50                 y_max            = 0,
51                 noise_threshhold = 0,
52                 noise_params     = {
53                         offset=0.35,
54                         scale=0.2,
55                         spread={x=5, y=5, z=5},
56                         seed=-316,
57                         octaves=1,
58                         persist=0.5
59                 },
60         })
61
62         minetest.register_ore({ 
63                 ore_type         = "blob",
64                 ore              = "default:sand",
65                 wherein          = {"default:stone"},
66                 clust_scarcity   = 24*24*24,
67                 clust_size       = 7,
68                 y_min            = -63,
69                 y_max            = 4,
70                 noise_threshhold = 0,
71                 noise_params     = {
72                         offset=0.35,
73                         scale=0.2,
74                         spread={x=5, y=5, z=5},
75                         seed=2316,
76                         octaves=1,
77                         persist=0.5
78                 },
79         })
80
81         minetest.register_ore({
82                 ore_type         = "blob",
83                 ore              = "default:dirt",
84                 wherein          = {"default:stone"},
85                 clust_scarcity   = 24*24*24,
86                 clust_size       = 7,
87                 y_min            = -63,
88                 y_max            = 31000,
89                 noise_threshhold = 0,
90                 noise_params     = {
91                         offset=0.35,
92                         scale=0.2,
93                         spread={x=5, y=5, z=5},
94                         seed=17676,
95                         octaves=1,
96                         persist=0.5
97                 },
98         })
99
100         minetest.register_ore({
101                 ore_type         = "blob",
102                 ore              = "default:gravel",
103                 wherein          = {"default:stone"},
104                 clust_scarcity   = 24*24*24,
105                 clust_size       = 7,
106                 y_min            = -31000,
107                 y_max            = 31000,
108                 noise_threshhold = 0,
109                 noise_params     = {
110                         offset=0.35,
111                         scale=0.2,
112                         spread={x=5, y=5, z=5},
113                         seed=766,
114                         octaves=1,
115                         persist=0.5
116                 },
117         })
118
119         minetest.register_ore({
120                 ore_type       = "scatter",
121                 ore            = "default:stone_with_coal",
122                 wherein        = "default:stone",
123                 clust_scarcity = 8*8*8,
124                 clust_num_ores = 8,
125                 clust_size     = 3,
126                 y_min          = -31000,
127                 y_max          = 64,
128         })
129
130         minetest.register_ore({
131                 ore_type       = "scatter",
132                 ore            = "default:stone_with_coal",
133                 wherein        = "default:stone",
134                 clust_scarcity = 24*24*24,
135                 clust_num_ores = 27,
136                 clust_size     = 6,
137                 y_min          = -31000,
138                 y_max          = 0,
139         })
140
141         minetest.register_ore({
142                 ore_type       = "scatter",
143                 ore            = "default:stone_with_iron",
144                 wherein        = "default:stone",
145                 clust_scarcity = 12*12*12,
146                 clust_num_ores = 3,
147                 clust_size     = 2,
148                 y_min          = -15,
149                 y_max          = 2,
150         })
151
152         minetest.register_ore({
153                 ore_type       = "scatter",
154                 ore            = "default:stone_with_iron",
155                 wherein        = "default:stone",
156                 clust_scarcity = 9*9*9,
157                 clust_num_ores = 5,
158                 clust_size     = 3,
159                 y_min          = -63,
160                 y_max          = -16,
161         })
162
163         minetest.register_ore({
164                 ore_type       = "scatter",
165                 ore            = "default:stone_with_iron",
166                 wherein        = "default:stone",
167                 clust_scarcity = 7*7*7,
168                 clust_num_ores = 5,
169                 clust_size     = 3,
170                 y_min          = -31000,
171                 y_max          = -64,
172         })
173
174         minetest.register_ore({
175                 ore_type       = "scatter",
176                 ore            = "default:stone_with_iron",
177                 wherein        = "default:stone",
178                 clust_scarcity = 24*24*24,
179                 clust_num_ores = 27,
180                 clust_size     = 6,
181                 y_min          = -31000,
182                 y_max          = -64,
183         })
184
185         minetest.register_ore({
186                 ore_type       = "scatter",
187                 ore            = "default:stone_with_mese",
188                 wherein        = "default:stone",
189                 clust_scarcity = 18*18*18,
190                 clust_num_ores = 3,
191                 clust_size     = 2,
192                 y_min          = -255,
193                 y_max          = -64,
194         })
195
196         minetest.register_ore({
197                 ore_type       = "scatter",
198                 ore            = "default:stone_with_mese",
199                 wherein        = "default:stone",
200                 clust_scarcity = 14*14*14,
201                 clust_num_ores = 5,
202                 clust_size     = 3,
203                 y_min          = -31000,
204                 y_max          = -256,
205         })
206
207         minetest.register_ore({
208                 ore_type       = "scatter",
209                 ore            = "default:mese",
210                 wherein        = "default:stone",
211                 clust_scarcity = 36*36*36,
212                 clust_num_ores = 3,
213                 clust_size     = 2,
214                 y_min          = -31000,
215                 y_max          = -1024,
216         })
217
218         minetest.register_ore({
219                 ore_type       = "scatter",
220                 ore            = "default:stone_with_gold",
221                 wherein        = "default:stone",
222                 clust_scarcity = 15*15*15,
223                 clust_num_ores = 3,
224                 clust_size     = 2,
225                 y_min          = -255,
226                 y_max          = -64,
227         })
228
229         minetest.register_ore({
230                 ore_type       = "scatter",
231                 ore            = "default:stone_with_gold",
232                 wherein        = "default:stone",
233                 clust_scarcity = 13*13*13,
234                 clust_num_ores = 5,
235                 clust_size     = 3,
236                 y_min          = -31000,
237                 y_max          = -256,
238         })
239
240         minetest.register_ore({
241                 ore_type       = "scatter",
242                 ore            = "default:stone_with_diamond",
243                 wherein        = "default:stone",
244                 clust_scarcity = 17*17*17,
245                 clust_num_ores = 4,
246                 clust_size     = 3,
247                 y_min          = -255,
248                 y_max          = -128,
249         })
250
251         minetest.register_ore({
252                 ore_type       = "scatter",
253                 ore            = "default:stone_with_diamond",
254                 wherein        = "default:stone",
255                 clust_scarcity = 15*15*15,
256                 clust_num_ores = 4,
257                 clust_size     = 3,
258                 y_min          = -31000,
259                 y_max          = -256,
260         })
261
262         minetest.register_ore({
263                 ore_type       = "scatter",
264                 ore            = "default:stone_with_copper",
265                 wherein        = "default:stone",
266                 clust_scarcity = 12*12*12,
267                 clust_num_ores = 4,
268                 clust_size     = 3,
269                 y_min          = -63,
270                 y_max          = -16,
271         })
272
273         minetest.register_ore({
274                 ore_type       = "scatter",
275                 ore            = "default:stone_with_copper",
276                 wherein        = "default:stone",
277                 clust_scarcity = 9*9*9,
278                 clust_num_ores = 5,
279                 clust_size     = 3,
280                 y_min          = -31000,
281                 y_max          = -64,
282         })
283 end
284
285
286 --
287 -- Register biomes
288 --
289
290
291 function default.register_biomes()
292         minetest.clear_registered_biomes()
293
294         minetest.register_biome({
295                 name = "default:grassland",
296                 --node_dust = "",
297                 node_top = "default:dirt_with_grass",
298                 depth_top = 1,
299                 node_filler = "default:dirt",
300                 depth_filler = 1,
301                 --node_stone = "",
302                 --node_water_top = "",
303                 --depth_water_top = ,
304                 --node_water = "",
305                 y_min = 5,
306                 y_max = 31000,
307                 heat_point = 50,
308                 humidity_point = 50,
309         })
310
311         minetest.register_biome({
312                 name = "default:grassland_ocean",
313                 --node_dust = "",
314                 node_top = "default:sand",
315                 depth_top = 1,
316                 node_filler = "default:sand",
317                 depth_filler = 2,
318                 --node_stone = "",
319                 --node_water_top = "",
320                 --depth_water_top = ,
321                 --node_water = "",
322                 y_min = -31000,
323                 y_max = 4,
324                 heat_point = 50,
325                 humidity_point = 50,
326         })
327 end
328
329
330 --
331 -- Register mgv6 decorations
332 --
333
334
335 function default.register_mgv6_decorations()
336
337         -- Papyrus
338
339         minetest.register_decoration({
340                 deco_type = "simple",
341                 place_on = {"default:dirt_with_grass"},
342                 sidelen = 8,
343                 noise_params = {
344                         offset = -0.3,
345                         scale = 0.7,
346                         spread = {x=100, y=100, z=100},
347                         seed = 354,
348                         octaves = 3,
349                         persist = 0.7
350                 },
351                 y_min = 1,
352                 y_max = 1,
353                 decoration = "default:papyrus",
354                 height = 2,
355                 height_max = 4,
356                 spawn_by = "default:water_source",
357                 num_spawn_by = 1,
358         })
359
360         -- Cacti
361
362         minetest.register_decoration({
363                 deco_type = "simple",
364                 place_on = {"default:desert_sand"},
365                 sidelen = 16,
366                 noise_params = {
367                         offset = -0.012,
368                         scale = 0.024,
369                         spread = {x=100, y=100, z=100},
370                         seed = 230,
371                         octaves = 3,
372                         persist = 0.6
373                 },
374                 y_min = 1,
375                 y_max = 30,
376                 decoration = "default:cactus",
377                 height = 3,
378                 height_max = 4,
379         })
380
381         -- Grasses
382
383         for length = 1, 5 do
384                 minetest.register_decoration({
385                         deco_type = "simple",
386                         place_on = {"default:dirt_with_grass"},
387                         sidelen = 16,
388                         noise_params = {
389                                 offset = 0,
390                                 scale = 0.007,
391                                 spread = {x=100, y=100, z=100},
392                                 seed = 329,
393                                 octaves = 3,
394                                 persist = 0.6
395                         },
396                         y_min = 1,
397                         y_max = 30,
398                         decoration = "default:grass_"..length,
399                 })
400         end
401
402         -- Dry shrubs
403
404         minetest.register_decoration({
405                 deco_type = "simple",
406                 place_on = {"default:desert_sand", "default:dirt_with_snow"},
407                 sidelen = 16,
408                 noise_params = {
409                         offset = 0,
410                         scale = 0.035,
411                         spread = {x=100, y=100, z=100},
412                         seed = 329,
413                         octaves = 3,
414                         persist = 0.6
415                 },
416                 y_min = 1,
417                 y_max = 30,
418                 decoration = "default:dry_shrub",
419         })
420 end
421
422
423 --
424 -- Register decorations
425 --
426
427
428 function default.register_decorations()
429
430         -- Flowers
431
432         minetest.register_decoration({
433                 deco_type = "simple",
434                 place_on = {"default:dirt_with_grass"},
435                 sidelen = 16,
436                 noise_params = {
437                         offset = -0.02,
438                         scale = 0.03,
439                         spread = {x=200, y=200, z=200},
440                         seed = 436,
441                         octaves = 3,
442                         persist = 0.6
443                 },
444                 biomes = {"default:grassland"},
445                 y_min = -31000,
446                 y_max = 31000,
447                 decoration = "flowers:rose",
448         })
449         
450         minetest.register_decoration({
451                 deco_type = "simple",
452                 place_on = {"default:dirt_with_grass"},
453                 sidelen = 16,
454                 noise_params = {
455                         offset = -0.02,
456                         scale = 0.03,
457                         spread = {x=200, y=200, z=200},
458                         seed = 19822,
459                         octaves = 3,
460                         persist = 0.6
461                 },
462                 biomes = {"default:grassland"},
463                 y_min = 33,
464                 y_max = 31000,
465                 decoration = "flowers:tulip",
466         })
467         
468         minetest.register_decoration({
469                 deco_type = "simple",
470                 place_on = {"default:dirt_with_grass"},
471                 sidelen = 16,
472                 noise_params = {
473                         offset = -0.02,
474                         scale = 0.03,
475                         spread = {x=200, y=200, z=200},
476                         seed = 1220999,
477                         octaves = 3,
478                         persist = 0.6
479                 },
480                 biomes = {"default:grassland"},
481                 y_min = -31000,
482                 y_max = 31000,
483                 decoration = "flowers:dandelion_yellow",
484         })
485         
486         minetest.register_decoration({
487                 deco_type = "simple",
488                 place_on = {"default:dirt_with_grass"},
489                 sidelen = 16,
490                 noise_params = {
491                         offset = -0.02,
492                         scale = 0.03,
493                         spread = {x=200, y=200, z=200},
494                         seed = 36662,
495                         octaves = 3,
496                         persist = 0.6
497                 },
498                 biomes = {"default:grassland"},
499                 y_min = -31000,
500                 y_max = 31000,
501                 decoration = "flowers:geranium",
502         })
503         
504         minetest.register_decoration({
505                 deco_type = "simple",
506                 place_on = {"default:dirt_with_grass"},
507                 sidelen = 16,
508                 noise_params = {
509                         offset = -0.02,
510                         scale = 0.03,
511                         spread = {x=200, y=200, z=200},
512                         seed = 1133,
513                         octaves = 3,
514                         persist = 0.6
515                 },
516                 biomes = {"default:grassland"},
517                 y_min = -31000,
518                 y_max = 31000,
519                 decoration = "flowers:viola",
520         })
521         
522         minetest.register_decoration({
523                 deco_type = "simple",
524                 place_on = {"default:dirt_with_grass"},
525                 sidelen = 16,
526                 noise_params = {
527                         offset = -0.02,
528                         scale = 0.03,
529                         spread = {x=200, y=200, z=200},
530                         seed = 73133,
531                         octaves = 3,
532                         persist = 0.6
533                 },
534                 biomes = {"default:grassland"},
535                 y_min = -31000,
536                 y_max = 31000,
537                 decoration = "flowers:dandelion_white",
538         })
539
540         -- Grasses
541
542         minetest.register_decoration({
543                 deco_type = "simple",
544                 place_on = {"default:dirt_with_grass"},
545                 sidelen = 16,
546                 noise_params = {
547                         offset = 0.04,
548                         scale = 0.04,
549                         spread = {x=200, y=200, z=200},
550                         seed = 66440,
551                         octaves = 3,
552                         persist = 0.6
553                 },
554                 biomes = {"default:grassland"},
555                 y_min = -31000,
556                 y_max = 31000,
557                 decoration = "default:grass_1",
558         })
559         
560         minetest.register_decoration({
561                 deco_type = "simple",
562                 place_on = {"default:dirt_with_grass"},
563                 sidelen = 16,
564                 noise_params = {
565                         offset = 0.02,
566                         scale = 0.06,
567                         spread = {x=200, y=200, z=200},
568                         seed = 66440,
569                         octaves = 3,
570                         persist = 0.6
571                 },
572                 biomes = {"default:grassland"},
573                 y_min = -31000,
574                 y_max = 31000,
575                 decoration = "default:grass_2",
576         })
577         
578         minetest.register_decoration({
579                 deco_type = "simple",
580                 place_on = {"default:dirt_with_grass"},
581                 sidelen = 16,
582                 noise_params = {
583                         offset = 0,
584                         scale = 0.08,
585                         spread = {x=200, y=200, z=200},
586                         seed = 66440,
587                         octaves = 3,
588                         persist = 0.6
589                 },
590                 biomes = {"default:grassland"},
591                 y_min = -31000,
592                 y_max = 31000,
593                 decoration = "default:grass_3",
594         })
595         
596         minetest.register_decoration({
597                 deco_type = "simple",
598                 place_on = {"default:dirt_with_grass"},
599                 sidelen = 16,
600                 noise_params = {
601                         offset = -0.02,
602                         scale = 0.10,
603                         spread = {x=200, y=200, z=200},
604                         seed = 66440,
605                         octaves = 3,
606                         persist = 0.6
607                 },
608                 biomes = {"default:grassland"},
609                 y_min = -31000,
610                 y_max = 31000,
611                 decoration = "default:grass_4",
612         })
613         
614         minetest.register_decoration({
615                 deco_type = "simple",
616                 place_on = {"default:dirt_with_grass"},
617                 sidelen = 16,
618                 noise_params = {
619                         offset = -0.04,
620                         scale = 0.12,
621                         spread = {x=200, y=200, z=200},
622                         seed = 66440,
623                         octaves = 3,
624                         persist = 0.6
625                 },
626                 biomes = {"default:grassland"},
627                 y_min = -31000,
628                 y_max = 31000,
629                 decoration = "default:grass_5",
630         })
631 end
632
633
634 --
635 -- Detect mapgen to select functions
636 --
637
638
639 -- Mods using singlenode mapgen can call these functions to enable
640 -- the use of minetest.generate_ores or minetest.generate_decorations
641
642 local mg_params = minetest.get_mapgen_params()
643 if mg_params.mgname == "v6" then
644         default.register_ores()
645         default.register_mgv6_decorations()
646 elseif mg_params.mgname ~= "singlenode" then
647         default.register_ores()
648         default.register_biomes()
649         default.register_decorations()
650 end
651
652
653 --
654 -- Generate nyan cats in all mapgens
655 --
656
657
658 -- facedir: 0/1/2/3 (head node facedir value)
659 -- length: length of rainbow tail
660 function default.make_nyancat(pos, facedir, length)
661         local tailvec = {x=0, y=0, z=0}
662         if facedir == 0 then
663                 tailvec.z = 1
664         elseif facedir == 1 then
665                 tailvec.x = 1
666         elseif facedir == 2 then
667                 tailvec.z = -1
668         elseif facedir == 3 then
669                 tailvec.x = -1
670         else
671                 --print("default.make_nyancat(): Invalid facedir: "+dump(facedir))
672                 facedir = 0
673                 tailvec.z = 1
674         end
675         local p = {x=pos.x, y=pos.y, z=pos.z}
676         minetest.set_node(p, {name="default:nyancat", param2=facedir})
677         for i=1,length do
678                 p.x = p.x + tailvec.x
679                 p.z = p.z + tailvec.z
680                 minetest.set_node(p, {name="default:nyancat_rainbow", param2=facedir})
681         end
682 end
683
684
685 function default.generate_nyancats(minp, maxp, seed)
686         local height_min = -31000
687         local height_max = -32
688         if maxp.y < height_min or minp.y > height_max then
689                 return
690         end
691         local y_min = math.max(minp.y, height_min)
692         local y_max = math.min(maxp.y, height_max)
693         local volume = (maxp.x-minp.x+1)*(y_max-y_min+1)*(maxp.z-minp.z+1)
694         local pr = PseudoRandom(seed + 9324342)
695         local max_num_nyancats = math.floor(volume / (16*16*16))
696         for i=1,max_num_nyancats do
697                 if pr:next(0, 1000) == 0 then
698                         local x0 = pr:next(minp.x, maxp.x)
699                         local y0 = pr:next(minp.y, maxp.y)
700                         local z0 = pr:next(minp.z, maxp.z)
701                         local p0 = {x=x0, y=y0, z=z0}
702                         default.make_nyancat(p0, pr:next(0,3), pr:next(3,15))
703                 end
704         end
705 end
706
707
708 minetest.register_on_generated(default.generate_nyancats)
709
710
711 --
712 -- Deprecated ore generation code
713 --
714
715
716 function default.generate_ore(name, wherein, minp, maxp, seed,
717                 chunks_per_volume, chunk_size, ore_per_chunk, height_min, height_max)
718         minetest.log('action', "WARNING: default.generate_ore is deprecated")
719
720         if maxp.y < height_min or minp.y > height_max then
721                 return
722         end
723         local y_min = math.max(minp.y, height_min)
724         local y_max = math.min(maxp.y, height_max)
725         if chunk_size >= y_max - y_min + 1 then
726                 return
727         end
728         local volume = (maxp.x-minp.x+1)*(y_max-y_min+1)*(maxp.z-minp.z+1)
729         local pr = PseudoRandom(seed)
730         local num_chunks = math.floor(chunks_per_volume * volume)
731         local inverse_chance = math.floor(chunk_size*chunk_size*chunk_size / ore_per_chunk)
732         --print("generate_ore num_chunks: "..dump(num_chunks))
733         for i=1,num_chunks do
734                 local y0 = pr:next(y_min, y_max-chunk_size+1)
735                 if y0 >= height_min and y0 <= height_max then
736                         local x0 = pr:next(minp.x, maxp.x-chunk_size+1)
737                         local z0 = pr:next(minp.z, maxp.z-chunk_size+1)
738                         local p0 = {x=x0, y=y0, z=z0}
739                         for x1=0,chunk_size-1 do
740                         for y1=0,chunk_size-1 do
741                         for z1=0,chunk_size-1 do
742                                 if pr:next(1,inverse_chance) == 1 then
743                                         local x2 = x0+x1
744                                         local y2 = y0+y1
745                                         local z2 = z0+z1
746                                         local p2 = {x=x2, y=y2, z=z2}
747                                         if minetest.get_node(p2).name == wherein then
748                                                 minetest.set_node(p2, {name=name})
749                                         end
750                                 end
751                         end
752                         end
753                         end
754                 end
755         end
756         --print("generate_ore done")
757 end
758