Fix heightmap issues with trees.

This commit is contained in:
Duane 2016-06-23 22:35:48 -05:00
parent 3e3e0c17d6
commit 9325a474b5
2 changed files with 25 additions and 4 deletions

View file

@ -7,12 +7,25 @@ fun_caves.cave_noise_2 = {offset = 0, scale = 1, seed = -8402, spread = {x = 40,
local cave_noise_3 = {offset = 15, scale = 10, seed = 3721, spread = {x = 40, y = 40, z = 40}, octaves = 3, persist = 1, lacunarity = 2} local cave_noise_3 = {offset = 15, scale = 10, seed = 3721, spread = {x = 40, y = 40, z = 40}, octaves = 3, persist = 1, lacunarity = 2}
local ground_nodes = {}
ground_nodes[minetest.get_content_id('default:stone')] = true
ground_nodes[minetest.get_content_id('default:desert_stone')] = true
ground_nodes[minetest.get_content_id('default:sandstone')] = true
ground_nodes[minetest.get_content_id('default:dirt')] = true
ground_nodes[minetest.get_content_id('default:sand')] = true
ground_nodes[minetest.get_content_id('default:dirt_with_grass')] = true
ground_nodes[minetest.get_content_id('default:dirt_with_snow')] = true
ground_nodes[minetest.get_content_id('default:dirt_with_dry_grass')] = true
fun_caves.cavegen = function(minp, maxp, data, area, node, heightmap, underzone) fun_caves.cavegen = function(minp, maxp, data, area, node, heightmap, underzone)
local csize = vector.add(vector.subtract(maxp, minp), 1) local csize = vector.add(vector.subtract(maxp, minp), 1)
local map_max = {x = csize.x, y = csize.y + 2, z = csize.z} local map_max = {x = csize.x, y = csize.y + 2, z = csize.z}
local map_min = {x = minp.x, y = minp.y - 1, z = minp.z} local map_min = {x = minp.x, y = minp.y - 1, z = minp.z}
local return_heightmap = false
if not heightmap then if not heightmap then
return_heightmap = true
heightmap = {} heightmap = {}
end end
@ -39,7 +52,7 @@ fun_caves.cavegen = function(minp, maxp, data, area, node, heightmap, underzone)
height = - max_depth height = - max_depth
local ivm2 = area:index(x, maxp.y + 8, z) local ivm2 = area:index(x, maxp.y + 8, z)
for y = maxp.y + 8, minp.y - 8, -1 do for y = maxp.y + 8, minp.y - 8, -1 do
if data[ivm2] ~= node['air'] and data[ivm2] ~= node['ignore'] then if ground_nodes[data[ivm2]] then
height = (y < maxp.y + 8) and y or max_depth height = (y < maxp.y + 8) and y or max_depth
break break
end end
@ -103,5 +116,9 @@ fun_caves.cavegen = function(minp, maxp, data, area, node, heightmap, underzone)
end end
end end
return write, heightmap if return_heightmap then
return write, heightmap
else
return write, nil
end
end end

View file

@ -388,8 +388,12 @@ local function generate(p_minp, p_maxp, seed)
fun_caves.fortress(minp, maxp, data, area, node) fun_caves.fortress(minp, maxp, data, area, node)
write = true write = true
else else
local write1, write2, write3 local write1, write2, write3, h2
write1, heightmap = fun_caves.cavegen(minp, maxp, data, area, node, heightmap, underzone) write1, h2 = fun_caves.cavegen(minp, maxp, data, area, node, heightmap, underzone)
if h2 then
heightmap = h2
end
write2, write_p2 = fun_caves.decogen(minp, maxp, data, p2data, area, node, heightmap, biome_ids, underzone) write2, write_p2 = fun_caves.decogen(minp, maxp, data, p2data, area, node, heightmap, biome_ids, underzone)
write3 = fun_caves.treegen(minp, maxp, data, p2data, area, node) write3 = fun_caves.treegen(minp, maxp, data, p2data, area, node)
write = write1 or write2 or write3 write = write1 or write2 or write3