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:
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.

Calinou
Moderator
Posts: 3166
Joined: Mon Aug 01, 2011 14:26
GitHub: Calinou
IRC: Calinou
In-game: Calinou
Location: Troyes, France
Contact:
Evergreen wrote:Now I have another question. Is the function math.random part of minetest?
Last edited by Calinou on Sat Feb 16, 2013 12:37, edited 1 time in total.

0gb.us
Member
Posts: 841
Joined: Sun Sep 16, 2012 01:55
Location: 0gb.us:30000
Contact:
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?

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:
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"

VanessaE
Moderator
Posts: 4566
Joined: Sun Apr 01, 2012 12:38
GitHub: VanessaE
IRC: VanessaE
In-game: VanessaE
Location: Western NC
Contact:
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)

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:
VanessaE wrote:I might point out that More Trees already has birches.
I know. Everyone and their brother has told me that already.

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:
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.

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:
The saplings officially work!

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:
The treegen is working! Now to figure out how to make them less rare...

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:
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.

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:
I tried changing the random, but that didn't seem to help.

Casimir
Member
Posts: 1189
Joined: Fri Aug 03, 2012 16:59
GitHub: CasimirKaPazi
So, how do I get the position of an entity?

pandaro
Member
Posts: 323
Joined: Sun Jan 08, 2012 21:34
GitHub: pandaro
Location: behind
! 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.
Linux debian 7 wheezy 64
kde

Member
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
Location: Germany
pandaro wrote:type:
self:getpos()
Nope, its:

Code: Select all

``self.object:getpos()``

Topywo
Member
Posts: 1721
Joined: Fri May 18, 2012 20:27
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.

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:
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.

4aiman
Member
Posts: 1208
Joined: Mon Jul 30, 2012 05:47
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.

Topywo
Member
Posts: 1721
Joined: Fri May 18, 2012 20:27
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.

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:
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.

jojoa1997
Member
Posts: 2890
Joined: Thu Dec 13, 2012 05:11
Location: Earth
when people put .. in there code what does it mean?
Coding;
1X coding
3X debugging
12X tweaking to be just right

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:
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

Topywo
Member
Posts: 1721
Joined: Fri May 18, 2012 20:27
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)

Topywo
Member
Posts: 1721
Joined: Fri May 18, 2012 20:27
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.

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:
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``````

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:
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.