Post your modding questions here

User avatar
Evergreen
Member
Posts: 2135
Joined: Sun Jan 06, 2013 01:22
GitHub: 4Evergreen4
IRC: EvergreenTree
In-game: Evergreen
Location: A forest in the midwest
Contact:

by Evergreen » Post

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.
Back from the dead!

User avatar
Calinou
Moderator
Posts: 3162
Joined: Mon Aug 01, 2011 14:26
GitHub: Calinou
IRC: Calinou
In-game: Calinou
Location: Troyes, France
Contact:

by Calinou » Post

Evergreen wrote:Now I have another question. Is the function math.random part of minetest?
Minetest-related functions usually start with... "minetest". 8)
Last edited by Calinou on Sat Feb 16, 2013 12:37, edited 1 time in total.

User avatar
0gb.us
Member
Posts: 841
Joined: Sun Sep 16, 2012 01:55
Location: 0gb.us:30000
Contact:

by 0gb.us » Post

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?

User avatar
Evergreen
Member
Posts: 2135
Joined: Sun Jan 06, 2013 01:22
GitHub: 4Evergreen4
IRC: EvergreenTree
In-game: Evergreen
Location: A forest in the midwest
Contact:

by Evergreen » Post

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"
Back from the dead!

User avatar
VanessaE
Moderator
Posts: 4504
Joined: Sun Apr 01, 2012 12:38
GitHub: VanessaE
IRC: VanessaE
In-game: VanessaE
Location: Western NC
Contact:

by VanessaE » Post

I might point out that More Trees already has birches.
You might like some of my stuff: Plantlife ~ More Trees ~ Home Decor ~ Pipeworks ~ HDX Textures (64-512px)

User avatar
Evergreen
Member
Posts: 2135
Joined: Sun Jan 06, 2013 01:22
GitHub: 4Evergreen4
IRC: EvergreenTree
In-game: Evergreen
Location: A forest in the midwest
Contact:

by Evergreen » Post

VanessaE wrote:I might point out that More Trees already has birches.
I know. Everyone and their brother has told me that already.
Back from the dead!

User avatar
Evergreen
Member
Posts: 2135
Joined: Sun Jan 06, 2013 01:22
GitHub: 4Evergreen4
IRC: EvergreenTree
In-game: Evergreen
Location: A forest in the midwest
Contact:

by Evergreen » Post

Whoops, nevermind, that was a stupid mistake. "llocal" XD
Last edited by Evergreen on Sat Feb 16, 2013 16:20, edited 1 time in total.
Back from the dead!

User avatar
Evergreen
Member
Posts: 2135
Joined: Sun Jan 06, 2013 01:22
GitHub: 4Evergreen4
IRC: EvergreenTree
In-game: Evergreen
Location: A forest in the midwest
Contact:

by Evergreen » Post

The saplings officially work!
Back from the dead!

User avatar
Evergreen
Member
Posts: 2135
Joined: Sun Jan 06, 2013 01:22
GitHub: 4Evergreen4
IRC: EvergreenTree
In-game: Evergreen
Location: A forest in the midwest
Contact:

by Evergreen » Post

The treegen is working! Now to figure out how to make them less rare...
Back from the dead!

User avatar
Evergreen
Member
Posts: 2135
Joined: Sun Jan 06, 2013 01:22
GitHub: 4Evergreen4
IRC: EvergreenTree
In-game: Evergreen
Location: A forest in the midwest
Contact:

by Evergreen » Post

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.
Back from the dead!

User avatar
Evergreen
Member
Posts: 2135
Joined: Sun Jan 06, 2013 01:22
GitHub: 4Evergreen4
IRC: EvergreenTree
In-game: Evergreen
Location: A forest in the midwest
Contact:

by Evergreen » Post

I tried changing the random, but that didn't seem to help.
Back from the dead!

User avatar
Casimir
Member
Posts: 1163
Joined: Fri Aug 03, 2012 16:59
GitHub: CasimirKaPazi

by Casimir » Post

So, how do I get the position of an entity?

User avatar
pandaro
Member
Posts: 320
Joined: Sun Jan 08, 2012 21:34
GitHub: pandaro
Location: behind

by pandaro » Post

! attention this is wrong!

type:
self:getpos()

! attention this is wrong!
Last edited by pandaro on Sat Feb 16, 2013 22:35, edited 1 time in total.
sorry for bad english
Linux debian 7 wheezy 64
kde

User avatar
PilzAdam
Member
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam
Location: Germany

by PilzAdam » Post

pandaro wrote:type:
self:getpos()
Nope, its:

Code: Select all

self.object:getpos()

User avatar
Topywo
Member
Posts: 1721
Joined: Fri May 18, 2012 20:27

by Topywo » Post

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.
Last edited by Topywo on Sun Feb 17, 2013 00:01, edited 1 time in total.

User avatar
Evergreen
Member
Posts: 2135
Joined: Sun Jan 06, 2013 01:22
GitHub: 4Evergreen4
IRC: EvergreenTree
In-game: Evergreen
Location: A forest in the midwest
Contact:

by Evergreen » Post

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.
Last edited by Evergreen on Sun Feb 17, 2013 00:17, edited 1 time in total.
Back from the dead!

4aiman
Member
Posts: 1208
Joined: Mon Jul 30, 2012 05:47

by 4aiman » Post

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.

User avatar
Topywo
Member
Posts: 1721
Joined: Fri May 18, 2012 20:27

by Topywo » Post

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.

User avatar
Evergreen
Member
Posts: 2135
Joined: Sun Jan 06, 2013 01:22
GitHub: 4Evergreen4
IRC: EvergreenTree
In-game: Evergreen
Location: A forest in the midwest
Contact:

by Evergreen » Post

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.
Back from the dead!

User avatar
jojoa1997
Member
Posts: 2890
Joined: Thu Dec 13, 2012 05:11
Location: Earth

by jojoa1997 » Post

when people put .. in there code what does it mean?
Coding;
1X coding
3X debugging
12X tweaking to be just right

User avatar
Evergreen
Member
Posts: 2135
Joined: Sun Jan 06, 2013 01:22
GitHub: 4Evergreen4
IRC: EvergreenTree
In-game: Evergreen
Location: A forest in the midwest
Contact:

by Evergreen » Post

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
Back from the dead!

User avatar
Topywo
Member
Posts: 1721
Joined: Fri May 18, 2012 20:27

by Topywo » Post

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)

User avatar
Topywo
Member
Posts: 1721
Joined: Fri May 18, 2012 20:27

by Topywo » Post

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.

User avatar
Evergreen
Member
Posts: 2135
Joined: Sun Jan 06, 2013 01:22
GitHub: 4Evergreen4
IRC: EvergreenTree
In-game: Evergreen
Location: A forest in the midwest
Contact:

by Evergreen » Post

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
Back from the dead!

User avatar
Evergreen
Member
Posts: 2135
Joined: Sun Jan 06, 2013 01:22
GitHub: 4Evergreen4
IRC: EvergreenTree
In-game: Evergreen
Location: A forest in the midwest
Contact:

by Evergreen » Post

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.
Back from the dead!

Locked

Who is online

Users browsing this forum: No registered users and 2 guests