1
0
Fork 0

Draw non-overlapping trees on map

This commit is contained in:
Nils Dagsson Moskopp 2022-05-18 21:29:17 +02:00
parent 0882a48751
commit c5f87c5129
Signed by untrusted user who does not match committer: erle
GPG Key ID: A3BC671C35191080
1 changed files with 76 additions and 0 deletions

View File

@ -84,6 +84,8 @@ maps.create_map = function(pos, player_name)
{ 150, 105, 55 }, -- more liquid { 150, 105, 55 }, -- more liquid
{ 165, 120, 70 }, -- more liquid { 165, 120, 70 }, -- more liquid
{ 150, 105, 55 }, -- more liquid { 150, 105, 55 }, -- more liquid
{ 60, 35, 16 }, -- tree outline
{ 150, 105, 55 }, -- tree fill
} }
for x = 1,size,1 do for x = 1,size,1 do
for z = 1,size,1 do for z = 1,size,1 do
@ -132,6 +134,80 @@ maps.create_map = function(pos, player_name)
end end
end end
local positions = minetest.find_nodes_in_area_under_air(
minp,
maxp,
{
"group:leaves",
"default:snow", -- snow-covered leaves
}
)
for _, p in ipairs(positions) do
local z = p.z - minp.z + 1
local x = p.x - minp.x + 1
local node = minetest.get_node({
x=p.x,
y=p.y - 4,
z=p.z,
})
local draw_tree = (
minetest.get_item_group(
node.name,
"tree"
) > 0 ) and (
z < size - 6 and
x > 3 and
x < size - 3
)
if draw_tree then
local tree = {}
if nil ~= node.name:find("pine") then
tree = {
" # ",
"#####",
"#...#",
" #.# ",
" #.# ",
" # ",
}
else
tree = {
" # ",
" # ",
" ### ",
"#...#",
"#...#",
"#...#",
" ### ",
}
end
local overlap = false
for t_z = 1,#tree do
for t_x = 1,#tree[t_z] do
local color = pixels[z + t_z][x + t_x - 3][1]
-- do not draw trees close together
if 7 == color then
overlap = true
break
end
end
end
if overlap then
tree = {}
end
for t_z = 1,#tree do
for t_x = 1,#tree[t_z] do
local byte = tree[t_z]:byte(t_x)
if 35 == byte then -- #
pixels[z + t_z][x + t_x - 3] = { 7 }
elseif 46 == byte then -- .
pixels[z + t_z][x + t_x - 3] = { 8 }
end
end
end
end
end
local filepath = textures_dir .. filename local filepath = textures_dir .. filename
tga_encoder.image(pixels):save( tga_encoder.image(pixels):save(
filepath, filepath,