forked from VoxeLibre/VoxeLibre
Address review comments on mcl_util.trace_nodes
This commit is contained in:
parent
981cddddd4
commit
189a2c62ad
|
@ -1134,21 +1134,21 @@ end
|
||||||
|
|
||||||
-- Traces along a line of nodes vertically to find the next possition that isn't an allowed node
|
-- Traces along a line of nodes vertically to find the next possition that isn't an allowed node
|
||||||
---@param pos The position to start tracing from
|
---@param pos The position to start tracing from
|
||||||
---@param dir The direction to trace in (1 is up, -1 is down)
|
---@param dir The direction to trace in. 1 is up, -1 is down, all other values are not allowed.
|
||||||
---@param allowed_nodes A table of node names to trace along
|
---@param allowed_nodes A set of node names to trace along.
|
||||||
---@param limit The maximum number of steps to make. Defaults to 16 if nil or missing
|
---@param limit The maximum number of steps to make. Defaults to 16 if nil or missing
|
||||||
---@return Three return values:
|
---@return Three return values:
|
||||||
--- the position of the next node that isn't allowed or nil if no such node was found,
|
--- the position of the next node that isn't allowed or nil if no such node was found,
|
||||||
--- the distance from the start where that node was found,
|
--- the distance from the start where that node was found,
|
||||||
--- the node table if a node was found
|
--- the node table if a node was found
|
||||||
function mcl_util.trace_nodes(pos, dir, allowed_nodes, limit)
|
function mcl_util.trace_nodes(pos, dir, allowed_nodes, limit)
|
||||||
if not dir or dir == 0 or #allowed_nodes == 0 then return nil, 0, nil end
|
if ( dir ~= -1 ) and ( dir ~= 1 ) then return nil, 0, nil end
|
||||||
limit = limit or 16
|
limit = limit or 16
|
||||||
|
|
||||||
for i = 1,limit do
|
for i = 1,limit do
|
||||||
pos = vector.offset(pos, 0, dir, 0)
|
pos = vector.offset(pos, 0, dir, 0)
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
if table.indexof(allowed_nodes, node.name) == -1 then return pos, i, node end
|
if not allowed_nodes[node.name] then return pos, i, node end
|
||||||
end
|
end
|
||||||
|
|
||||||
return nil, limit, nil
|
return nil, limit, nil
|
||||||
|
|
|
@ -44,6 +44,10 @@ mcl_bamboo.bamboo_index = {
|
||||||
"mcl_bamboo:bamboo_2",
|
"mcl_bamboo:bamboo_2",
|
||||||
"mcl_bamboo:bamboo_3",
|
"mcl_bamboo:bamboo_3",
|
||||||
}
|
}
|
||||||
|
mcl_bamboo.bamboo_set = {}
|
||||||
|
for _,key in pairs(mcl_bamboo.bamboo_index) do
|
||||||
|
mcl_bamboo.bamboo_set[key] = true
|
||||||
|
end
|
||||||
|
|
||||||
function mcl_bamboo.is_bamboo(node_name)
|
function mcl_bamboo.is_bamboo(node_name)
|
||||||
local index = table.indexof(mcl_bamboo.bamboo_index, node_name)
|
local index = table.indexof(mcl_bamboo.bamboo_index, node_name)
|
||||||
|
@ -108,7 +112,7 @@ function mcl_bamboo.grow_bamboo(pos, bonemeal_applied)
|
||||||
|
|
||||||
-- Determine the location of soil
|
-- Determine the location of soil
|
||||||
local soil_pos
|
local soil_pos
|
||||||
soil_pos,a,b = mcl_util.trace_nodes(pos, -1, mcl_bamboo.bamboo_index, BAMBOO_MAX_HEIGHT - 1)
|
soil_pos,a,b = mcl_util.trace_nodes(pos, -1, mcl_bamboo.bamboo_set, BAMBOO_MAX_HEIGHT - 1)
|
||||||
|
|
||||||
-- No soil found, return false so that bonemeal isn't used
|
-- No soil found, return false so that bonemeal isn't used
|
||||||
if not soil_pos then return false end
|
if not soil_pos then return false end
|
||||||
|
@ -127,7 +131,7 @@ function mcl_bamboo.grow_bamboo(pos, bonemeal_applied)
|
||||||
log("Grow bamboo; height: " .. height)
|
log("Grow bamboo; height: " .. height)
|
||||||
|
|
||||||
-- Locate the bamboo tip
|
-- Locate the bamboo tip
|
||||||
local bamboo_tip,actual_height,bamboo_tip_node = mcl_util.trace_nodes(first_shoot, 1, mcl_bamboo.bamboo_index, height - 1)
|
local bamboo_tip,actual_height,bamboo_tip_node = mcl_util.trace_nodes(first_shoot, 1, mcl_bamboo.bamboo_set, height - 1)
|
||||||
log("Current height: "..tostring(actual_height))
|
log("Current height: "..tostring(actual_height))
|
||||||
|
|
||||||
-- Short circuit growth if the bamboo is already finished growing
|
-- Short circuit growth if the bamboo is already finished growing
|
||||||
|
|
|
@ -23,7 +23,8 @@ function grow_vines(pos, moreontop, vine, dir)
|
||||||
if dir == nil then dir = 1 end
|
if dir == nil then dir = 1 end
|
||||||
if not moreontop or moreontop < 1 then return false end
|
if not moreontop or moreontop < 1 then return false end
|
||||||
|
|
||||||
local allowed_nodes = {vine}
|
local allowed_nodes = {}
|
||||||
|
allowed_nodes[vine] = true
|
||||||
|
|
||||||
-- Find the root, tip and calculate height
|
-- Find the root, tip and calculate height
|
||||||
local root,_,root_node = mcl_util.trace_nodes(pos, -dir, allowed_nodes, MAXIMUM_VINE_HEIGHT)
|
local root,_,root_node = mcl_util.trace_nodes(pos, -dir, allowed_nodes, MAXIMUM_VINE_HEIGHT)
|
||||||
|
|
Loading…
Reference in New Issue