52 lines
1013 B
Lua
52 lines
1013 B
Lua
local modname = minetest.get_current_modname()
|
|
|
|
blockgame.tree = blockgame.tree or {}
|
|
local api = blockgame.tree
|
|
|
|
-- TODO move these to the general api since they're not tree-specific.
|
|
local sides = {
|
|
vector.new(0, 0, -1),
|
|
vector.new(0, 0, 1),
|
|
vector.new(-1, 0, 0),
|
|
vector.new(1, 0, 0),
|
|
}
|
|
|
|
local directions = {
|
|
vector.new(0, 0, -1),
|
|
vector.new(0, 0, 1),
|
|
vector.new(0, -1, 0),
|
|
vector.new(0, 1, 0),
|
|
vector.new(-1, 0, 0),
|
|
vector.new(1, 0, 0),
|
|
}
|
|
|
|
blockgame.random_side = function ()
|
|
return sides[math.random(#sides)]
|
|
end
|
|
blockgame.random_dir = function ()
|
|
return directions[math.random(#directions)]
|
|
end
|
|
|
|
blockgame.get_below = function (pos)
|
|
return pos + vector.new(0, -1, 0)
|
|
end
|
|
-- end of TODO
|
|
|
|
|
|
|
|
api.find_bottom_log = function (pos, max_height)
|
|
local pos = vector.copy(pos)
|
|
local step = 0
|
|
while step < max_height do
|
|
local new_pos = blockgame.get_below(pos)
|
|
if minetest.get_node(new_pos).name ~= modname .. ":log" then
|
|
return pos
|
|
end
|
|
pos = new_pos
|
|
|
|
step = step + 1
|
|
end
|
|
return nil
|
|
end
|
|
|