Page 4 of 169

Posted: Sat Feb 16, 2013 12:18
by Evergreen
I'm getting so close to finishing my birch tree mod. PilzAdam, I used your rubber.lua from your farming mod to generate the trees, make the sapling, leaves, and sapling growth.

Here is the tree growth that seems to cause a problem when I add it to the code.

Code: Select all

llocal generate_birch_tree = function(pos)
    node = {name = ""}
    for dy=1,4 do
        pos.y = pos.y+dy
        if minetest.env:get_node(pos).name ~= "air" then
            return
        end
        pos.y = pos.y-dy
    end
    node.name = "birch:tree"
    for dy=0,4 do
        pos.y = pos.y+dy
        minetest.env:set_node(pos, node)
        pos.y = pos.y-dy
    end
    
    node.name = "birch:leaves"
    pos.y = pos.y+3
    for dx=-2,2 do
        for dz=-2,2 do
            for dy=0,3 do
                pos.x = pos.x+dx
                pos.y = pos.y+dy
                pos.z = pos.z+dz
                
                if dx == 0 and dz == 0 and dy==3 then
                    if minetest.env:get_node(pos).name == "air" and math.random(1, 5) <= 4 then
                        minetest.env:set_node(pos, node)
                    end
                elseif dx == 0 and dz == 0 and dy==4 then
                    if minetest.env:get_node(pos).name == "air" and math.random(1, 5) <= 4 then
                        minetest.env:set_node(pos, node)
                    end
                elseif math.abs(dx) ~= 2 and math.abs(dz) ~= 2 then
                    if minetest.env:get_node(pos).name == "air" then
                        minetest.env:set_node(pos, node)
                    end
                else
                    if math.abs(dx) ~= 2 or math.abs(dz) ~= 2 then
                        if minetest.env:get_node(pos).name == "air" and math.random(1, 5) <= 4 then
                            minetest.env:set_node(pos, node)
                        end
                    end
                end
                
                pos.x = pos.x-dx
                pos.y = pos.y-dy
                pos.z = pos.z-dz
            end
        end
    end
end
I get a ModError when I add this to the code. PS. The name of the mod is birch.

Posted: Sat Feb 16, 2013 12:35
by Calinou
Evergreen wrote:Now I have another question. Is the function math.random part of minetest?
Minetest-related functions usually start with... "minetest". 8)

Posted: Sat Feb 16, 2013 14:49
by 0gb.us
Evergreen wrote:I'm getting so close to finishing my birch tree mod. PilzAdam, I used your rubber.lua from your farming mod to generate the trees, make the sapling, leaves, and sapling growth.

Here is the tree growth that seems to cause a problem when I add it to the code.

Code: Select all

...
I get a ModError when I add this to the code. PS. The name of the mod is birch.
"a ModError" isn't very specific. What is the error?

Posted: Sat Feb 16, 2013 15:04
by Evergreen
0gb.us wrote:
Evergreen wrote:I'm getting so close to finishing my birch tree mod. PilzAdam, I used your rubber.lua from your farming mod to generate the trees, make the sapling, leaves, and sapling growth.

Here is the tree growth that seems to cause a problem when I add it to the code.

Code: Select all

...
I get a ModError when I add this to the code. PS. The name of the mod is birch.
"a ModError" isn't very specific. What is the error?
It says, "ModError: Failed to load and run /home/.minetest/mods/minetest/birch"

Posted: Sat Feb 16, 2013 15:59
by VanessaE
I might point out that More Trees already has birches.

Posted: Sat Feb 16, 2013 16:17
by Evergreen
VanessaE wrote:I might point out that More Trees already has birches.
I know. Everyone and their brother has told me that already.

Posted: Sat Feb 16, 2013 16:20
by Evergreen
Whoops, nevermind, that was a stupid mistake. "llocal" XD

Posted: Sat Feb 16, 2013 16:23
by Evergreen
The saplings officially work!

