Page 1 of 1

Limiting tree growth [solved]

PostPosted: Thu Aug 23, 2012 23:23
by Ragnarok
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

PostPosted: Fri Aug 24, 2012 09:27
by cornernote
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
})   

PostPosted: Fri Aug 24, 2012 10:37
by Ragnarok
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 :)