2 -- Aliases for map generator outputs
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")
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")
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")
40 -- Blob ore first to avoid other ores inside blobs
42 function default.register_ores()
43 minetest.register_ore({
46 wherein = {"default:sand"},
47 clust_scarcity = 24*24*24,
55 spread={x=5, y=5, z=5},
62 minetest.register_ore({
65 wherein = {"default:stone"},
66 clust_scarcity = 24*24*24,
74 spread={x=5, y=5, z=5},
81 minetest.register_ore({
84 wherein = {"default:stone"},
85 clust_scarcity = 24*24*24,
93 spread={x=5, y=5, z=5},
100 minetest.register_ore({
102 ore = "default:gravel",
103 wherein = {"default:stone"},
104 clust_scarcity = 24*24*24,
108 noise_threshhold = 0,
112 spread={x=5, y=5, z=5},
119 minetest.register_ore({
120 ore_type = "scatter",
121 ore = "default:stone_with_coal",
122 wherein = "default:stone",
123 clust_scarcity = 8*8*8,
130 minetest.register_ore({
131 ore_type = "scatter",
132 ore = "default:stone_with_coal",
133 wherein = "default:stone",
134 clust_scarcity = 24*24*24,
141 minetest.register_ore({
142 ore_type = "scatter",
143 ore = "default:stone_with_iron",
144 wherein = "default:stone",
145 clust_scarcity = 12*12*12,
152 minetest.register_ore({
153 ore_type = "scatter",
154 ore = "default:stone_with_iron",
155 wherein = "default:stone",
156 clust_scarcity = 9*9*9,
163 minetest.register_ore({
164 ore_type = "scatter",
165 ore = "default:stone_with_iron",
166 wherein = "default:stone",
167 clust_scarcity = 7*7*7,
174 minetest.register_ore({
175 ore_type = "scatter",
176 ore = "default:stone_with_iron",
177 wherein = "default:stone",
178 clust_scarcity = 24*24*24,
185 minetest.register_ore({
186 ore_type = "scatter",
187 ore = "default:stone_with_mese",
188 wherein = "default:stone",
189 clust_scarcity = 18*18*18,
196 minetest.register_ore({
197 ore_type = "scatter",
198 ore = "default:stone_with_mese",
199 wherein = "default:stone",
200 clust_scarcity = 14*14*14,
207 minetest.register_ore({
208 ore_type = "scatter",
209 ore = "default:mese",
210 wherein = "default:stone",
211 clust_scarcity = 36*36*36,
218 minetest.register_ore({
219 ore_type = "scatter",
220 ore = "default:stone_with_gold",
221 wherein = "default:stone",
222 clust_scarcity = 15*15*15,
229 minetest.register_ore({
230 ore_type = "scatter",
231 ore = "default:stone_with_gold",
232 wherein = "default:stone",
233 clust_scarcity = 13*13*13,
240 minetest.register_ore({
241 ore_type = "scatter",
242 ore = "default:stone_with_diamond",
243 wherein = "default:stone",
244 clust_scarcity = 17*17*17,
251 minetest.register_ore({
252 ore_type = "scatter",
253 ore = "default:stone_with_diamond",
254 wherein = "default:stone",
255 clust_scarcity = 15*15*15,
262 minetest.register_ore({
263 ore_type = "scatter",
264 ore = "default:stone_with_copper",
265 wherein = "default:stone",
266 clust_scarcity = 12*12*12,
273 minetest.register_ore({
274 ore_type = "scatter",
275 ore = "default:stone_with_copper",
276 wherein = "default:stone",
277 clust_scarcity = 9*9*9,
291 function default.register_biomes()
292 minetest.clear_registered_biomes()
294 minetest.register_biome({
295 name = "default:grassland",
297 node_top = "default:dirt_with_grass",
299 node_filler = "default:dirt",
302 --node_water_top = "",
303 --depth_water_top = ,
311 minetest.register_biome({
312 name = "default:grassland_ocean",
314 node_top = "default:sand",
316 node_filler = "default:sand",
319 --node_water_top = "",
320 --depth_water_top = ,
331 -- Register mgv6 decorations
335 function default.register_mgv6_decorations()
339 minetest.register_decoration({
340 deco_type = "simple",
341 place_on = {"default:dirt_with_grass"},
346 spread = {x=100, y=100, z=100},
353 decoration = "default:papyrus",
356 spawn_by = "default:water_source",
362 minetest.register_decoration({
363 deco_type = "simple",
364 place_on = {"default:desert_sand"},
369 spread = {x=100, y=100, z=100},
376 decoration = "default:cactus",
384 minetest.register_decoration({
385 deco_type = "simple",
386 place_on = {"default:dirt_with_grass"},
391 spread = {x=100, y=100, z=100},
398 decoration = "default:grass_"..length,
404 minetest.register_decoration({
405 deco_type = "simple",
406 place_on = {"default:desert_sand", "default:dirt_with_snow"},
411 spread = {x=100, y=100, z=100},
418 decoration = "default:dry_shrub",
424 -- Register decorations
428 function default.register_decorations()
432 minetest.register_decoration({
433 deco_type = "simple",
434 place_on = {"default:dirt_with_grass"},
439 spread = {x=200, y=200, z=200},
444 biomes = {"default:grassland"},
447 decoration = "flowers:rose",
450 minetest.register_decoration({
451 deco_type = "simple",
452 place_on = {"default:dirt_with_grass"},
457 spread = {x=200, y=200, z=200},
462 biomes = {"default:grassland"},
465 decoration = "flowers:tulip",
468 minetest.register_decoration({
469 deco_type = "simple",
470 place_on = {"default:dirt_with_grass"},
475 spread = {x=200, y=200, z=200},
480 biomes = {"default:grassland"},
483 decoration = "flowers:dandelion_yellow",
486 minetest.register_decoration({
487 deco_type = "simple",
488 place_on = {"default:dirt_with_grass"},
493 spread = {x=200, y=200, z=200},
498 biomes = {"default:grassland"},
501 decoration = "flowers:geranium",
504 minetest.register_decoration({
505 deco_type = "simple",
506 place_on = {"default:dirt_with_grass"},
511 spread = {x=200, y=200, z=200},
516 biomes = {"default:grassland"},
519 decoration = "flowers:viola",
522 minetest.register_decoration({
523 deco_type = "simple",
524 place_on = {"default:dirt_with_grass"},
529 spread = {x=200, y=200, z=200},
534 biomes = {"default:grassland"},
537 decoration = "flowers:dandelion_white",
542 minetest.register_decoration({
543 deco_type = "simple",
544 place_on = {"default:dirt_with_grass"},
549 spread = {x=200, y=200, z=200},
554 biomes = {"default:grassland"},
557 decoration = "default:grass_1",
560 minetest.register_decoration({
561 deco_type = "simple",
562 place_on = {"default:dirt_with_grass"},
567 spread = {x=200, y=200, z=200},
572 biomes = {"default:grassland"},
575 decoration = "default:grass_2",
578 minetest.register_decoration({
579 deco_type = "simple",
580 place_on = {"default:dirt_with_grass"},
585 spread = {x=200, y=200, z=200},
590 biomes = {"default:grassland"},
593 decoration = "default:grass_3",
596 minetest.register_decoration({
597 deco_type = "simple",
598 place_on = {"default:dirt_with_grass"},
603 spread = {x=200, y=200, z=200},
608 biomes = {"default:grassland"},
611 decoration = "default:grass_4",
614 minetest.register_decoration({
615 deco_type = "simple",
616 place_on = {"default:dirt_with_grass"},
621 spread = {x=200, y=200, z=200},
626 biomes = {"default:grassland"},
629 decoration = "default:grass_5",
635 -- Detect mapgen to select functions
639 -- Mods using singlenode mapgen can call these functions to enable
640 -- the use of minetest.generate_ores or minetest.generate_decorations
642 local mg_params = minetest.get_mapgen_params()
643 if mg_params.mgname == "v5" then
644 default.register_ores()
645 default.register_biomes()
646 default.register_decorations()
647 elseif mg_params.mgname == "v6" then
648 default.register_ores()
649 default.register_mgv6_decorations()
650 elseif mg_params.mgname == "v7" then
651 default.register_ores()
652 default.register_biomes()
653 default.register_decorations()
658 -- Generate nyan cats in all mapgens
662 -- facedir: 0/1/2/3 (head node facedir value)
663 -- length: length of rainbow tail
664 function default.make_nyancat(pos, facedir, length)
665 local tailvec = {x=0, y=0, z=0}
668 elseif facedir == 1 then
670 elseif facedir == 2 then
672 elseif facedir == 3 then
675 --print("default.make_nyancat(): Invalid facedir: "+dump(facedir))
679 local p = {x=pos.x, y=pos.y, z=pos.z}
680 minetest.set_node(p, {name="default:nyancat", param2=facedir})
682 p.x = p.x + tailvec.x
683 p.z = p.z + tailvec.z
684 minetest.set_node(p, {name="default:nyancat_rainbow", param2=facedir})
689 function default.generate_nyancats(minp, maxp, seed)
690 local height_min = -31000
691 local height_max = -32
692 if maxp.y < height_min or minp.y > height_max then
695 local y_min = math.max(minp.y, height_min)
696 local y_max = math.min(maxp.y, height_max)
697 local volume = (maxp.x-minp.x+1)*(y_max-y_min+1)*(maxp.z-minp.z+1)
698 local pr = PseudoRandom(seed + 9324342)
699 local max_num_nyancats = math.floor(volume / (16*16*16))
700 for i=1,max_num_nyancats do
701 if pr:next(0, 1000) == 0 then
702 local x0 = pr:next(minp.x, maxp.x)
703 local y0 = pr:next(minp.y, maxp.y)
704 local z0 = pr:next(minp.z, maxp.z)
705 local p0 = {x=x0, y=y0, z=z0}
706 default.make_nyancat(p0, pr:next(0,3), pr:next(3,15))
712 minetest.register_on_generated(default.generate_nyancats)
716 -- Deprecated ore generation code
720 function default.generate_ore(name, wherein, minp, maxp, seed,
721 chunks_per_volume, chunk_size, ore_per_chunk, height_min, height_max)
722 minetest.log('action', "WARNING: default.generate_ore is deprecated")
724 if maxp.y < height_min or minp.y > height_max then
727 local y_min = math.max(minp.y, height_min)
728 local y_max = math.min(maxp.y, height_max)
729 if chunk_size >= y_max - y_min + 1 then
732 local volume = (maxp.x-minp.x+1)*(y_max-y_min+1)*(maxp.z-minp.z+1)
733 local pr = PseudoRandom(seed)
734 local num_chunks = math.floor(chunks_per_volume * volume)
735 local inverse_chance = math.floor(chunk_size*chunk_size*chunk_size / ore_per_chunk)
736 --print("generate_ore num_chunks: "..dump(num_chunks))
737 for i=1,num_chunks do
738 local y0 = pr:next(y_min, y_max-chunk_size+1)
739 if y0 >= height_min and y0 <= height_max then
740 local x0 = pr:next(minp.x, maxp.x-chunk_size+1)
741 local z0 = pr:next(minp.z, maxp.z-chunk_size+1)
742 local p0 = {x=x0, y=y0, z=z0}
743 for x1=0,chunk_size-1 do
744 for y1=0,chunk_size-1 do
745 for z1=0,chunk_size-1 do
746 if pr:next(1,inverse_chance) == 1 then
750 local p2 = {x=x2, y=y2, z=z2}
751 if minetest.get_node(p2).name == wherein then
752 minetest.set_node(p2, {name=name})
760 --print("generate_ore done")