1 -- minetest/default/mapgen.lua
4 -- Aliases for map generator outputs
7 minetest.register_alias("mapgen_air", "air")
8 minetest.register_alias("mapgen_stone", "default:stone")
9 minetest.register_alias("mapgen_tree", "default:tree")
10 minetest.register_alias("mapgen_leaves", "default:leaves")
11 minetest.register_alias("mapgen_apple", "default:apple")
12 minetest.register_alias("mapgen_water_source", "default:water_source")
13 minetest.register_alias("mapgen_dirt", "default:dirt")
14 minetest.register_alias("mapgen_sand", "default:sand")
15 minetest.register_alias("mapgen_gravel", "default:gravel")
16 minetest.register_alias("mapgen_clay", "default:clay")
17 minetest.register_alias("mapgen_lava_source", "default:lava_source")
18 minetest.register_alias("mapgen_cobble", "default:cobble")
19 minetest.register_alias("mapgen_mossycobble", "default:mossycobble")
20 minetest.register_alias("mapgen_dirt_with_grass", "default:dirt_with_grass")
21 minetest.register_alias("mapgen_junglegrass", "default:junglegrass")
22 minetest.register_alias("mapgen_stone_with_coal", "default:stone_with_coal")
23 minetest.register_alias("mapgen_stone_with_iron", "default:stone_with_iron")
24 minetest.register_alias("mapgen_mese", "default:mese")
25 minetest.register_alias("mapgen_desert_sand", "default:desert_sand")
26 minetest.register_alias("mapgen_desert_stone", "default:desert_stone")
32 local function generate_ore(name, wherein, minp, maxp, seed, chunks_per_volume, ore_per_chunk, height_min, height_max)
33 if maxp.y < height_min or minp.y > height_max then
36 local y_min = math.max(minp.y, height_min)
37 local y_max = math.min(maxp.y, height_max)
38 local volume = (maxp.x-minp.x+1)*(y_max-y_min+1)*(maxp.z-minp.z+1)
39 local pr = PseudoRandom(seed)
40 local num_chunks = math.floor(chunks_per_volume * volume)
42 if ore_per_chunk <= 4 then
45 local inverse_chance = math.floor(chunk_size*chunk_size*chunk_size / ore_per_chunk)
46 --print("generate_ore num_chunks: "..dump(num_chunks))
48 local y0 = pr:next(y_min, y_max-chunk_size+1)
49 if y0 >= height_min and y0 <= height_max then
50 local x0 = pr:next(minp.x, maxp.x-chunk_size+1)
51 local z0 = pr:next(minp.z, maxp.z-chunk_size+1)
52 local p0 = {x=x0, y=y0, z=z0}
53 for x1=0,chunk_size-1 do
54 for y1=0,chunk_size-1 do
55 for z1=0,chunk_size-1 do
56 if pr:next(1,inverse_chance) == 1 then
60 local p2 = {x=x2, y=y2, z=z2}
61 if minetest.env:get_node(p2).name == wherein then
62 minetest.env:set_node(p2, {name=name})
70 --print("generate_ore done")
73 function default.make_papyrus(pos, size)
75 local p = {x=pos.x, y=pos.y+y, z=pos.z}
76 minetest.env:set_node(p, {name="default:papyrus"})
80 function default.make_cactus(pos, size)
82 local p = {x=pos.x, y=pos.y+y, z=pos.z}
83 minetest.env:set_node(p, {name="default:cactus"})
87 minetest.register_on_generated(function(minp, maxp, seed)
88 generate_ore("default:stone_with_coal", "default:stone", minp, maxp, seed, 1/8/8/8, 5, -31000, 64)
89 generate_ore("default:stone_with_iron", "default:stone", minp, maxp, seed+1, 1/16/16/16, 5, -5, 7)
90 generate_ore("default:stone_with_iron", "default:stone", minp, maxp, seed+2, 1/12/12/12, 5, -16, -5)
91 generate_ore("default:stone_with_iron", "default:stone", minp, maxp, seed+3, 1/9/9/9, 5, -31000, -17)
92 if maxp.y >= 2 and minp.y <= 0 then
94 -- Assume X and Z lengths are equal
96 local divs = (maxp.x-minp.x)/divlen+1;
97 for divx=0+1,divs-1-1 do
98 for divz=0+1,divs-1-1 do
99 local cx = minp.x + math.floor((divx+0.5)*divlen)
100 local cz = minp.z + math.floor((divz+0.5)*divlen)
101 if minetest.env:get_node({x=cx,y=1,z=cz}).name == "default:water_source" and
102 minetest.env:get_node({x=cx,y=0,z=cz}).name == "default:sand" then
103 local is_shallow = true
104 local num_water_around = 0
105 if minetest.env:get_node({x=cx-divlen*2,y=1,z=cz+0}).name == "default:water_source" then
106 num_water_around = num_water_around + 1 end
107 if minetest.env:get_node({x=cx+divlen*2,y=1,z=cz+0}).name == "default:water_source" then
108 num_water_around = num_water_around + 1 end
109 if minetest.env:get_node({x=cx+0,y=1,z=cz-divlen*2}).name == "default:water_source" then
110 num_water_around = num_water_around + 1 end
111 if minetest.env:get_node({x=cx+0,y=1,z=cz+divlen*2}).name == "default:water_source" then
112 num_water_around = num_water_around + 1 end
113 if num_water_around >= 2 then
117 for x1=-divlen,divlen do
118 for z1=-divlen,divlen do
119 if minetest.env:get_node({x=cx+x1,y=0,z=cz+z1}).name == "default:sand" then
120 minetest.env:set_node({x=cx+x1,y=0,z=cz+z1}, {name="default:clay"})
129 local perlin1 = minetest.env:get_perlin(354, 3, 0.7, 100)
130 -- Assume X and Z lengths are equal
132 local divs = (maxp.x-minp.x)/divlen+1;
135 local x0 = minp.x + math.floor((divx+0)*divlen)
136 local z0 = minp.z + math.floor((divz+0)*divlen)
137 local x1 = minp.x + math.floor((divx+1)*divlen)
138 local z1 = minp.z + math.floor((divz+1)*divlen)
139 -- Determine papyrus amount from perlin noise
140 local papyrus_amount = math.floor(perlin1:get2d({x=x0, y=z0}) * 45 - 20)
141 -- Find random positions for papyrus based on this random
142 local pr = PseudoRandom(seed+1)
143 for i=0,papyrus_amount do
144 local x = pr:next(x0, x1)
145 local z = pr:next(z0, z1)
146 if minetest.env:get_node({x=x,y=1,z=z}).name == "default:dirt_with_grass" and
147 minetest.env:find_node_near({x=x,y=1,z=z}, 1, "default:water_source") then
148 default.make_papyrus({x=x,y=2,z=z}, pr:next(2, 4))
154 local perlin1 = minetest.env:get_perlin(230, 3, 0.6, 100)
155 -- Assume X and Z lengths are equal
157 local divs = (maxp.x-minp.x)/divlen+1;
160 local x0 = minp.x + math.floor((divx+0)*divlen)
161 local z0 = minp.z + math.floor((divz+0)*divlen)
162 local x1 = minp.x + math.floor((divx+1)*divlen)
163 local z1 = minp.z + math.floor((divz+1)*divlen)
164 -- Determine cactus amount from perlin noise
165 local cactus_amount = math.floor(perlin1:get2d({x=x0, y=z0}) * 6 - 3)
166 -- Find random positions for cactus based on this random
167 local pr = PseudoRandom(seed+1)
168 for i=0,cactus_amount do
169 local x = pr:next(x0, x1)
170 local z = pr:next(z0, z1)
171 -- Find ground level (0...15)
174 if minetest.env:get_node({x=x,y=y,z=z}).name ~= "air" then
179 -- If desert sand, make cactus
180 if ground_y and minetest.env:get_node({x=x,y=ground_y,z=z}).name == "default:desert_sand" then
181 default.make_cactus({x=x,y=ground_y+1,z=z}, pr:next(3, 4))
186 -- Generate dry shrubs
187 local perlin1 = minetest.env:get_perlin(329, 3, 0.6, 100)
188 -- Assume X and Z lengths are equal
190 local divs = (maxp.x-minp.x)/divlen+1;
193 local x0 = minp.x + math.floor((divx+0)*divlen)
194 local z0 = minp.z + math.floor((divz+0)*divlen)
195 local x1 = minp.x + math.floor((divx+1)*divlen)
196 local z1 = minp.z + math.floor((divz+1)*divlen)
197 -- Determine cactus amount from perlin noise
198 local cactus_amount = math.floor(perlin1:get2d({x=x0, y=z0}) * 5 + 2)
199 -- Find random positions for cactus based on this random
200 local pr = PseudoRandom(seed+1)
201 for i=0,cactus_amount do
202 local x = pr:next(x0, x1)
203 local z = pr:next(z0, z1)
204 -- Find ground level (0...15)
207 if minetest.env:get_node({x=x,y=y,z=z}).name ~= "air" then
212 -- If desert sand, make cactus
213 if ground_y and minetest.env:get_node({x=x,y=ground_y,z=z}).name == "default:desert_sand" then
214 minetest.env:set_node({x=x,y=ground_y+1,z=z}, {name="default:dry_shrub"})