Posted: Sat Feb 16, 2013 16:42
by Evergreen
The treegen is working! Now to figure out how to make them less rare...

Posted: Sat Feb 16, 2013 17:42
by Evergreen
I need to ask this question to PilzAdam, because he is the one who coded the tree generation.
Here is the code for the generation of birch trees.

Code: Select all

minetest.register_on_generated(function(minp, maxp, blockseed)
    if math.random(1, 100) ~= 1 then
        return
    end
    local tmp = {x=(maxp.x-minp.x)/2+minp.x, y=(maxp.y-minp.y)/2+minp.y, z=(maxp.z-minp.z)/2+minp.z}
    local pos = minetest.env:find_node_near(tmp, maxp.x-minp.x, {"default:dirt_with_grass"})
    if pos ~= nil then
        generate_birch_tree({x=pos.x, y=pos.y+1, z=pos.z})
    end
end)
Please tell me how to make them less rare.

Posted: Sat Feb 16, 2013 18:25
by Evergreen
I tried changing the random, but that didn't seem to help.

Posted: Sat Feb 16, 2013 21:48
by Casimir
So, how do I get the position of an entity?

Posted: Sat Feb 16, 2013 22:31
by pandaro
! attention this is wrong!

type:
self:getpos()

! attention this is wrong!

Posted: Sat Feb 16, 2013 22:32
by PilzAdam
pandaro wrote:type:
self:getpos()
Nope, its:

Code: Select all

self.object:getpos()

Posted: Sat Feb 16, 2013 23:51
by Topywo
Evergreen wrote:I tried changing the random, but that didn't seem to help.
I think you must lower the 100. Just try changing it in 1 or 2 for a quick result.

Edit: teleport to an unloaded chunk or create a new world.

Posted: Sun Feb 17, 2013 00:17
by Evergreen
Topywo wrote:
Evergreen wrote:I tried changing the random, but that didn't seem to help.
I think you must lower the 100. Just try changing it in 1 or 2 for a quick result.

Edit: teleport to an unloaded chunk or create a new world.
Already did that, didn't seem to make a difference.

Posted: Sun Feb 17, 2013 08:15
by 4aiman
Evergreen wrote:
Topywo wrote:
Evergreen wrote:I tried changing the random, but that didn't seem to help.
I think you must lower the 100. Just try changing it in 1 or 2 for a quick result.

Edit: teleport to an unloaded chunk or create a new world.
Already did that, didn't seem to make a difference.
You may repeat that code twice to increase chances to have at least 1 tree ;)
Well, technically it wouldn't increase, but still.

Posted: Sun Feb 17, 2013 09:38
by Topywo
Evergreen wrote:The treegen is working! Now to figure out how to make them less rare...
I didn't suggest the following before because you wrote you got the treegen working.

In your birch code I don't see the green marked part of the rubber tree code:

farmingplus/rubber.lua:

farming:generate_tree({x=pos.x, y=pos.y+1, z=pos.z}, "farming_plus:rubber_tree_full", "farming_plus:rubber_leaves", {"default:dirt", "default:dirt_with_grass"})

As far as I understand, it tells which nodes to place where.

The function for it is in:

farming/init.lua

function farming:generate_tree(pos, trunk, leaves, underground, replacements)

I hope this might solve the problems.

Posted: Sun Feb 17, 2013 12:21
by Evergreen
Topywo wrote:
Evergreen wrote:The treegen is working! Now to figure out how to make them less rare...
I didn't suggest the following before because you wrote you got the treegen working.

In your birch code I don't see the green marked part of the rubber tree code:

farmingplus/rubber.lua:

farming:generate_tree({x=pos.x, y=pos.y+1, z=pos.z}, "farming_plus:rubber_tree_full", "farming_plus:rubber_leaves", {"default:dirt", "default:dirt_with_grass"})

As far as I understand, it tells which nodes to place where.

