Page 1 of 1

I don't understand how to use mapgen.

PostPosted: Sat Sep 07, 2013 00:09
by Chinchow
I have read the modding API for mapgen and I don't get it.
I have tried looking at mods that add biomes(snow biome).
I just have not been able to understand it.
If anyone could explain mapgen to me I would appreciate it, if not it's alright.

PostPosted: Sat Sep 07, 2013 13:43
by Chinchow
The only thing I figured out how to spawn was ores(not that hard) but I can't figure out how to spawn plants or make a biomes like Splizard did.

PostPosted: Sat Sep 07, 2013 23:37
by Chinchow
Yes I looked at it but it just isn't as easy to understand as the normal item registration code.

PostPosted: Sun Sep 22, 2013 02:02
by leetelate
LULZ! so you make a folder called ouch in the mods folder, create an empty file called depends.txt with the one word 'default' in it (no quotes - needed so it can find the defaults table to get the cobble id), then create an empty file called init.lua, insert the code, create a new world USING THE SINGLENODE IN THE MAPGEN DROPDOWN, enable the new ouch mod then hit play - you are now inside a solid world of cobblestone! - even if you had a pickaxe (or changed the cobble to default:sand), you can never dig your way out because the mapgen you just created creates a new area ahead of your digging!!!

priceless!!! and a great tutorial on the basic mapgen mod!!!

THANK YOU!!!

+1^5362437436 to hybrid dog!!!

PostPosted: Sun Sep 22, 2013 02:49
by paramat
There's a more interesting mapgen example here (requires 0.4.7dev/0.4.8 Minetest) https://forum.minetest.net/viewtopic.php?id=6396
Now just experiment with the code inside the triple xyz loop, use maths and perlin noise to add different nodes.

PostPosted: Sun Sep 22, 2013 03:49
by leetelate
thanks!!!

like:
if y > 0 then --above ground
data[area:index(x, y, z)] = c_air
else -- doing the ground
--handle -x and -z be snow, etc - depth will be unlimited
if x<0 and z<0 and y<0 then
data[area:index(x, y, z)] = c_stone
end
if x>=0 and z<0 and y<0 then
data[area:index(x, y, z)] = c_sand
end
if x<0 and z>=0 and y<0 then
data[area:index(x, y, z)] = c_water
end
if x>=0 and z>=0 and y<0 then
data[area:index(x, y, z)] = c_dirt
end
end --if the air

one area is like 80*80*80 nodes - whew! no wonder they write it in c!

be nice if there were a way in lua to fill arrays, oh wait there is pipes! - http://lua-users.org/wiki/FiltersAndPipesReloaded

function my_filter( pInput, pOutput )
while ... do
...
... = pInput()
...
pOutput( ... )
...
end

so a pipe we make to take our perlin nose, transform it with the content as it goes into the pipe - and to get it out we unpack() it

like in the villages mapgen https://forum.minetest.net/viewtopic.php?id=7263 - very complicated for me

ok, I get it, now on to my mapgen from a picture (picture with height info, like in 3d printing) - you have been wonderful and thank you!

"when, from defaults we fill with the id's of the textures for" <-- why I don't write explanations

PostPosted: Sun Sep 22, 2013 07:17
by paramat
leetelate wrote: if y > 0 then --above ground
data[area:index(x, y, z)] = c_air
else -- doing the ground
--handle -x and -z be snow, etc - depth will be unlimited
if x<0 and z<0 and y<0 then
data[area:index(x, y, z)] = c_stone
end
if x>=0 and z<0 and y<0 then
data[area:index(x, y, z)] = c_sand
end
if x<0 and z>=0 and y<0 then
data[area:index(x, y, z)] = c_water
end
if x>=0 and z>=0 and y<0 then
data[area:index(x, y, z)] = c_dirt
end
end --if the air

Yes but use if-then-elseif-then-else-end statements wherever possible to avoid unnecessary processing.

PostPosted: Sun Sep 22, 2013 07:58
by paramat
Forum member hmmmm is the Minetest mapgen dev, his example there is simple '3D noise mixed with a gradient type', explained simply on this page by celeron55, it describes a previous Minetest mapgen V5 http://c55.me/random/2011-07/noisestuff/
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
if nvals[ni] - (y - 25) / 55 > 0.5 then

nvals[ni] is the 3D noise.
- (y - 25) / 55 is the gradient, this term has value zero at y = 25, goes negative above and positive below.
0.5 is the density threshold for a solid node.
nvals[ni] - (y - 25) / 55 can be thought of as density.
So the line above means 'if density is above the chosen threshold then make node solid' with whatever material.

PostPosted: Sun Sep 22, 2013 10:50
by paramat
if noise - gradient > threshold then make node solid.
If there was only noise, the world would be an asteroid field of floating blobs. If there was only gradient, there would be a flatland world.

Some calculations only need to be done once per column, usually choosing the biome, so it's better to order the triple loop XZ Y, working through each column in a chunk, and for each column working either upwards or downwards depending on the advantages. So biome choosing code goes after 'for z = ... do' and before 'for y = ... do'.