Page 1 of 1

Mapgen Version 7 Trees Posted: Wed Jan 14, 2015 16:50
I really like the speed of version 7 mapgen, but there are no trees so it's a little boring. Here is a simple method to bring trees to Version 7, which is built off of Pilzadam's fantastic Farming_Plus mod:
Code: Select all
--Grow Tree
minetest.register_on_generated(function(minp, maxp, seed)
if maxp.y <= 150 or minp.y >= 0 then
-- Generate plants (code from flowers)
local perlin1 = minetest.get_perlin(974, 3, 0.6, 100)
-- Assume X and Z lengths are equal
local divlen = 16
local divs = (maxp.x-minp.x)/divlen+1;
for divx=0,divs-1 do
for divz=0,divs-1 do
local x0 = minp.x + math.floor((divx+0)*divlen)
local z0 = minp.z + math.floor((divz+0)*divlen)
local x1 = minp.x + math.floor((divx+1)*divlen)
local z1 = minp.z + math.floor((divz+1)*divlen)
-- Determine flowers amount from perlin noise
local grass_amount = math.floor(perlin1:get2d({x=x0, y=z0}) ^ 3 * 9)
-- Find random positions for flowers based on this random
local pr = PseudoRandom(seed+456)
for i=0,grass_amount do
local x = pr:next(x0, x1)
local z = pr:next(z0, z1)
-- Find ground level (0...15)
local ground_y = nil
for y=30,0,-1 do
if minetest.get_node({x=x,y=y,z=z}).name ~= "air" then
ground_y = y
break
end
end
if ground_y then
local p = {x=x,y=ground_y+1,z=z}
local nn = minetest.get_node(p).name
-- Check if the node can be replaced
if minetest.registered_nodes[nn] and
minetest.registered_nodes[nn].buildable_to then
nn = minetest.get_node({x=x,y=ground_y,z=z}).name
if nn == "default:dirt_with_grass" then
local possibilities = {true,false}
local is_apple_tree = possibilities[math.random(1,2)]
default.grow_tree(p, is_apple_tree)
end
end
end
end
end
end
end
end)

Re: Mapgen Version 7 Trees Posted: Wed Jan 14, 2015 18:14
It has no trees because they are not defined. You need a Mapgenv7 mod. minetest_game doesn't fully support MapgenV7 yet, so doesn't define biomes or decorations.

Trees are placed using decorations.