Remove growing_trees
Signed-off-by: Daniel Borchmann <daniel@algebra20.de>
This commit is contained in:
parent
ce4fdae099
commit
c884b596b1
@ -1,278 +0,0 @@
|
||||
-------------------------------------------------------------------------------
|
||||
-- Growing Trees Mod by Sapier
|
||||
--
|
||||
-- License GPLv3
|
||||
--
|
||||
--! @file abms.lua
|
||||
--! @brief file containing abms doing growing
|
||||
--! mod
|
||||
--! @copyright Sapier
|
||||
--! @author Sapier
|
||||
--! @date 2012-09-04
|
||||
--
|
||||
-- Contact sapier a t gmx net
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
--
|
||||
-- grow trunk abm
|
||||
--
|
||||
-------------------------------------------------------------------------------
|
||||
minetest.register_abm({
|
||||
nodenames = { "growing_trees:trunk_sprout" },
|
||||
interval = 180,
|
||||
chance = 5,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
|
||||
growing_trees_debug("verbose","Growing_Trees: trunk_sprout ABM###################")
|
||||
|
||||
local trunktop = growing_trees_get_trunk_below(pos)
|
||||
|
||||
if trunktop == nil then
|
||||
growing_trees_debug("error","Growing_Trees: sprout not ontop of tree")
|
||||
return
|
||||
end
|
||||
|
||||
local treesize,tree_root = growing_trees_get_tree_size(trunktop)
|
||||
|
||||
if treesize > (SLOWDOWN_TREE_GROWTH_SIZE + ((MAX_TREE_SIZE - SLOWDOWN_TREE_GROWTH_SIZE)/2)) then
|
||||
local root_node = minetest.env:get_node(tree_root)
|
||||
growing_trees_debug("verbose","Growing_Trees: Tree should have big trunk does it have? " .. root_node.name)
|
||||
if root_node ~= nil and
|
||||
root_node.name ~= "growing_trees:big_trunk" then
|
||||
|
||||
growing_trees_make_trunk_big(tree_root,SLOWDOWN_TREE_GROWTH_SIZE)
|
||||
end
|
||||
end
|
||||
|
||||
--print("Treesize: " .. treesize)
|
||||
if (treesize > MAX_TREE_SIZE) then
|
||||
minetest.env:remove_node(pos)
|
||||
minetest.env:add_node(pos,{type=node,name="growing_trees:trunk_top"})
|
||||
growing_trees_debug("info","Growing_Trees: maximum tree size reached")
|
||||
return
|
||||
end
|
||||
|
||||
--reduce growing speed for trees larger then 10
|
||||
if (treesize > SLOWDOWN_TREE_GROWTH_SIZE ) then
|
||||
if math.random() > 1/treesize then
|
||||
growing_trees_debug("info","Growing_Trees: not growing due to reduced growth speed")
|
||||
return
|
||||
end
|
||||
end
|
||||
local grown = false
|
||||
|
||||
if math.random() > 0.2 then
|
||||
--print("growing straight")
|
||||
local pos_above = {x= pos.x,y=pos.y+1,z=pos.z}
|
||||
|
||||
local node_above = minetest.env:get_node(pos_above)
|
||||
|
||||
if node_above.name == "air" or
|
||||
growing_trees_node_is_type(leaves_type,node_above.name) then
|
||||
|
||||
minetest.env:remove_node(pos)
|
||||
minetest.env:add_node(pos,{type=node,name="growing_trees:trunk"})
|
||||
minetest.env:add_node(pos_above,{type=node,name="growing_trees:trunk_sprout"})
|
||||
|
||||
grown = true
|
||||
end
|
||||
end
|
||||
|
||||
if not grown then
|
||||
if growing_trees_next_to(pos,trunk_static_type) == false then
|
||||
--print("growing horizontaly")
|
||||
--decide which direction to grow trunk
|
||||
local pos_to_grow_to = growing_trees_get_random_next_to(pos)
|
||||
local node_at_pos_to_grow = minetest.env:get_node(pos_to_grow_to)
|
||||
|
||||
--check if pos is feasable
|
||||
if node_at_pos_to_grow.name == "air" or
|
||||
growing_trees_node_is_type(leaves_type,node_at_pos_to_grow.name) then
|
||||
|
||||
minetest.env:remove_node(pos)
|
||||
minetest.env:add_node(pos,{type=node,name="growing_trees:trunk"})
|
||||
|
||||
minetest.env:add_node(pos_to_grow_to,{type=node,name="growing_trees:trunk_sprout"})
|
||||
|
||||
grown = true
|
||||
end
|
||||
else
|
||||
growing_trees_debug("verbose","Not growing horizontaly twice")
|
||||
end
|
||||
end
|
||||
growing_trees_debug("verbose","Growing_Trees: trunk_sprout ABM*******************")
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
--
|
||||
-- create branch abm
|
||||
--
|
||||
-------------------------------------------------------------------------------
|
||||
minetest.register_abm({
|
||||
nodenames = trunk_static_type,
|
||||
interval = 45,
|
||||
chance = 5,
|
||||
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
growing_trees_debug("verbose","Growing_Trees: branch_add ABM###################")
|
||||
|
||||
local treesize,tree_root = growing_trees_get_tree_size(pos)
|
||||
|
||||
--don't add branches to trees to small
|
||||
if treesize < 4 then
|
||||
growing_trees_debug("verbose","Growing_Trees: branch_abm ABM*******************")
|
||||
return
|
||||
end
|
||||
|
||||
local growpos = growing_trees_get_random_next_to(pos)
|
||||
local node_at_pos = minetest.env:get_node(growpos)
|
||||
|
||||
if growing_trees_is_tree_structure(growpos) == false and
|
||||
( node_at_pos.name == "air" or
|
||||
growing_trees_node_is_type(leaves_type,node_at_pos.name)) then
|
||||
|
||||
local distance = growing_trees_min_distance(growpos)
|
||||
local next_to_branch = growing_trees_next_to_branch(growpos,nil)
|
||||
--print("branch sprout add function, distance to ground: " .. distance)
|
||||
|
||||
if distance > 2 and
|
||||
next_to_branch == false then
|
||||
minetest.env:remove_node(growpos)
|
||||
minetest.env:add_node(growpos,{type=node,name="growing_trees:branch_sprout"})
|
||||
else
|
||||
growing_trees_debug("verbose","Growing_Trees: NOT adding branch: " .. distance .. " ntb: " .. dump(next_to_branch) )
|
||||
end
|
||||
else
|
||||
growing_trees_debug("info","unable to get valid growpos for branch")
|
||||
end
|
||||
|
||||
growing_trees_debug("verbose","Growing_Trees: branch_add ABM********************")
|
||||
end
|
||||
})
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
--
|
||||
-- grow branch abm
|
||||
--
|
||||
-------------------------------------------------------------------------------
|
||||
minetest.register_abm({
|
||||
nodenames = { "growing_trees:branch_sprout" },
|
||||
interval = 90,
|
||||
chance = 5,
|
||||
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
growing_trees_debug("verbose","Growing_Trees: branch_sprout ABM###################")
|
||||
local growpos = growing_trees_get_branch_growpos(pos)
|
||||
|
||||
if growpos == nil then
|
||||
growing_trees_debug("verbose","Growing_Trees: no growpos found next to " .. dump(pos))
|
||||
return
|
||||
end
|
||||
local node_at_pos = minetest.env:get_node(growpos)
|
||||
growing_trees_debug("verbose","Growing_Trees: fetching growpos information: " .. printpos(growpos) .. " -> " .. node_at_pos.name)
|
||||
local tree_structure = growing_trees_is_tree_structure(growpos)
|
||||
local next_to_branch = growing_trees_next_to_branch(growpos,pos)
|
||||
|
||||
growing_trees_debug("verbose","Growing_Trees: evaluating growpos information " .. dump(tree_structure) .. " " .. dump(next_to_branch))
|
||||
if tree_structure == false and
|
||||
next_to_branch == false and
|
||||
( node_at_pos.name == "air" or
|
||||
growing_trees_node_is_type(leaves_type,node_at_pos.name)) then
|
||||
growing_trees_debug("verbose","valid growing pos found:" .. printpos(growpos) .. " -> " .. node_at_pos.name )
|
||||
|
||||
local branch = {}
|
||||
local distance_from_trunk,treesize,tree_root = growing_trees_get_tree_information(pos,branch)
|
||||
|
||||
if treesize == 0 or
|
||||
tree_root == nil then
|
||||
growing_trees_debug("info","Growing_Trees: unable to get tree information")
|
||||
return
|
||||
end
|
||||
|
||||
local top_distance = (tree_root.y + treesize) - pos.y
|
||||
--print ("Treesize: " .. treesize .. " Distance: " .. distance_from_trunk)
|
||||
|
||||
if (top_distance < 0) then
|
||||
growing_trees_debug("error","Growing_Trees: top_distance calculation wrong")
|
||||
top_distance = treesize
|
||||
end
|
||||
growing_trees_debug("verbose","Growing_Trees: Tree information treesize: " .. treesize ..
|
||||
" distance from trunk: " .. distance_from_trunk ..
|
||||
" distance to top: " .. top_distance .. " root_pos: " .. printpos(tree_root))
|
||||
|
||||
if (treesize > MAX_TREE_SIZE) then
|
||||
growing_trees_debug("info","Growing_Trees: branch maximum tree size reached")
|
||||
if math.random() < 0.1 then
|
||||
growing_trees_debug("info","Growing_Trees: aborting branch growth")
|
||||
minetest.env:remove_node(pos)
|
||||
minetest.env:add_node(pos,{type=node,name="growing_trees:leaves"})
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
if treesize ~= 0 and
|
||||
distance_from_trunk < treesize/4 and
|
||||
((top_distance > treesize/8) or (distance_from_trunk < top_distance))
|
||||
then
|
||||
growing_trees_debug("info","Growing_Trees: growing branch to " .. printpos(growpos))
|
||||
|
||||
minetest.env:remove_node(growpos)
|
||||
minetest.env:add_node(growpos,{type=node,name="growing_trees:branch_sprout"})
|
||||
|
||||
growing_trees_place_branch(pos)
|
||||
end
|
||||
else
|
||||
--TODO check why this happens
|
||||
growing_trees_debug("info","Growing_Trees: Position " .. printpos(growpos) .. " invalid to grow branch to ts: " .. dump(tree_structure) .. " ntb: " ..dump(next_to_branch))
|
||||
end
|
||||
|
||||
growing_trees_debug("verbose","Growing_Trees: branch_sprout ABM*******************")
|
||||
end
|
||||
})
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
--
|
||||
-- remove leaves abm
|
||||
--
|
||||
-------------------------------------------------------------------------------
|
||||
minetest.register_abm({
|
||||
nodenames = { "growing_trees:leaves" },
|
||||
interval = 10,
|
||||
chance = 2,
|
||||
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
|
||||
if math.random() < 0.3 then
|
||||
minetest.env:remove_node(pos)
|
||||
end
|
||||
end
|
||||
|
||||
})
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
--
|
||||
-- grow leaves abms
|
||||
--
|
||||
-------------------------------------------------------------------------------
|
||||
minetest.register_abm({
|
||||
nodenames = { "growing_trees:trunk_sprout" },
|
||||
interval = 5,
|
||||
chance = 2,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
growing_trees_grow_sprout_leaves(pos)
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = branch_static_type,
|
||||
interval = 5,
|
||||
chance = 2,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
growing_trees_grow_leaves(pos)
|
||||
end
|
||||
|
||||
})
|
@ -1,402 +0,0 @@
|
||||
-------------------------------------------------------------------------------
|
||||
-- Growing Trees Mod by Sapier
|
||||
--
|
||||
-- License GPLv3
|
||||
--
|
||||
--! @file branch_functions.lua
|
||||
--! @brief contains any branch related function used by growing trees mod
|
||||
--! @copyright Sapier
|
||||
--! @author Sapier
|
||||
--! @date 2012-09-04
|
||||
--
|
||||
-- Contact sapier a t gmx net
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: growing_trees_min_distance(pos)
|
||||
--
|
||||
--! @brief get minimum "free" space up and down for a specific pos
|
||||
--
|
||||
--! @param pos position to check
|
||||
--! @return minimum number of free nodes
|
||||
-------------------------------------------------------------------------------
|
||||
function growing_trees_min_distance(pos)
|
||||
|
||||
local runpos = {x=pos.x,y=pos.y-1,z=pos.z}
|
||||
|
||||
local runnode = minetest.env:get_node(runpos)
|
||||
|
||||
local distance_down = 0
|
||||
|
||||
while runnode ~= nil and (
|
||||
runnode.name == "air" or
|
||||
growing_trees_node_is_type(leaves_type,runnode.name)) do
|
||||
distance_down = distance_down +1
|
||||
runpos = {x=runpos.x,y=runpos.y-1,z=runpos.z}
|
||||
runnode = minetest.env:get_node(runpos)
|
||||
end
|
||||
|
||||
|
||||
local distance_up = 0
|
||||
|
||||
runpos = {x=pos.x,y=pos.y+1,z=pos.z}
|
||||
runnode = minetest.env:get_node(runpos)
|
||||
|
||||
while runnode ~= nil and (
|
||||
runnode.name == "air" or
|
||||
growing_trees_node_is_type(leaves_type,runnode.name)) do
|
||||
distance_up = distance_up +1
|
||||
runpos = {x=runpos.x,y=runpos.y+1,z=runpos.z}
|
||||
runnode = minetest.env:get_node(runpos)
|
||||
end
|
||||
|
||||
if (distance_down < distance_up) then
|
||||
return distance_down
|
||||
else
|
||||
return distance_up
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: growing_trees_next_to_branch(pos,origin)
|
||||
--
|
||||
--! @brief check if position is next to another branch
|
||||
--
|
||||
--! @param pos position to check
|
||||
--! @param origin not to consider
|
||||
--! @return true/false
|
||||
-------------------------------------------------------------------------------
|
||||
function growing_trees_next_to_branch(pos,origin)
|
||||
|
||||
local node_at_pos = minetest.env:get_node(pos)
|
||||
growing_trees_debug("verbose","Growing_Trees: looking for branch next to " .. dump(pos) .. " type is " .. dump(node_at_pos.name))
|
||||
|
||||
if origin ~= nil then
|
||||
local node_origin = minetest.env:get_node(origin)
|
||||
growing_trees_debug("verbose","Growing_Trees: found branch origin at " .. dump(origin) .. " type is " .. dump(node_origin.name))
|
||||
end
|
||||
|
||||
local neighbourpos = growing_trees_neighbour_positions(pos,true)
|
||||
|
||||
for i,value in ipairs(neighbourpos) do
|
||||
if (growing_trees_pos_is_type(branch_type,value)) and
|
||||
not issamepos(value,origin) then
|
||||
return true
|
||||
else
|
||||
local node = minetest.env:get_node(value)
|
||||
growing_trees_debug("verbose","Growing_Trees: node at " .. printpos(value) .. " of type " .. node.name .. " didn't match")
|
||||
end
|
||||
end
|
||||
|
||||
growing_trees_debug("info","Growing_Trees: not found another branch next to " .. printpos(pos))
|
||||
return false
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: growing_trees_next_to(pos,tolookfor,ytoo)
|
||||
--
|
||||
--! @brief find out if a pos is next to a element of type "tolookfor"
|
||||
--
|
||||
--! @param pos position to check
|
||||
--! @param tolookfor table of node types to look for
|
||||
--! @param ytoo consider y direction too
|
||||
--! @return position of neighbouring element or nil
|
||||
-------------------------------------------------------------------------------
|
||||
function growing_trees_next_to(pos,tolookfor,ytoo)
|
||||
|
||||
growing_trees_debug("verbose","Growing_Trees: looking for type at pos " .. printpos(pos) .. " try-y: " ..dump(ytoo) )
|
||||
|
||||
if pos == nil then
|
||||
growing_trees_debug("error","Growing_Trees: growing_trees_next_to trying to look for at nil pos")
|
||||
end
|
||||
|
||||
local neighbourpos = growing_trees_neighbour_positions(pos,ytoo)
|
||||
|
||||
for i,value in ipairs(neighbourpos) do
|
||||
if (growing_trees_pos_is_type(tolookfor,value)) then
|
||||
return value
|
||||
else
|
||||
local node = minetest.env:get_node(value)
|
||||
growing_trees_debug("verbose","Growing_Trees: node at " .. printpos(value) .. " of type " .. node.name .. " didn't match")
|
||||
end
|
||||
end
|
||||
|
||||
growing_trees_debug("info","Growing_Trees: not found any of " .. dump(tolookfor) .. " next to " ..printpos(pos))
|
||||
return nil
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: growing_get_branch_next_to(pos,branch)
|
||||
--
|
||||
-- @brief find next branch element not already known to be a branch element
|
||||
--
|
||||
-- @param position pos to check
|
||||
-- @param branch table containing known branch positions
|
||||
-- @return position of next branch element
|
||||
-------------------------------------------------------------------------------
|
||||
function growing_trees_get_next_new_branch_element(pos,branch)
|
||||
|
||||
if pos == nil then
|
||||
growing_trees_debug("error","Growing_Trees: growing_trees_get_next_new_branch_element trying to look for at nil pos")
|
||||
end
|
||||
|
||||
local neighbourpos = growing_trees_neighbour_positions(pos,ytoo)
|
||||
for i,value in ipairs(neighbourpos) do
|
||||
if not contains(branch,value) and
|
||||
growing_trees_pos_is_type(branch_static_type,value) then
|
||||
growing_trees_debug("verbose","Growing_Trees: found branch element at " .. printpos(value) .. " next to " ..printpos(pos))
|
||||
return value
|
||||
end
|
||||
end
|
||||
|
||||
growing_trees_debug("info","Growing_Trees: not found another branch element next to " ..printpos(pos))
|
||||
return nil
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: growing_trees_get_tree_information(pos)
|
||||
--
|
||||
-- @brief get information about tree starting evaluation from branch sprout
|
||||
--
|
||||
-- @param pos start tree evaluation
|
||||
-- @return branch_length,trunk height,root of trunk
|
||||
-------------------------------------------------------------------------------
|
||||
function growing_trees_get_tree_information(pos)
|
||||
|
||||
local distance = 0
|
||||
local treesize = 0
|
||||
local tree_root = nil
|
||||
|
||||
local branch = {}
|
||||
local current_pos = pos
|
||||
local nextpos = current_pos
|
||||
|
||||
local node_at_start = minetest.env:get_node(pos)
|
||||
growing_trees_debug("verbose","Growing_Trees: fetching tree information starting at " .. printpos(pos) .. " -> " ..node_at_start.name)
|
||||
|
||||
while nextpos ~= nil do
|
||||
distance = distance +1
|
||||
current_pos = nextpos
|
||||
nextpos = growing_trees_get_next_new_branch_element(current_pos,branch)
|
||||
table.insert(branch,nextpos)
|
||||
end
|
||||
|
||||
growing_trees_debug("verbose","Growing_Trees: looking for trunk next to " .. printpos(current_pos))
|
||||
local pos_of_trunk = growing_trees_next_to(current_pos,trunk_static_type,false)
|
||||
|
||||
if (pos_of_trunk ~= nil) then
|
||||
growing_trees_debug("verbose","Growing_Trees: fetching trunk information next to " .. printpos(pos_of_trunk))
|
||||
treesize,tree_root = growing_trees_get_tree_size(pos_of_trunk)
|
||||
else
|
||||
growing_trees_debug("error","Growing_Trees: trunk not found")
|
||||
end
|
||||
|
||||
return distance,treesize,tree_root
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: growing_trees_get_branch_growpos(pos)
|
||||
--
|
||||
--! @brief get a new branchpos next to current sprout
|
||||
--
|
||||
--! @param pos start searching around pos
|
||||
--! @return pos to grow to
|
||||
-------------------------------------------------------------------------------
|
||||
function growing_trees_get_branch_growpos(pos)
|
||||
growing_trees_debug("info","Growing_Trees: trying to get growpos next to " .. printpos(pos))
|
||||
--grow to preferred direction
|
||||
if math.random() < 0.5 then
|
||||
local origin = growing_trees_next_to(pos,branch_type,true)
|
||||
|
||||
if origin == nil then
|
||||
origin = growing_trees_next_to(pos,trunk_static_type,false)
|
||||
end
|
||||
|
||||
if origin ~= nil then
|
||||
growing_trees_debug("info","Growing_Trees: got origin for " .. printpos(pos) .. " at: " .. printpos(origin))
|
||||
if origin.x ~= pos.x then
|
||||
if origin.x < pos.x then
|
||||
return {x=pos.x+1,y=pos.y,z=pos.z}
|
||||
else
|
||||
return {x=pos.x-1,y=pos.y,z=pos.z}
|
||||
end
|
||||
end
|
||||
|
||||
if origin.z ~= pos.z then
|
||||
if origin.z < pos.z then
|
||||
return {x=pos.x,y=pos.y,z=pos.z+1}
|
||||
else
|
||||
return {x=pos.x,y=pos.y,z=pos.z-1}
|
||||
end
|
||||
end
|
||||
else
|
||||
--if origin couln't be found grow to random direction
|
||||
growing_trees_debug("error","Growing_Trees: unable to find origin for branch at: " .. printpos(pos))
|
||||
return growing_trees_get_random_next_to(pos)
|
||||
end
|
||||
else
|
||||
--grow to random direction
|
||||
growing_trees_debug("verbose","Growing_Trees: random growpos selection around " .. printpos(pos))
|
||||
return growing_trees_get_random_next_to(pos)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: growing_trees_grow_leaves(pos)
|
||||
--
|
||||
--! @brief grow leaves around pos
|
||||
--
|
||||
--! @param pos center of growth
|
||||
-------------------------------------------------------------------------------
|
||||
function growing_trees_grow_leaves(pos)
|
||||
|
||||
for x = pos.x - 1, pos.x + 1 do
|
||||
for y = pos.y - 1, pos.y + 1 do
|
||||
for z = pos.z - 1, pos.z + 1 do
|
||||
local currentpos = {x = x, y = y, z = z}
|
||||
|
||||
local current_node = minetest.env:get_node(currentpos)
|
||||
|
||||
if current_node ~= nil and
|
||||
current_node.name == "air" then
|
||||
if growing_trees_next_to(currentpos,branch_type,true) ~= nil or
|
||||
growing_trees_next_to(currentpos,leaves_type,true) ~= nil and
|
||||
math.random() < 0.4 then
|
||||
if math.random() < 0.05 and
|
||||
growing_trees_next_to(currentpos,{ "default:apple" },true) then
|
||||
minetest.env:add_node(currentpos,{type="node",name="default:apple"})
|
||||
else
|
||||
minetest.env:add_node(currentpos,{type="node",name="growing_trees:leaves"})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for x = pos.x - 2, pos.x + 2 do
|
||||
for y = pos.y - 2, pos.y + 2 do
|
||||
for z = pos.z - 2, pos.z + 2 do
|
||||
local currentpos = {x = x, y = y, z = z}
|
||||
|
||||
local distance = growing_trees_calc_distance(pos,currentpos)
|
||||
|
||||
if distance <= 2 then
|
||||
if current_node ~= nil and
|
||||
current_node.name == "air" then
|
||||
|
||||
if growing_trees_next_to(currentpos,branch_type,true) ~= nil or
|
||||
growing_trees_next_to(currentpos,leaves_type,true) ~= nil and
|
||||
math.random() < 0.2 then
|
||||
minetest.env:add_node(currentpos,{type="node",name="growing_trees:leaves"})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: growing_trees_grow_sprout_leaves(pos)
|
||||
--
|
||||
--! @brief grow leaves around trunk sprout pos
|
||||
--
|
||||
--! @param pos center of growth
|
||||
-------------------------------------------------------------------------------
|
||||
function growing_trees_grow_sprout_leaves(pos)
|
||||
for x = pos.x - 1, pos.x + 1 do
|
||||
for y = pos.y - 1, pos.y + 1 do
|
||||
for z = pos.z - 1, pos.z + 1 do
|
||||
local currentpos = {x = x, y = y, z = z}
|
||||
|
||||
local distance = growing_trees_calc_distance(pos,currentpos)
|
||||
|
||||
if distance <= 1.5 then
|
||||
local current_node = minetest.env:get_node(currentpos)
|
||||
|
||||
if current_node ~= nil and
|
||||
current_node.name == "air" then
|
||||
|
||||
if growing_trees_next_to(currentpos,trunk_type,true) ~= nil or
|
||||
growing_trees_next_to(currentpos,leaves_type,true) ~= nil and
|
||||
math.random() < 0.3 then
|
||||
minetest.env:add_node(currentpos,{type="node",name="growing_trees:leaves"})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local treesize = growing_trees_get_tree_size({x=pos.x,y=pos.y-1,z=pos.z})
|
||||
|
||||
if treesize > 2 and
|
||||
treesize < 6 then
|
||||
|
||||
for x = pos.x - 3, pos.x + 3 do
|
||||
for y = pos.y - 3, pos.y + 3 do
|
||||
for z = pos.z - 3, pos.z + 3 do
|
||||
local currentpos = {x = x, y = y, z = z}
|
||||
local current_node = minetest.env:get_node(currentpos)
|
||||
|
||||
if current_node ~= nil and
|
||||
current_node.name == "air" then
|
||||
local distance = growing_trees_calc_distance(pos,currentpos)
|
||||
if distance <= 3 then
|
||||
if growing_trees_next_to(currentpos,branch_type,true) ~= nil or
|
||||
growing_trees_next_to(currentpos,leaves_type,true) ~= nil and
|
||||
math.random() < 0.2 then
|
||||
minetest.env:add_node(currentpos,{type="node",name="growing_trees:leaves"})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: growing_trees_place_branch(pos)
|
||||
--
|
||||
--! @brief place correct branch type
|
||||
--
|
||||
--! @param pos to place branch
|
||||
-------------------------------------------------------------------------------
|
||||
function growing_trees_place_branch(pos)
|
||||
local branch_type = growing_trees_get_branch_type(pos)
|
||||
|
||||
if branch_type == "xx" then
|
||||
minetest.env:remove_node(pos)
|
||||
minetest.env:add_node(pos,{type=node,name="growing_trees:branch_xx"})
|
||||
end
|
||||
|
||||
if branch_type == "zz" then
|
||||
minetest.env:remove_node(pos)
|
||||
minetest.env:add_node(pos,{type=node,name="growing_trees:branch_zz"})
|
||||
end
|
||||
|
||||
if branch_type == "xpzp" then
|
||||
minetest.env:remove_node(pos)
|
||||
minetest.env:add_node(pos,{type=node,name="growing_trees:branch_xpzp"})
|
||||
end
|
||||
|
||||
if branch_type == "xpzm" then
|
||||
minetest.env:remove_node(pos)
|
||||
minetest.env:add_node(pos,{type=node,name="growing_trees:branch_xpzm"})
|
||||
end
|
||||
|
||||
if branch_type == "xmzp" then
|
||||
minetest.env:remove_node(pos)
|
||||
minetest.env:add_node(pos,{type=node,name="growing_trees:branch_xmzp"})
|
||||
end
|
||||
|
||||
if branch_type == "xmzm" then
|
||||
minetest.env:remove_node(pos)
|
||||
minetest.env:add_node(pos,{type=node,name="growing_trees:branch_xmzm"})
|
||||
end
|
||||
end
|
@ -1,62 +0,0 @@
|
||||
-------------------------------------------------------------------------------
|
||||
-- Growing Trees Mod by Sapier
|
||||
--
|
||||
-- License GPLv3
|
||||
--
|
||||
--! @file crafts.lua
|
||||
--! @brief file containing craft recieps and item definitions
|
||||
--! mod
|
||||
--! @copyright Sapier
|
||||
--! @author Sapier
|
||||
--! @date 2012-09-04
|
||||
--
|
||||
-- Contact sapier a t gmx net
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
function growing_trees_place_sprout(pos)
|
||||
local pos_above = {x=pos.x,y=pos.y+1,z=pos.z}
|
||||
local node = minetest.env:get_node(pos)
|
||||
local node_above = minetest.env:get_node(pos_above)
|
||||
|
||||
if node.name == "air" and
|
||||
node_above.name == "air" then
|
||||
local pos_bottom = { x=pos.x,y=pos.y-1,z=pos.z }
|
||||
|
||||
local bottom_node = minetest.env:get_node(pos_bottom)
|
||||
|
||||
if bottom_node.name == "default:dirt" or
|
||||
bottom_node.name == "default:dirt_with_grass" then
|
||||
|
||||
minetest.env:add_node(pos,{type=node,name="growing_trees:trunk"})
|
||||
minetest.env:add_node(pos_above,{type=node,name="growing_trees:trunk_sprout"})
|
||||
growing_trees_grow_sprout_leaves(pos_above)
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
minetest.register_craftitem("growing_trees:sapling", {
|
||||
description = "Sapling (growing tree mod)",
|
||||
image = "default_sapling.png",
|
||||
on_place = function(item,place,pointed_thing)
|
||||
if pointed_thing.type == "node" then
|
||||
local pos = pointed_thing.above
|
||||
if growing_trees_place_sprout(pos) then
|
||||
item:take_item(1)
|
||||
end
|
||||
end
|
||||
|
||||
return item
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
output = "growing_trees:sapling",
|
||||
recipe = {
|
||||
{"default:sapling"},
|
||||
{"default:sapling"},
|
||||
}
|
||||
})
|
@ -1 +0,0 @@
|
||||
default
|
@ -1,156 +0,0 @@
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: printpos(pos)
|
||||
--
|
||||
-- action: convert pos to string of type "(X,Y,Z)"
|
||||
--
|
||||
-- param1: position to convert
|
||||
-- retval: string with coordinates of pos
|
||||
-------------------------------------------------------------------------------
|
||||
function printpos(pos)
|
||||
if pos ~= nil then
|
||||
if pos.y ~= nil then
|
||||
return "("..pos.x..","..pos.y..","..pos.z..")"
|
||||
else
|
||||
return "("..pos.x..", ? ,"..pos.z..")"
|
||||
end
|
||||
end
|
||||
return ""
|
||||
end
|
||||
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: issamepos(pos1,pos2)
|
||||
--
|
||||
-- @brief check if two 3d positions are equal
|
||||
--
|
||||
-- @param pos1 position one
|
||||
-- @param pos2 position two
|
||||
-- @return true/false
|
||||
-------------------------------------------------------------------------------
|
||||
function issamepos(pos1,pos2)
|
||||
|
||||
if (pos1 == nil) or
|
||||
(pos2 == nil) and
|
||||
(pos1 ~= pos2) then
|
||||
return false
|
||||
end
|
||||
|
||||
if (pos1.x == pos2.x) and
|
||||
(pos1.y == pos2.y) and
|
||||
(pos1.z == pos2.z) then
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
--is element in table
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: contains(table_to_check,position)
|
||||
--
|
||||
-- @brief check if a table contains a specific position
|
||||
--
|
||||
-- @param table_to_check table to search in
|
||||
-- @param position position to search
|
||||
-- @return true/false
|
||||
-------------------------------------------------------------------------------
|
||||
function contains(table_to_check,position)
|
||||
for i,v in ipairs(table_to_check) do
|
||||
if issamepos(v,position) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: growing_trees_is_tree_structure(pos)
|
||||
--
|
||||
-- @brief check if node at pos a tree structure (leaves don't count as structure)
|
||||
--
|
||||
-- @param pos position to check
|
||||
-- @return true/false
|
||||
-------------------------------------------------------------------------------
|
||||
--
|
||||
function growing_trees_is_tree_structure(pos)
|
||||
local node = minetest.env:get_node(pos)
|
||||
|
||||
if node == nil then
|
||||
return false
|
||||
end
|
||||
|
||||
if growing_trees_node_is_type(trunk_type ,node.name) or
|
||||
growing_trees_node_is_type(branch_type ,node.name) then
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: growing_trees_get_surface(x,z, min_y, max_y)
|
||||
--
|
||||
--! @brief get surface for x/z coordinates
|
||||
--
|
||||
--! @param x x-coordinate
|
||||
--! @param z z-coordinate
|
||||
--! @param min_y minimum y-coordinate to consider
|
||||
--! @param max_y maximum y-coordinate to consider
|
||||
--! @return y value of surface or nil
|
||||
-------------------------------------------------------------------------------
|
||||
function growing_trees_get_surface(x,z, min_y, max_y)
|
||||
|
||||
for runy = min_y, max_y do
|
||||
local pos = { x=x,y=runy, z=z }
|
||||
local node_to_check = minetest.env:get_node(pos)
|
||||
|
||||
if node_to_check.name == "default:dirt_with_grass" then
|
||||
return pos.y
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: growing_trees_neighbour_positions(pos,ynodes_too)
|
||||
--
|
||||
--! @brief get positions of positions sharing a side with pos
|
||||
--
|
||||
--! @param pos position to get surrounding positions
|
||||
--! @param ynodes_too get y neighbours too
|
||||
--! @return table of positions
|
||||
-------------------------------------------------------------------------------
|
||||
function growing_trees_neighbour_positions(pos,ynodes_too)
|
||||
local retval = {}
|
||||
|
||||
table.insert(retval, {x=pos.x-1,y=pos.y,z=pos.z})
|
||||
table.insert(retval, {x=pos.x+1,y=pos.y,z=pos.z})
|
||||
table.insert(retval, {x=pos.x,y=pos.y,z=pos.z+1})
|
||||
table.insert(retval, {x=pos.x,y=pos.y,z=pos.z-1})
|
||||
|
||||
if ynodes_too then
|
||||
table.insert(retval, {x=pos.x,y=pos.y+1,z=pos.z})
|
||||
table.insert(retval, {x=pos.x,y=pos.y-1,z=pos.z})
|
||||
end
|
||||
|
||||
return retval
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: growing_trees_calc_distance(pos1,pos2)
|
||||
--
|
||||
--! @brief calculate 3d distance between to points
|
||||
--
|
||||
--! @param pos1 first position
|
||||
--! @param pos2 second position
|
||||
--! @retval scalar value, distance
|
||||
-------------------------------------------------------------------------------
|
||||
function growing_trees_calc_distance(pos1,pos2)
|
||||
return math.sqrt( math.pow(pos1.x-pos2.x,2) +
|
||||
math.pow(pos1.y-pos2.y,2) +
|
||||
math.pow(pos1.z-pos2.z,2))
|
||||
end
|
@ -1,49 +0,0 @@
|
||||
-------------------------------------------------------------------------------
|
||||
-- Growing Trees Mod by Sapier
|
||||
--
|
||||
-- License GPLv3
|
||||
--
|
||||
--! @file init.lua
|
||||
--! @brief main module file responsible for including all parts of growing tees
|
||||
--! mod
|
||||
--! @copyright Sapier
|
||||
--! @author Sapier
|
||||
--! @date 2012-09-04
|
||||
--
|
||||
-- Contact sapier a t gmx net
|
||||
-------------------------------------------------------------------------------
|
||||
local version = "0.0.9"
|
||||
|
||||
local growing_trees_modpath = minetest.get_modpath("growing_trees")
|
||||
|
||||
dofile (growing_trees_modpath .. "/type_declarations.lua")
|
||||
dofile (growing_trees_modpath .. "/models.lua")
|
||||
dofile (growing_trees_modpath .. "/trunk_functions.lua")
|
||||
dofile (growing_trees_modpath .. "/branch_functions.lua")
|
||||
dofile (growing_trees_modpath .. "/generic_functions.lua")
|
||||
dofile (growing_trees_modpath .. "/nodes.lua")
|
||||
dofile (growing_trees_modpath .. "/crafts.lua")
|
||||
dofile (growing_trees_modpath .. "/model_selection.lua")
|
||||
dofile (growing_trees_modpath .. "/abms.lua")
|
||||
dofile (growing_trees_modpath .. "/spawning.lua")
|
||||
|
||||
MAX_TREE_SIZE = 20
|
||||
SLOWDOWN_TREE_GROWTH_SIZE = 10
|
||||
|
||||
function growing_trees_debug(loglevel,text)
|
||||
--minetest.log(loglevel,text)
|
||||
--print(loglevel .. ": " .. text)
|
||||
end
|
||||
|
||||
local tree_size_setting = minetest.setting_get("growing_trees_max_size")
|
||||
local tree_slowdown_setting = minetest.setting_get("growing_trees_slowdown_size")
|
||||
|
||||
if tree_size_setting ~= nil then
|
||||
MAX_TREE_SIZE = tree_size_setting
|
||||
end
|
||||
|
||||
if tree_slowdown_setting ~= nil then
|
||||
SLOWDOWN_TREE_GROWTH_SIZE = tree_slowdown_setting
|
||||
end
|
||||
|
||||
print("growing_trees mod " .. version .. " loaded")
|
@ -1,72 +0,0 @@
|
||||
-------------------------------------------------------------------------------
|
||||
-- Growing Trees Mod by Sapier
|
||||
--
|
||||
-- License GPLv3
|
||||
--
|
||||
--! @file model_selection.lua
|
||||
--! @brief file containing functions for detecting which model to use
|
||||
--! mod
|
||||
--! @copyright Sapier
|
||||
--! @author Sapier
|
||||
--! @date 2012-09-04
|
||||
--
|
||||
-- Contact sapier a t gmx net
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
function growing_trees_get_branch_type(pos)
|
||||
|
||||
local pos_xp1 = {x=pos.x+1,y=pos.y,z=pos.z}
|
||||
local pos_xm1 = {x=pos.x-1,y=pos.y,z=pos.z}
|
||||
local pos_zp1 = {x=pos.x,y=pos.y,z=pos.z+1}
|
||||
local pos_zm1 = {x=pos.x,y=pos.y,z=pos.z-1}
|
||||
|
||||
local xp1 = growing_trees_is_tree_structure(pos_xp1)
|
||||
local xm1 = growing_trees_is_tree_structure(pos_xm1)
|
||||
local zp1 = growing_trees_is_tree_structure(pos_zp1)
|
||||
local zm1 = growing_trees_is_tree_structure(pos_zm1)
|
||||
|
||||
|
||||
if (not zm1) and
|
||||
(not zp1) and
|
||||
(xp1 or xm1) then
|
||||
return "xx"
|
||||
end
|
||||
|
||||
if (not xm1) and
|
||||
(not xp1) and
|
||||
(zp1 or zm1) then
|
||||
return "zz"
|
||||
end
|
||||
|
||||
if (not xm1) and
|
||||
(not zm1) and
|
||||
xp1 and
|
||||
zp1 then
|
||||
return "xpzp"
|
||||
end
|
||||
|
||||
if (not xp1) and
|
||||
(not zp1) and
|
||||
xm1 and
|
||||
zm1 then
|
||||
return "xmzm"
|
||||
end
|
||||
|
||||
if (not xp1) and
|
||||
(not zm1) and
|
||||
xm1 and
|
||||
zp1 then
|
||||
return "xmzp"
|
||||
end
|
||||
|
||||
if (not xm1) and
|
||||
(not zp1) and
|
||||
xp1 and
|
||||
zm1 then
|
||||
return "xpzm"
|
||||
end
|
||||
|
||||
|
||||
|
||||
return "ukn"
|
||||
end
|
@ -1,168 +0,0 @@
|
||||
-------------------------------------------------------------------------------
|
||||
-- Growing Trees Mod by Sapier
|
||||
--
|
||||
-- License GPLv3
|
||||
--
|
||||
--! @file models.lua
|
||||
--! @brief file containing model definitions
|
||||
--! mod
|
||||
--! @copyright Sapier
|
||||
--! @author Sapier
|
||||
--! @date 2012-09-04
|
||||
--
|
||||
-- Contact sapier a t gmx net
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
|
||||
function x(val)
|
||||
return (((val -4) / 8) * 0.7)
|
||||
end
|
||||
|
||||
function z(val)
|
||||
return (((val -4) / 8) * 0.7)
|
||||
end
|
||||
|
||||
function y(val)
|
||||
return (((val + 4) / 8) * 0.7)
|
||||
end
|
||||
|
||||
function xo(val)
|
||||
return (val -0.5)
|
||||
end
|
||||
|
||||
function zo(val)
|
||||
return (val -0.5)
|
||||
end
|
||||
|
||||
function yo(val)
|
||||
return (val + 0.5)
|
||||
end
|
||||
|
||||
nodebox_trunk_sprout = {
|
||||
{-0.35,-0.5,-0.4, 0.35,-0.2,0.4},
|
||||
{-0.4,-0.5,-0.35, 0.4,-0.2,0.35},
|
||||
{-0.25,-0.5,-0.45, 0.25,-0.2,0.45},
|
||||
{-0.45,-0.5,-0.25, 0.45,-0.2,0.25},
|
||||
{-0.15,-0.5,-0.5, 0.15,-0.2,0.5},
|
||||
{-0.5,-0.5,-0.15, 0.5,-0.2,0.15},
|
||||
|
||||
|
||||
|
||||
{-0.10,-0.2,-0.45, 0.10,0.1,0.45},
|
||||
{-0.20,-0.2,-0.40, 0.20,0.1,0.40},
|
||||
{-0.30,-0.2,-0.35, 0.30,0.1,0.35},
|
||||
{-0.35,-0.2,-0.30, 0.35,0.1,0.30},
|
||||
{-0.40,-0.2,-0.20, 0.40,0.1,0.20},
|
||||
{-0.45,-0.2,-0.10, 0.45,0.1,0.10},
|
||||
|
||||
|
||||
{-0.05,0.1,-0.4, 0.05,0.5,0.4},
|
||||
{-0.15,0.1,-0.35, 0.15,0.5,0.35},
|
||||
{-0.25,0.1,-0.3, 0.25,0.5,0.3},
|
||||
{-0.3,0.1,-0.25, 0.3,0.5,0.25},
|
||||
{-0.35,0.1,-0.15, 0.35,0.5,0.15},
|
||||
{-0.4,0.1,-0.05, 0.4,0.5,0.05},
|
||||
}
|
||||
|
||||
-- ...
|
||||
-- www
|
||||
-- ...
|
||||
nodebox_branch_xx = {
|
||||
{ xo(-0.1), y(0), z(6), xo(1.1), y(-1), z(2)},
|
||||
{ xo(-0.1), y(-1), z(7), xo(1.1), y(-2), z(1)},
|
||||
{ xo(-0.1), y(-2), z(8), xo(1.1), y(-6), z(0)},
|
||||
{ xo(-0.1), y(-6), z(7), xo(1.1), y(-7), z(1)},
|
||||
{ xo(-0.1), y(-7), z(6), xo(1.1), y(-8), z(2)},
|
||||
}
|
||||
|
||||
-- .w.
|
||||
-- .w.
|
||||
-- .w.
|
||||
nodebox_branch_zz = {
|
||||
{ x(2), y(0), zo(1.1), x(6), y(-1), zo(-0.1)},
|
||||
{ x(1), y(-1), zo(1.1), x(7), y(-2), zo(-0.1)},
|
||||
{ x(0), y(-2), zo(1.1), x(8), y(-6), zo(-0.1)},
|
||||
{ x(1), y(-6), zo(1.1), x(7), y(-7), zo(-0.1)},
|
||||
{ x(2), y(-7), zo(1.1), x(6), y(-8), zo(-0.1)},
|
||||
}
|
||||
|
||||
-- .w.
|
||||
-- www
|
||||
-- .w.
|
||||
nodebox_branch_ukn = {
|
||||
{ x(2), y(0), zo(1.1), x(6), y(-1), zo(-0.1)},
|
||||
{ x(1), y(-1), zo(1.1), x(7), y(-2), zo(-0.1)},
|
||||
{ x(0), y(-2), zo(1.1), x(8), y(-6), zo(-0.1)},
|
||||
{ x(1), y(-6), zo(1.1), x(7), y(-7), zo(-0.1)},
|
||||
{ x(2), y(-7), zo(1.1), x(6), y(-8), zo(-0.1)},
|
||||
{ xo(-0.1), y(0), z(6), xo(1.1), y(-1), z(2)},
|
||||
{ xo(-0.1), y(-1), z(7), xo(1.1), y(-2), z(1)},
|
||||
{ xo(-0.1), y(-2), z(8), xo(1.1), y(-6), z(0)},
|
||||
{ xo(-0.1), y(-6), z(7), xo(1.1), y(-7), z(1)},
|
||||
{ xo(-0.1), y(-7), z(6), xo(1.1), y(-8), z(2)},
|
||||
}
|
||||
|
||||
|
||||
-- .w.
|
||||
-- .ww
|
||||
-- ...
|
||||
nodebox_branch_xpzp = {
|
||||
{ x(2), y(0), zo(1.1), x(6), y(-1), z(2)},
|
||||
{ x(1), y(-1), zo(1.1), x(7), y(-2), z(1)},
|
||||
{ x(0), y(-2), zo(1.1), x(8), y(-6), z(0)},
|
||||
{ x(1), y(-6), zo(1.1), x(7), y(-7), z(1)},
|
||||
{ x(2), y(-7), zo(1.1), x(6), y(-8), z(2)},
|
||||
{ x(2), y(0), z(6), xo(1.1), y(-1), z(2)},
|
||||
{ x(1), y(-1), z(7), xo(1.1), y(-2), z(1)},
|
||||
{ x(0), y(-2), z(8), xo(1.1), y(-6), z(0)},
|
||||
{ x(1), y(-6), z(7), xo(1.1), y(-7), z(1)},
|
||||
{ x(2), y(-7), z(6), xo(1.1), y(-8), z(2)},
|
||||
}
|
||||
|
||||
-- ...
|
||||
-- .ww
|
||||
-- .w.
|
||||
nodebox_branch_xpzm = {
|
||||
{ x(2), y(0), z(6), x(6), y(-1), zo(-0.1)},
|
||||
{ x(1), y(-1), z(7), x(7), y(-2), zo(-0.1)},
|
||||
{ x(0), y(-2), z(8), x(8), y(-6), zo(-0.1)},
|
||||
{ x(1), y(-6), z(7), x(7), y(-7), zo(-0.1)},
|
||||
{ x(2), y(-7), z(6), x(6), y(-8), zo(-0.1)},
|
||||
{ x(2), y(0), z(6), xo(1.1), y(-1), z(2)},
|
||||
{ x(1), y(-1), z(7), xo(1.1), y(-2), z(1)},
|
||||
{ x(0), y(-2), z(8), xo(1.1), y(-6), z(0)},
|
||||
{ x(1), y(-6), z(7), xo(1.1), y(-7), z(1)},
|
||||
{ x(2), y(-7), z(6), xo(1.1), y(-8), z(2)},
|
||||
}
|
||||
|
||||
-- .w.
|
||||
-- ww.
|
||||
-- ...
|
||||
nodebox_branch_xmzp = {
|
||||
{ x(2), y(0), zo(1.1), x(6), y(-1), z(2)},
|
||||
{ x(1), y(-1), zo(1.1), x(7), y(-2), z(1)},
|
||||
{ x(0), y(-2), zo(1.1), x(8), y(-6), z(0)},
|
||||
{ x(1), y(-6), zo(1.1), x(7), y(-7), z(1)},
|
||||
{ x(2), y(-7), zo(1.1), x(6), y(-8), z(2)},
|
||||
{ xo(-0.1), y(0), z(6), x(6), y(-1), z(2)},
|
||||
{ xo(-0.1), y(-1), z(7), x(7), y(-2), z(1)},
|
||||
{ xo(-0.1), y(-2), z(8), x(8), y(-6), z(0)},
|
||||
{ xo(-0.1), y(-6), z(7), x(7), y(-7), z(1)},
|
||||
{ xo(-0.1), y(-7), z(6), x(6), y(-8), z(2)},
|
||||
}
|
||||
|
||||
-- ...
|
||||
-- ww.
|
||||
-- .w.
|
||||
nodebox_branch_xmzm = {
|
||||
{ x(2), y(0), z(6), x(6), y(-1), zo(-0.1)},
|
||||
{ x(1), y(-1), z(7), x(7), y(-2), zo(-0.1)},
|
||||
{ x(0), y(-2), z(8), x(8), y(-6), zo(-0.1)},
|
||||
{ x(1), y(-6), z(7), x(7), y(-7), zo(-0.1)},
|
||||
{ x(2), y(-7), z(6), x(6), y(-8), zo(-0.1)},
|
||||
{ xo(-0.1), y(0), z(6), x(6), y(-1), z(2)},
|
||||
{ xo(-0.1), y(-1), z(7), x(7), y(-2), z(1)},
|
||||
{ xo(-0.1), y(-2), z(8), x(8), y(-6), z(0)},
|
||||
{ xo(-0.1), y(-6), z(7), x(7), y(-7), z(1)},
|
||||
{ xo(-0.1), y(-7), z(6), x(6), y(-8), z(2)},
|
||||
}
|
@ -1,327 +0,0 @@
|
||||
-------------------------------------------------------------------------------
|
||||
-- Growing Trees Mod by Sapier
|
||||
--
|
||||
-- License GPLv3
|
||||
--
|
||||
--! @file nodes.lua
|
||||
--! @brief file containing node definitions
|
||||
--! mod
|
||||
--! @copyright Sapier
|
||||
--! @author Sapier
|
||||
--! @date 2012-09-04
|
||||
--
|
||||
-- Contact sapier a t gmx net
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
local textures_trunk = {"default_tree_top.png", "default_tree_top.png", "default_tree.png"}
|
||||
local textures_branch_xx = {"default_tree.png", "default_tree.png", "default_tree_top.png","default_tree_top.png","default_tree.png", "default_tree.png"}
|
||||
local textures_branch_zz = {"default_tree.png", "default_tree.png","default_tree.png", "default_tree.png", "default_tree_top.png","default_tree_top.png"}
|
||||
local textures_branch = {"default_tree_top.png", "default_tree_top.png", "default_tree.png"}
|
||||
local textures_branch_xpzp = {"default_tree.png", "default_tree.png","default_tree_top.png", "default_tree.png", "default_tree.png","default_tree_top.png"}
|
||||
local textures_branch_xmzm = {"default_tree.png", "default_tree.png","default_tree.png", "default_tree_top.png", "default_tree_top.png","default_tree.png"}
|
||||
local textures_branch_xmzp = {"default_tree.png", "default_tree.png","default_tree.png", "default_tree_top.png", "default_tree.png","default_tree_top.png"}
|
||||
local textures_branch_xpzm = {"default_tree.png", "default_tree.png","default_tree_top.png", "default_tree.png", "default_tree_top.png","default_tree.png"}
|
||||
|
||||
|
||||
minetest.register_node("growing_trees:trunk_sprout", {
|
||||
description = "Trunk-Sprout (growing_trees)",
|
||||
paramtype = "light",
|
||||
tiles = textures_trunk,
|
||||
is_ground_content = true,
|
||||
drawtype = "nodebox",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = nodebox_trunk_sprout,
|
||||
},
|
||||
groups = {
|
||||
tree = 1,
|
||||
snappy = 1,
|
||||
choppy = 2,
|
||||
oddly_breakable_by_hand = 1,
|
||||
flammable = 2
|
||||
},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
drop = "default:tree"
|
||||
})
|
||||
|
||||
minetest.register_node("growing_trees:trunk_top", {
|
||||
description = "Trunk-Top (growing_trees)",
|
||||
paramtype = "light",
|
||||
tiles = textures_trunk,
|
||||
is_ground_content = true,
|
||||
drawtype = "nodebox",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = nodebox_trunk_sprout,
|
||||
},
|
||||
groups = {
|
||||
tree = 1,
|
||||
snappy = 1,
|
||||
choppy = 2,
|
||||
oddly_breakable_by_hand = 1,
|
||||
flammable = 2
|
||||
},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
drop = "default:tree"
|
||||
})
|
||||
|
||||
minetest.register_node("growing_trees:leaves", {
|
||||
description = "Leaves (growing_trees)",
|
||||
drawtype = "allfaces_optional",
|
||||
visual_scale = 1.3,
|
||||
tiles = {"default_leaves.png"},
|
||||
paramtype = "light",
|
||||
groups = {snappy=3},
|
||||
drop = {
|
||||
max_items = 1,
|
||||
items = {
|
||||
{
|
||||
-- player will get sapling with 1/20 chance
|
||||
items = {'growing_trees:sapling'},
|
||||
rarity = 20,
|
||||
},
|
||||
{
|
||||
-- player will get leaves only if he get no saplings,
|
||||
-- this is because max_items is 1
|
||||
items = {'default:leaves'},
|
||||
}
|
||||
}
|
||||
},
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
})
|
||||
|
||||
minetest.register_node("growing_trees:branch_sprout", {
|
||||
description = "Leaves-Sprout (growing_trees)",
|
||||
drawtype = "allfaces_optional",
|
||||
visual_scale = 1.3,
|
||||
tiles = {"default_leaves.png"},
|
||||
paramtype = "light",
|
||||
groups = {snappy=3},
|
||||
drop = {
|
||||
max_items = 1,
|
||||
items = {
|
||||
{
|
||||
-- player will get sapling with 1/20 chance
|
||||
items = {'growing_trees:sapling'},
|
||||
rarity = 20,
|
||||
},
|
||||
{
|
||||
-- player will get leaves only if he get no saplings,
|
||||
-- this is because max_items is 1
|
||||
items = {'default:leaves'},
|
||||
}
|
||||
}
|
||||
},
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
})
|
||||
|
||||
minetest.register_node("growing_trees:trunk", {
|
||||
description = "Trunk (growing_trees)",
|
||||
paramtype = "light",
|
||||
tiles = textures_trunk,
|
||||
is_ground_content = true,
|
||||
drawtype = "nodebox",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.35,-0.5,-0.40, 0.35,0.5,0.40},
|
||||
{-0.40,-0.5,-0.35, 0.40,0.5,0.35},
|
||||
|
||||
{-0.25,-0.5,-0.45, 0.25,0.5,0.45},
|
||||
{-0.45,-0.5,-0.25, 0.45,0.5,0.25},
|
||||
|
||||
{-0.15,-0.5,-0.50, 0.15,0.5,0.50},
|
||||
{-0.50,-0.5,-0.15, 0.50,0.5,0.15},
|
||||
},
|
||||
},
|
||||
groups = {
|
||||
tree = 1,
|
||||
snappy = 1,
|
||||
choppy = 2,
|
||||
oddly_breakable_by_hand = 1,
|
||||
flammable = 2
|
||||
},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
drop = "default:tree"
|
||||
})
|
||||
|
||||
minetest.register_node("growing_trees:medium_trunk", {
|
||||
description = "Trunk (growing_trees)",
|
||||
paramtype = "light",
|
||||
tiles = textures_trunk,
|
||||
is_ground_content = true,
|
||||
drawtype = "nodebox",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.45,-0.5,-0.50, 0.45, 0.5,0.50},
|
||||
{-0.50,-0.5,-0.45, 0.50, 0.5,0.45},
|
||||
|
||||
{-0.35,-0.5,-0.55, 0.35, 0.5,0.55},
|
||||
{-0.55,-0.5,-0.35, 0.55, 0.5,0.35},
|
||||
|
||||
{-0.25,-0.5,-0.60, 0.25, 0.5,0.60},
|
||||
{-0.60,-0.5,-0.25, 0.60, 0.5,0.25},
|
||||
},
|
||||
},
|
||||
groups = {
|
||||
tree = 1,
|
||||
snappy = 1,
|
||||
choppy = 2,
|
||||
oddly_breakable_by_hand = 1,
|
||||
flammable = 2
|
||||
},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
drop = "default:tree 2"
|
||||
})
|
||||
|
||||
minetest.register_node("growing_trees:big_trunk", {
|
||||
description = "Trunk (growing_trees)",
|
||||
paramtype = "light",
|
||||
tiles = textures_trunk,
|
||||
is_ground_content = true,
|
||||
drawtype = "nodebox",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.55,-0.5,-0.60, 0.55, 0.5,0.60},
|
||||
{-0.60,-0.5,-0.55, 0.60, 0.5,0.55},
|
||||
|
||||
{-0.45,-0.5,-0.65, 0.45, 0.5,0.65},
|
||||
{-0.65,-0.5,-0.45, 0.65, 0.5,0.45},
|
||||
|
||||
{-0.35,-0.5,-0.70, 0.35, 0.5,0.70},
|
||||
{-0.70,-0.5,-0.35, 0.70, 0.5,0.35},
|
||||
},
|
||||
},
|
||||
groups = {
|
||||
tree = 1,
|
||||
snappy = 1,
|
||||
choppy = 2,
|
||||
oddly_breakable_by_hand = 1,
|
||||
flammable = 2
|
||||
},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
drop = "default:tree 3"
|
||||
})
|
||||
|
||||
minetest.register_node("growing_trees:branch", {
|
||||
description = "Branch (growing_trees)",
|
||||
drawtype = "nodebox",
|
||||
tiles = textures_branch,
|
||||
paramtype = "light",
|
||||
is_ground_content = true,
|
||||
walkable = true,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = nodebox_branch_ukn,
|
||||
},
|
||||
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=1,flammable=2,tree=1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
drop = "default:tree"
|
||||
})
|
||||
|
||||
minetest.register_node("growing_trees:branch_xmzm", {
|
||||
description = "Branch (growing_trees)",
|
||||
drawtype = "nodebox",
|
||||
tiles = textures_branch_xmzm,
|
||||
paramtype = "light",
|
||||
is_ground_content = true,
|
||||
walkable = true,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = nodebox_branch_xmzm,
|
||||
},
|
||||
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=1,flammable=2,tree=1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
drop = "default:tree"
|
||||
})
|
||||
|
||||
minetest.register_node("growing_trees:branch_xpzm", {
|
||||
description = "Branch (growing_trees)",
|
||||
drawtype = "nodebox",
|
||||
tiles = textures_branch_xpzm,
|
||||
paramtype = "light",
|
||||
is_ground_content = true,
|
||||
walkable = true,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = nodebox_branch_xpzm,
|
||||
},
|
||||
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=1,flammable=2,tree=1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
drop = "default:tree"
|
||||
})
|
||||
|
||||
minetest.register_node("growing_trees:branch_xmzp", {
|
||||
description = "Branch (growing_trees)",
|
||||
drawtype = "nodebox",
|
||||
tiles = textures_branch_xmzp,
|
||||
paramtype = "light",
|
||||
is_ground_content = true,
|
||||
walkable = true,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = nodebox_branch_xmzp,
|
||||
},
|
||||
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=1,flammable=2,tree=1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
drop = "default:tree"
|
||||
})
|
||||
|
||||
minetest.register_node("growing_trees:branch_xpzp", {
|
||||
description = "Branch (growing_trees)",
|
||||
drawtype = "nodebox",
|
||||
tiles = textures_branch_xpzp,
|
||||
paramtype = "light",
|
||||
is_ground_content = true,
|
||||
walkable = true,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = nodebox_branch_xpzp,
|
||||
},
|
||||
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=1,flammable=2,tree=1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
drop = "default:tree"
|
||||
})
|
||||
|
||||
minetest.register_node("growing_trees:branch_zz", {
|
||||
description = "Branch (growing_trees)",
|
||||
drawtype = "nodebox",
|
||||
tiles = textures_branch_zz,
|
||||
paramtype = "light",
|
||||
is_ground_content = true,
|
||||
walkable = true,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = nodebox_branch_zz,
|
||||
},
|
||||
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=1,flammable=2,tree=1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
drop = "default:tree"
|
||||
})
|
||||
|
||||
minetest.register_node("growing_trees:branch_xx", {
|
||||
description = "Branch (growing_trees)",
|
||||
drawtype = "nodebox",
|
||||
tiles = textures_branch_xx,
|
||||
paramtype = "light",
|
||||
is_ground_content = true,
|
||||
walkable = true,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = nodebox_branch_xx,
|
||||
},
|
||||
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=1,flammable=2,tree=1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
drop = "default:tree"
|
||||
})
|
||||
|
||||
--minetest.register_node("growing_trees:branch", {
|
||||
-- description = "Branch (growing_trees)",
|
||||
-- tile_images = {"default_tree_top.png", "default_tree_top.png", "default_tree.png"},
|
||||
-- is_ground_content = true,
|
||||
-- groups = {snappy=1,choppy=2,oddly_breakable_by_hand=1,flammable=2,tree=1},
|
||||
-- sounds = default.node_sound_wood_defaults(),
|
||||
-- drop = "default:tree"
|
||||
--})
|
@ -1,104 +0,0 @@
|
||||
-------------------------------------------------------------------------------
|
||||
-- Growing Trees Mod by Sapier
|
||||
--
|
||||
-- License GPLv3
|
||||
--
|
||||
--! @file spawning.lua
|
||||
--! @brief contains spawn algorithm on mapgen
|
||||
--! mod
|
||||
--! @copyright Sapier
|
||||
--! @author Sapier
|
||||
--! @date 2012-09-04
|
||||
--
|
||||
-- Contact sapier a t gmx net
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
local minimum_tree_distance = 50
|
||||
|
||||
function MIN(a,b)
|
||||
if a > b then
|
||||
return b
|
||||
else
|
||||
return a
|
||||
end
|
||||
end
|
||||
|
||||
function MAX(a,b)
|
||||
if a > b then
|
||||
return a
|
||||
else
|
||||
return b
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--add trees on generation
|
||||
minetest.register_on_generated(function(minp, maxp, seed)
|
||||
|
||||
local min_x = MIN(minp.x,maxp.x)
|
||||
local min_y = MIN(minp.y,maxp.x)
|
||||
local min_z = MIN(minp.z,maxp.z)
|
||||
|
||||
local max_x = MAX(minp.x,maxp.x)
|
||||
local max_y = MAX(minp.y,maxp.y)
|
||||
local max_z = MAX(minp.z,maxp.z)
|
||||
|
||||
|
||||
local xdivs = math.floor(((max_x - min_x) / minimum_tree_distance) +1)
|
||||
local zdivs = math.floor(((max_z - min_z) / minimum_tree_distance) +1)
|
||||
|
||||
--print(min_x .. " " .. max_x .. " # " .. min_z .. " " .. max_z)
|
||||
--print("Generating in " .. xdivs .. " | " .. zdivs .. " chunks")
|
||||
|
||||
for i = 0, xdivs do
|
||||
for j = 0, zdivs do
|
||||
|
||||
local x_center = min_x + 0.5 * minimum_tree_distance + minimum_tree_distance * i
|
||||
local z_center = min_z + 0.5 * minimum_tree_distance + minimum_tree_distance * i
|
||||
|
||||
--check if there is already a growing tree within area
|
||||
local trunkpos = minetest.env:find_node_near({ x=x_center,
|
||||
y=growing_trees_get_surface(x_center,z_center,min_y,max_y),
|
||||
z=z_center},
|
||||
minimum_tree_distance/2, {"growing_trees:trunk"})
|
||||
|
||||
--randomly try to place new growing tree in area
|
||||
if not trunkpos then
|
||||
for i= 0, 5 do
|
||||
local x_try = math.random(minimum_tree_distance/-2,minimum_tree_distance/2)
|
||||
local z_try = math.random(minimum_tree_distance/-2,minimum_tree_distance/2)
|
||||
|
||||
local pos = { x= x_center + x_try,
|
||||
z= z_center+z_try }
|
||||
|
||||
local surface = growing_trees_get_surface(pos.x,pos.z,min_y,max_y)
|
||||
|
||||
if surface then
|
||||
local spawnpos = {x=pos.x,y=surface+1,z=pos.z}
|
||||
--print("Growing_Trees: found surface " .. printpos(spawnpos) .. " try: " .. i)
|
||||
|
||||
local to_near = minetest.env:find_node_near(spawnpos,4,{"default:tree", "growing_trees:trunk"})
|
||||
local near_enough = minetest.env:find_node_near(spawnpos,8,"default:tree")
|
||||
|
||||
--print(dump(to_near) .. " | " .. dump(near_enough))
|
||||
|
||||
if not to_near and
|
||||
near_enough ~= nil then
|
||||
if growing_trees_place_sprout(spawnpos) then
|
||||
growing_trees_debug("info","Growing_Trees: Tree growing at " .. printpos(spawnpos))
|
||||
break
|
||||
end
|
||||
end
|
||||
else
|
||||
--print("Growing_Trees: didn't find surface for " .. printpos(pos))
|
||||
end
|
||||
end
|
||||
else
|
||||
--print("Growing_Trees: found growing tree at: " .. trunkpos)
|
||||
end
|
||||
|
||||
end --for i
|
||||
end --for j
|
||||
|
||||
end
|
||||
)
|
@ -1,162 +0,0 @@
|
||||
|
||||
--find a trunk node exactly one level below current position
|
||||
--with a distance of at most 1
|
||||
function growing_trees_get_trunk_below(pos)
|
||||
|
||||
local pos_below = {x=pos.x,y=pos.y-1,z=pos.z}
|
||||
|
||||
if growing_trees_pos_is_type(trunk_static_type,pos_below) then
|
||||
return pos_below
|
||||
end
|
||||
|
||||
for x = pos.x - 1, pos.x + 1 do
|
||||
for z = pos.z - 1, pos.z + 1 do
|
||||
local runpos = {x = x, y = pos.y-1, z = z}
|
||||
if growing_trees_pos_is_type(trunk_static_type,runpos) then
|
||||
return runpos
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
--find a trunk node exactly above pos with
|
||||
--distance at most one
|
||||
function growing_trees_get_trunk_above(pos)
|
||||
|
||||
local pos_above = {x=pos.x,y=pos.y+1,z=pos.z}
|
||||
|
||||
if growing_trees_pos_is_type(trunk_static_type,pos_above) then
|
||||
return pos_above
|
||||
end
|
||||
|
||||
for x = pos.x - 1, pos.x + 1 do
|
||||
for z = pos.z - 1, pos.z + 1 do
|
||||
local runpos = {x = x, y = pos.y+1, z = z}
|
||||
if growing_trees_pos_is_type(trunk_static_type,runpos) then
|
||||
return runpos
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
--calculate size of trunk pos is element of in blocks
|
||||
function growing_trees_get_tree_size(pos)
|
||||
|
||||
local node = minetest.env:get_node(pos)
|
||||
local root = pos
|
||||
|
||||
if not growing_trees_pos_is_type(trunk_static_type,pos) then
|
||||
return 0
|
||||
end
|
||||
|
||||
local size=0
|
||||
|
||||
local runpos = pos;
|
||||
|
||||
while runpos ~= nil and
|
||||
growing_trees_pos_is_type(trunk_static_type,runpos) do
|
||||
size = size+1;
|
||||
|
||||
runpos = growing_trees_get_trunk_above(runpos)
|
||||
end
|
||||
|
||||
runpos = growing_trees_get_trunk_below(pos)
|
||||
|
||||
if runpos ~= nil then
|
||||
root = runpos
|
||||
end
|
||||
|
||||
while runpos ~= nil and
|
||||
growing_trees_pos_is_type(trunk_static_type,runpos) do
|
||||
size = size+1;
|
||||
|
||||
runpos = growing_trees_get_trunk_below(runpos)
|
||||
|
||||
if (runpos ~= nil) then
|
||||
root = runpos
|
||||
end
|
||||
end
|
||||
|
||||
return size,root
|
||||
end
|
||||
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: growing_trees_get_random_next_to(pos)
|
||||
--
|
||||
--! @brief get a random position next to pos at same height level
|
||||
--
|
||||
--! @param pos start searching around pos
|
||||
--! @return pos to grow to
|
||||
-------------------------------------------------------------------------------
|
||||
function growing_trees_get_random_next_to(pos)
|
||||
|
||||
local dirs = {
|
||||
{x= 1, z= 0},
|
||||
{x= 0, z= 1},
|
||||
{x=-1, z= 0},
|
||||
{x= 0, z=-1}
|
||||
}
|
||||
|
||||
local dir = dirs[math.random(1,#dirs)]
|
||||
|
||||
return {x=pos.x+dir.x,y=pos.y,z=pos.z+dir.z}
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: growing_trees_make_trunk_big(root,height)
|
||||
--
|
||||
--! @brief replace trunk by big trunk
|
||||
--
|
||||
--! @param root position to start
|
||||
--! @param height heigth to replace
|
||||
-------------------------------------------------------------------------------
|
||||
function growing_trees_make_trunk_big(root,height)
|
||||
growing_trees_debug("error","Growing_Trees: replacing small trunk at: " .. printpos(root))
|
||||
local ymax = root.y+height
|
||||
|
||||
local runy = root.y
|
||||
local current_pos = root
|
||||
|
||||
while runy < (ymax - (height/2)) and
|
||||
current_pos ~= nil do
|
||||
minetest.env:remove_node(current_pos)
|
||||
minetest.env:add_node(current_pos,{type=node,name="growing_trees:big_trunk"})
|
||||
|
||||
local neighbour = growing_trees_next_to(current_pos, { "growing_trees:trunk" },false)
|
||||
|
||||
if neighbour ~= nil then
|
||||
minetest.env:remove_node(neighbour)
|
||||
minetest.env:add_node(neighbour,{type=node,name="growing_trees:big_trunk"})
|
||||
current_pos = neighbour
|
||||
end
|
||||
|
||||
current_pos = growing_trees_get_trunk_above(current_pos)
|
||||
|
||||
runy = runy + 1
|
||||
end
|
||||
|
||||
while runy < ymax and
|
||||
current_pos ~= nil do
|
||||
minetest.env:remove_node(current_pos)
|
||||
minetest.env:add_node(current_pos,{type=node,name="growing_trees:medium_trunk"})
|
||||
|
||||
local neighbour = growing_trees_next_to(current_pos, { "growing_trees:trunk" },false)
|
||||
|
||||
if neighbour ~= nil then
|
||||
minetest.env:remove_node(neighbour)
|
||||
minetest.env:add_node(neighbour,{type=node,name="growing_trees:medium_trunk"})
|
||||
current_pos = neighbour
|
||||
end
|
||||
|
||||
current_pos = growing_trees_get_trunk_above(current_pos)
|
||||
|
||||
runy = runy + 1
|
||||
end
|
||||
|
||||
end
|
@ -1,99 +0,0 @@
|
||||
-------------------------------------------------------------------------------
|
||||
-- Growing Trees Mod by Sapier
|
||||
--
|
||||
-- License GPLv3
|
||||
--
|
||||
--! @file type_declarations.lua
|
||||
--! @brief file containing node to type mappings
|
||||
--! @copyright Sapier
|
||||
--! @author Sapier
|
||||
--! @date 2012-09-04
|
||||
--
|
||||
-- Contact sapier a t gmx net
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
branch_type = {
|
||||
"growing_trees:branch",
|
||||
"growing_trees:branch_ukn",
|
||||
"growing_trees:branch_zz",
|
||||
"growing_trees:branch_xx",
|
||||
"growing_trees:branch_xpzp",
|
||||
"growing_trees:branch_xpzm",
|
||||
"growing_trees:branch_xmzp",
|
||||
"growing_trees:branch_xmzm",
|
||||
"growing_trees:branch_sprout",
|
||||
}
|
||||
|
||||
branch_static_type = {
|
||||
"growing_trees:branch",
|
||||
"growing_trees:branch_ukn",
|
||||
"growing_trees:branch_zz",
|
||||
"growing_trees:branch_xx",
|
||||
"growing_trees:branch_xpzp",
|
||||
"growing_trees:branch_xpzm",
|
||||
"growing_trees:branch_xmzp",
|
||||
"growing_trees:branch_xmzm",
|
||||
}
|
||||
|
||||
trunk_type = {
|
||||
"growing_trees:trunk_top",
|
||||
"growing_trees:trunk",
|
||||
"growing_trees:medium_trunk",
|
||||
"growing_trees:big_trunk",
|
||||
"growing_trees:trunk_sprout"
|
||||
}
|
||||
|
||||
trunk_static_type = {
|
||||
"growing_trees:trunk",
|
||||
"growing_trees:medium_trunk",
|
||||
"growing_trees:big_trunk",
|
||||
}
|
||||
|
||||
leaves_type = {
|
||||
"growing_trees:leaves"
|
||||
}
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: growing_trees_node_is_type(table_to_check,name)
|
||||
--
|
||||
-- @brief check if a table contains a specific element
|
||||
--
|
||||
-- @param table_to_check table or string to search in
|
||||
-- @param name name to search
|
||||
-- @return true/false
|
||||
-------------------------------------------------------------------------------
|
||||
function growing_trees_node_is_type(type_declaration,name)
|
||||
if type(type_declaration) == "table" then
|
||||
for i,v in ipairs(type_declaration) do
|
||||
if v == name then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: growing_trees_pos_is_type(table_to_check,name)
|
||||
--
|
||||
-- @brief check if a table contains a specific element
|
||||
--
|
||||
-- @param table_to_check table or string to search in
|
||||
-- @param name name to search
|
||||
-- @return true/false
|
||||
-------------------------------------------------------------------------------
|
||||
function growing_trees_pos_is_type(type_declaration,pos)
|
||||
local node = minetest.env:get_node(pos)
|
||||
|
||||
if node ~= nil then
|
||||
if type(type_declaration) == "table" then
|
||||
for i,v in ipairs(type_declaration) do
|
||||
|
||||
if v == node.name then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user