mirror of
https://github.com/minetest/minetest_game.git
synced 2024-12-23 14:42:27 +01:00
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:
parent
0914e595c7
commit
585b2bc22e
@ -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")
|
local c_apple = minetest.get_content_id("default:apple")
|
||||||
|
|
||||||
-- Trunk
|
-- Trunk
|
||||||
for y_dist = 0, height - 1 do
|
data[a:index(x, y, z)] = tree_cid -- Force-place lowest trunk node to replace sapling
|
||||||
local vi = a:index(x, y + y_dist, z)
|
for yy = y + 1, y + height - 1 do
|
||||||
|
local vi = a:index(x, yy, z)
|
||||||
local node_id = data[vi]
|
local node_id = data[vi]
|
||||||
if y_dist == 0 or node_id == c_air or node_id == c_ignore
|
if node_id == c_air or node_id == c_ignore or node_id == leaves_cid then
|
||||||
or node_id == leaves_cid then
|
|
||||||
data[vi] = tree_cid
|
data[vi] = tree_cid
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -209,13 +209,15 @@ end
|
|||||||
-- Pinetree from mg mapgen mod, design by sfan5, pointy top added by paramat
|
-- 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)
|
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
|
data[vi] = c_pine_needles
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function add_snow(data, vi, c_air, c_ignore, c_snow)
|
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
|
data[vi] = c_snow
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -240,16 +242,14 @@ function default.grow_pine_tree(pos)
|
|||||||
local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
|
local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
|
||||||
local data = vm:get_data()
|
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
|
local snow = false
|
||||||
for yy = y - 1, y + 1 do
|
for yy = y - 1, y + 1 do
|
||||||
for zz = z - 1, z + 1 do
|
for zz = z - 1, z + 1 do
|
||||||
local vi = a:index(x - 1, yy, zz)
|
local vi = a:index(x - 1, yy, zz)
|
||||||
for xx = x - 1, x + 1 do
|
for xx = x - 1, x + 1 do
|
||||||
local nodid = data[vi]
|
local nodid = data[vi]
|
||||||
if nodid == c_snow
|
if nodid == c_snow or nodid == c_snowblock or nodid == c_dirtsnow then
|
||||||
or nodid == c_snowblock
|
|
||||||
or nodid == c_dirtsnow then
|
|
||||||
snow = true
|
snow = true
|
||||||
end
|
end
|
||||||
vi = vi + 1
|
vi = vi + 1
|
||||||
@ -266,7 +266,7 @@ function default.grow_pine_tree(pos)
|
|||||||
for xx = x - dev, x + dev do
|
for xx = x - dev, x + dev do
|
||||||
if random() < 0.95 - dev * 0.05 then
|
if random() < 0.95 - dev * 0.05 then
|
||||||
add_pine_needles(data, vi, c_air, c_ignore, c_snow,
|
add_pine_needles(data, vi, c_air, c_ignore, c_snow,
|
||||||
c_pine_needles)
|
c_pine_needles)
|
||||||
if snow then
|
if snow then
|
||||||
add_snow(data, via, c_air, c_ignore, c_snow)
|
add_snow(data, via, c_air, c_ignore, c_snow)
|
||||||
end
|
end
|
||||||
@ -280,9 +280,9 @@ function default.grow_pine_tree(pos)
|
|||||||
|
|
||||||
-- Centre top nodes
|
-- Centre top nodes
|
||||||
add_pine_needles(data, a:index(x, maxy + 1, z), c_air, c_ignore, c_snow,
|
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,
|
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
|
if snow then
|
||||||
add_snow(data, a:index(x, maxy + 3, z), c_air, c_ignore, c_snow)
|
add_snow(data, a:index(x, maxy + 3, z), c_air, c_ignore, c_snow)
|
||||||
end
|
end
|
||||||
@ -301,7 +301,7 @@ function default.grow_pine_tree(pos)
|
|||||||
local via = a:index(xi, yy + 1, zz)
|
local via = a:index(xi, yy + 1, zz)
|
||||||
for xx = xi, xi + 1 do
|
for xx = xi, xi + 1 do
|
||||||
add_pine_needles(data, vi, c_air, c_ignore, c_snow,
|
add_pine_needles(data, vi, c_air, c_ignore, c_snow,
|
||||||
c_pine_needles)
|
c_pine_needles)
|
||||||
if snow then
|
if snow then
|
||||||
add_snow(data, via, c_air, c_ignore, c_snow)
|
add_snow(data, via, c_air, c_ignore, c_snow)
|
||||||
end
|
end
|
||||||
@ -319,7 +319,7 @@ function default.grow_pine_tree(pos)
|
|||||||
for xx = x - dev, x + dev do
|
for xx = x - dev, x + dev do
|
||||||
if random() < 0.95 - dev * 0.05 then
|
if random() < 0.95 - dev * 0.05 then
|
||||||
add_pine_needles(data, vi, c_air, c_ignore, c_snow,
|
add_pine_needles(data, vi, c_air, c_ignore, c_snow,
|
||||||
c_pine_needles)
|
c_pine_needles)
|
||||||
if snow then
|
if snow then
|
||||||
add_snow(data, via, c_air, c_ignore, c_snow)
|
add_snow(data, via, c_air, c_ignore, c_snow)
|
||||||
end
|
end
|
||||||
@ -332,9 +332,13 @@ function default.grow_pine_tree(pos)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Trunk
|
-- 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)
|
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
|
end
|
||||||
|
|
||||||
vm:set_data(data)
|
vm:set_data(data)
|
||||||
|
Loading…
Reference in New Issue
Block a user