Trees don't appear. Because of "find_nodes_in_area" ?

User avatar
Gael de Sailly
Member
 
Posts: 736
Joined: Sun Jan 26, 2014 17:01
Location: Lyon, France
GitHub: Gael-de-Sailly
IRC: Gael-de-Sailly
In-game: Gael-de-Sailly Ginkgoo

Trees don't appear. Because of "find_nodes_in_area" ?

by Gael de Sailly » Sun Jan 26, 2014 17:47

Hello,

I'm a new member. I'm interested by programming mods at Minetest.
I try to create a mod which adds lots of trees, called Forest. But I have a problem with the map generation.
The code of mapgen.lua :
Code: Select all
minetest.register_on_mapgen_init(function(mgparams)
    minetest.set_mapgen_params({flags="", flagmask="trees"}) -- I turn off the default tree generation
end)

minetest.register_on_generated(function(minp, maxp)
    local biomes = minetest.get_perlin(289, 1, 0.6, 200)
-- biomes is the perlin noise who give for each point of map a biome numero.
-- This numero means nothing as such, but in an other file I have defined a biome numero for each tree.
    local grass_area = minetest.find_nodes_in_area(minp, maxp, "default:dirt_with_grass") -- I search all grass nodes in the concerned area.
    for grass, pos in pairs(grass_area) do
        if math.random(12) == 12 then
            local total = 0
            local temperature = get_average_temperature(pos) -- it's a function that I have defined
            local biome = biomes:get3d(pos) * 50 + 50
            local candidates = {} -- the list of trees which can grow at this point
            local water = true
            for specie, def in pairs(apportionment) do -- I have defined a table who contains informations about apportionment for each tree
                local difference = (def.biome - biome) ^ 2 -- difference with the tree's ideal biome numero
                if def.water_proximity then -- some trees needs water
                    if minetest.find_node_near(pos, def.water_proximity, {"group:water"}) == nil then
                        water = false
                    end
                end
                if temperature <= def.temperature.max and temperature >= def.temperature.min and water then -- checks the temperature
                    if difference < def.tolerance ^ 2 then
                        local chance = def.frequency * (def.tolerance ^ 2 - difference)
                        total = total + chance
                        candidates[specie] = total
                    end
                end
            end
            local num = math.random() * total
            local max = 0
            local tree = nil
            for specie, num_chance in pairs(candidates) do -- choose the tree
                if num >= num_chance and num_chance > max then
                    tree = specie
                    max = num_chance
                end
            end
            local def = apportionment[tree]
            pos = {x = pos.x, y = pos.y + 1, z = pos.z}
            if def then
                if math.random(20) <= def.density then
                    trees[tree].method(pos, tree) -- make the tree grow
                end
            end
        end
    end
end)


I explain my problem : trees don't appear higher than y = 16 blocks. It's very embarrassing, since some species appear only in high altitude.
I think the problem is from minetest.find_nodes_in_area.
Strangely, I have not this problem when I deactivate some trees.
Can you help me ?

PS : Sorry for my bad grammar, I'm French.
Just realize how bored we would be if the world was perfect.
 

Sokomine
Member
 
Posts: 3951
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine

by Sokomine » Wed Jan 29, 2014 17:03

I didn't take a closer look at this, but have you checked out plantslib and moretrees? Those already come with a spawning algorithm. It might also help to join IRC and talk about your problem there.
A list of my mods can be found here.
 

User avatar
Gael de Sailly
Member
 
Posts: 736
Joined: Sun Jan 26, 2014 17:01
Location: Lyon, France
GitHub: Gael-de-Sailly
IRC: Gael-de-Sailly
In-game: Gael-de-Sailly Ginkgoo

by Gael de Sailly » Sat Feb 08, 2014 12:58

I have fixed this problem. It was very silly. It was from the variant "water". It was not reset for each tree, so after the jungletree which grows not farther then 16 blocks to water, trees don't appear higher than 16 blocks. I searched complex reasons, for example regarding voxel areas (they are 16 blocks of lenght) but it was very simple.

An other thing : I have noticed Vanessa Ezekowiz has already created a mod which adds trees. But when I began, I didn't know this. But I am very motivated by creating mods and I continue programming it. I'm sorry for she.

The principle of my mod will be to reproduce the natural repartition of the trees, with very dense forest of oaks and beeches, and birches more scattered in plains, for example. I'm also working on rivers.
Just realize how bored we would be if the world was perfect.
 


Return to WIP Mods



Who is online

Users browsing this forum: Hume2 and 3 guests

cron