Page 1 of 1

how to tell if I am the top of the tree?

PostPosted: Fri Oct 05, 2012 02:37
by Microsuperman
I'm learning how to make mods, and well playing around with jeija's tutoral. I strip all the leaves off of the trees. so I want to put them back on. but I need to know when I am 2 tree blocks from the top. So my question is how do you tell when I am not on the top of the tree.

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"},
    interval = 1,
    chance = 10,
    action = function(pos)
        pos.y=pos.y+math.random(1,3)
        pos.x=pos.x+math.random(-3,3)
        pos.z=pos.z+math.random(-3,3)
        --pos.y=pos.y+1
        --minetest.env:remove_node(pos) -- this is what used to get remove all the leaves.
        minetest.env:add_node(pos, {name="default:leaves"})
    end,
})


This works pretty good, but it is also changing the tree trunks into leaves as well and I don't want it to do that.
how do you find out if and what the blocks are a-round a block?

PostPosted: Fri Oct 05, 2012 12:56
by PilzAdam
Use 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
action = function(pos)
    pos.y = pos.y+1 -- go one block higher
    if minetest.env:get_node(pos).name ~= "air" then -- if the block above is not air (e.g. tree)
        return -- do not continue
    end
    pos.y = pos.y-1 -- go back to the tree node

    -- your code
    pos.y=pos.y+math.random(1,3)
    pos.x=pos.x+math.random(-3,3)
    pos.z=pos.z+math.random(-3,3)
    --pos.y=pos.y+1
    --minetest.env:remove_node(pos) -- this is what used to get remove all the leaves.
    minetest.env:add_node(pos, {name="default:leaves"})
end,