Default/trees: Add checks for air/ignore/needles to pinetree trunk

Speed optimise: Trunk placing, add_pine_needles, add_snow
This commit is contained in:
paramat 2015-07-04 21:00:41 +01:00
parent 0914e595c7
commit 585b2bc22e
1 changed files with 21 additions and 17 deletions

View File

@ -74,11 +74,11 @@ local function add_trunk_and_leaves(data, a, pos, tree_cid, leaves_cid,
local c_apple = minetest.get_content_id("default:apple")
-- Trunk
for y_dist = 0, height - 1 do
local vi = a:index(x, y + y_dist, z)
data[a:index(x, y, z)] = tree_cid -- Force-place lowest trunk node to replace sapling
for yy = y + 1, y + height - 1 do
local vi = a:index(x, yy, z)
local node_id = data[vi]
if y_dist == 0 or node_id == c_air or node_id == c_ignore
or node_id == leaves_cid then
if node_id == c_air or node_id == c_ignore or node_id == leaves_cid then
data[vi] = tree_cid
end
end
@ -209,13 +209,15 @@ end
-- Pinetree from mg mapgen mod, design by sfan5, pointy top added by paramat
local function add_pine_needles(data, vi, c_air, c_ignore, c_snow, c_pine_needles)
if data[vi] == c_air or data[vi] == c_ignore or data[vi] == c_snow then
local node_id = data[vi]
if node_id == c_air or node_id == c_ignore or node_id == c_snow then
data[vi] = c_pine_needles
end
end
local function add_snow(data, vi, c_air, c_ignore, c_snow)
if data[vi] == c_air or data[vi] == c_ignore then
local node_id = data[vi]
if node_id == c_air or node_id == c_ignore then
data[vi] = c_snow
end
end
@ -240,16 +242,14 @@ function default.grow_pine_tree(pos)
local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
local data = vm:get_data()
-- Scan for snow nodes near sapling
-- Scan for snow nodes near sapling to enable snow on branches
local snow = false
for yy = y - 1, y + 1 do
for zz = z - 1, z + 1 do
local vi = a:index(x - 1, yy, zz)
for xx = x - 1, x + 1 do
local nodid = data[vi]
if nodid == c_snow
or nodid == c_snowblock
or nodid == c_dirtsnow then
if nodid == c_snow or nodid == c_snowblock or nodid == c_dirtsnow then
snow = true
end
vi = vi + 1
@ -266,7 +266,7 @@ function default.grow_pine_tree(pos)
for xx = x - dev, x + dev do
if random() < 0.95 - dev * 0.05 then
add_pine_needles(data, vi, c_air, c_ignore, c_snow,
c_pine_needles)
c_pine_needles)
if snow then
add_snow(data, via, c_air, c_ignore, c_snow)
end
@ -280,9 +280,9 @@ function default.grow_pine_tree(pos)
-- Centre top nodes
add_pine_needles(data, a:index(x, maxy + 1, z), c_air, c_ignore, c_snow,
c_pine_needles)
c_pine_needles)
add_pine_needles(data, a:index(x, maxy + 2, z), c_air, c_ignore, c_snow,
c_pine_needles) -- Paramat added a pointy top node
c_pine_needles) -- Paramat added a pointy top node
if snow then
add_snow(data, a:index(x, maxy + 3, z), c_air, c_ignore, c_snow)
end
@ -301,7 +301,7 @@ function default.grow_pine_tree(pos)
local via = a:index(xi, yy + 1, zz)
for xx = xi, xi + 1 do
add_pine_needles(data, vi, c_air, c_ignore, c_snow,
c_pine_needles)
c_pine_needles)
if snow then
add_snow(data, via, c_air, c_ignore, c_snow)
end
@ -319,7 +319,7 @@ function default.grow_pine_tree(pos)
for xx = x - dev, x + dev do
if random() < 0.95 - dev * 0.05 then
add_pine_needles(data, vi, c_air, c_ignore, c_snow,
c_pine_needles)
c_pine_needles)
if snow then
add_snow(data, via, c_air, c_ignore, c_snow)
end
@ -332,9 +332,13 @@ function default.grow_pine_tree(pos)
end
-- Trunk
for yy = y, maxy do
data[a:index(x, y, z)] = c_pinetree -- Force-place lowest trunk node to replace sapling
for yy = y + 1, maxy do
local vi = a:index(x, yy, z)
data[vi] = c_pinetree
local node_id = data[vi]
if node_id == c_air or node_id == c_ignore or node_id == c_pine_needles then
data[vi] = c_pinetree
end
end
vm:set_data(data)