Limiting tree growth [solved]

User avatar
Ragnarok
Member
 
Posts: 213
Joined: Thu Mar 22, 2012 12:56

Limiting tree growth [solved]

by Ragnarok » Thu Aug 23, 2012 23:23

I have an idea: remove all trunks and leaves 8 nodes above the dirt. I wrote simple code but I've done something wrong and all trees disappearing. Could you help me?

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_abm({

    nodenames = {"default:tree", "default:leaves"},
    interval = 0,
    chance = 1,

    action = function(pos)
        for r = -8, 0 do
            local current_node = {
                x = pos.x,
                y = pos.y + r,
                z = pos.z
            }
            if(minetest.env:get_node(current_node).name ~= "default:dirt") then
                minetest.env:remove_node(pos)
            end
        end
    end
})   



Thanks in advance
Last edited by Ragnarok on Fri Aug 24, 2012 10:38, edited 1 time in total.
 

cornernote
Member
 
Posts: 844
Joined: Wed Jul 11, 2012 15:02

by cornernote » Fri Aug 24, 2012 09:27

try this:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_abm({

    nodenames = {"default:tree", "default:leaves"},
    interval = 0,
    chance = 1,

    action = function(pos)
        -- check for dirt within 8 nodes down
        for r = -8, 0 do
            local current_pos = {x = pos.x, y = pos.y + r, z = pos.z}
            local current_node = minetest.env:get_node(current_pos).name
            if(current_node == "default:dirt" or current_node == "default:dirt_with_grass") then
                -- found dirt so return
                return
            end
        end
        -- if we didnt find dirt then remove this node
        minetest.env:remove_node(pos)
    end
})   
 

User avatar
Ragnarok
Member
 
Posts: 213
Joined: Thu Mar 22, 2012 12:56

by Ragnarok » Fri Aug 24, 2012 10:37

It works amazingly! Big thanks =) After setting r = 2 forest looks like after logging :D

OT:
I just noticed that is my hundredth post. Time to open the champagne :)
Last edited by Ragnarok on Fri Aug 24, 2012 10:40, edited 1 time in total.
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 7 guests