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

Microsuperman
New member
 
Posts: 7
Joined: Fri Oct 05, 2012 01:43

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

by Microsuperman » Fri Oct 05, 2012 02:37

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?
Last edited by Microsuperman on Fri Oct 05, 2012 02:47, edited 1 time in total.
 

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

by PilzAdam » Fri Oct 05, 2012 12:56

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,
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 14 guests

cron