The function for it is in:

farming/init.lua

function farming:generate_tree(pos, trunk, leaves, underground, replacements)

I hope this might solve the problems.
Thanks! I'll take all the help I can get.

Posted: Sun Feb 17, 2013 16:37
by jojoa1997
when people put .. in there code what does it mean?

Posted: Sun Feb 17, 2013 19:20
by Evergreen
Now, there is a problem that I had noticed. Birch trees don't like to spawn near other trees for some reason. They also seem to like to spawn near deserts as well

Posted: Sun Feb 17, 2013 20:01
by Topywo
jojoa1997 wrote:when people put .. in there code what does it mean?
It's a concatenation

"Strings can be joined together using the concatenation operator"

http://lua-users.org/wiki/TutorialDirectory

(under strings tutorial)

Posted: Sun Feb 17, 2013 20:07
by Topywo
Evergreen wrote:Now, there is a problem that I had noticed. Birch trees don't like to spawn near other trees for some reason. They also seem to like to spawn near deserts as well
Perhaps the leaves of the other trees are blocking it. If the code is like the farming/init.lua, there'll be a check if there's a non-air node between y=1 and y=4. If so, then there will not be a tree generated.

Posted: Sun Feb 17, 2013 20:14
by Evergreen
Topywo wrote:
Evergreen wrote:Now, there is a problem that I had noticed. Birch trees don't like to spawn near other trees for some reason. They also seem to like to spawn near deserts as well
Perhaps the leaves of the other trees are blocking it. If the code is like the farming/init.lua, there'll be a check if there's a non-air node between y=1 and y=4. If so, then there will not be a tree generated.
Welp, here's the code again. There is a check for a non air node somewhere in this code.

Code: Select all

local generate_birch_tree = function(pos, trunk, leaves, underground, replacements)
    node = {name = ""}
    for dy=1,4 do
        pos.y = pos.y+dy
        if minetest.env:get_node(pos).name ~= "air" then
            return
        end
        pos.y = pos.y-dy
    end
    node.name = "birch:tree"
    for dy=0,4 do
        pos.y = pos.y+dy
        minetest.env:set_node(pos, node)
        pos.y = pos.y-dy
    end
    
    node.name = "birch:leaves"
    pos.y = pos.y+3
    for dx=-2,2 do
        for dz=-2,2 do
            for dy=0,3 do
                pos.x = pos.x+dx
                pos.y = pos.y+dy
                pos.z = pos.z+dz
                
                if dx == 0 and dz == 0 and dy==3 then
                    if minetest.env:get_node(pos).name == "air" and math.random(1, 5) <= 4 then
                        minetest.env:set_node(pos, node)
                    end
                elseif dx == 0 and dz == 0 and dy==4 then
                    if minetest.env:get_node(pos).name == "air" and math.random(1, 5) <= 4 then
                        minetest.env:set_node(pos, node)
                    end
                elseif math.abs(dx) ~= 2 and math.abs(dz) ~= 2 then
                    if minetest.env:get_node(pos).name == "air" then
                        minetest.env:set_node(pos, node)
                    end
                else
                    if math.abs(dx) ~= 2 or math.abs(dz) ~= 2 then
                        if minetest.env:get_node(pos).name == "air" and math.random(1, 5) <= 4 then
                            minetest.env:set_node(pos, node)
                        end
                    end
                end
                
                pos.x = pos.x-dx
                pos.y = pos.y-dy
                pos.z = pos.z-dz
            end
        end
    end
end

Posted: Sun Feb 17, 2013 20:18
by Evergreen
Do I need to get rid of just this part of the code?

Code: Select all

for dy=1,4 do
        pos.y = pos.y+dy
        if minetest.env:get_node(pos).name ~= "air" then
            return
        end
        pos.y = pos.y-dy
    end
Because if the block that it checks is air, it will continue, but if it isn't it won't generate a tree.