1
0
Fork 0

Rework vine gen code and gen vines in swampland

This commit is contained in:
Wuzzy 2017-09-08 21:44:15 +02:00
parent fc2d9b3d32
commit 0259353b6f
1 changed files with 60 additions and 17 deletions

View File

@ -1104,18 +1104,52 @@ end)
-- Buffer for LuaVoxelManip -- Buffer for LuaVoxelManip
local lvm_buffer = {} local lvm_buffer = {}
-- Generate tree decorations in the bounding box. This adds:
-- Generate cocoas and vines at jungle trees within the bounding box -- * Cocoa at jungle trees
local function generate_jungle_tree_decorations(minp, maxp) -- * Jungle tree vines
-- * Oak vines in swamplands
local function generate_tree_decorations(minp, maxp, biomemap)
if maxp.y < 0 then if maxp.y < 0 then
return return
end end
local pos, treepos, dir local oaktree, oakleaves, jungletree, jungleleaves = {}, {}, {}, {}
local jungletree = minetest.find_nodes_in_area(minp, maxp, "mcl_core:jungletree") local swampland = minetest.get_biome_id("swampland")
local jungleleaves = minetest.find_nodes_in_area(minp, maxp, "mcl_core:jungleleaves") local swampland_shore = minetest.get_biome_id("swampland_shore")
local jungle = minetest.get_biome_id("jungle")
local jungle_shore = minetest.get_biome_id("jungle_shore")
-- Pass 1: Generate cocoas if biomemap then
-- Biome map available: Check if the required biome (jungle or swampland)
-- is in this mapchunk. We are only interested in trees in the correct biome.
-- The nodes are added if the correct biome is *anywhere* in the mapchunk.
-- TODO: Strictly generate vines in the correct biomes only.
local swamp_biome_found, jungle_biome_found = false, false
for b=1, #biomemap do
local id = biomemap[b]
if not swamp_biome_found and (id == swampland or id == swampland_shore) then
oaktree = minetest.find_nodes_in_area(minp, maxp, {"mcl_core:tree"})
oakleaves = minetest.find_nodes_in_area(minp, maxp, {"mcl_core:leaves"})
swamp_biome_found = true
elseif not jungle_biome_found and (id == jungle or id == jungle_shore) then
jungletree = minetest.find_nodes_in_area(minp, maxp, {"mcl_core:jungletree"})
jungleleaves = minetest.find_nodes_in_area(minp, maxp, {"mcl_core:jungleleaves"})
jungle_biome_found = true
end
if swamp_biome_found and jungle_biome_found then
break
end
end
else
-- If there is no biome map, we just count all jungle things we can find.
-- Oak vines will not be generated.
jungletree = minetest.find_nodes_in_area(minp, maxp, {"mcl_core:jungletree"})
jungleleaves = minetest.find_nodes_in_area(minp, maxp, {"mcl_core:jungleleaves"})
end
local pos, treepos, dir
-- Pass 1: Generate cocoas at jungle trees
for n = 1, #jungletree do for n = 1, #jungletree do
pos = jungletree[n] pos = jungletree[n]
@ -1149,19 +1183,26 @@ local function generate_jungle_tree_decorations(minp, maxp)
end end
end end
-- Pass 2: Generate vines at jungle wood and jungle leaves -- Pass 2: Generate vines at jungle wood, jungle leaves in jungle and oak wood, oak leaves in swampland
perlin_vines = perlin_vines or minetest.get_perlin(555, 4, 0.6, 500) perlin_vines = perlin_vines or minetest.get_perlin(555, 4, 0.6, 500)
perlin_vines_fine = perlin_vines_fine or minetest.get_perlin(43000, 3, 0.6, 1) perlin_vines_fine = perlin_vines_fine or minetest.get_perlin(43000, 3, 0.6, 1)
perlin_vines_length = perlin_vines_length or minetest.get_perlin(435, 4, 0.6, 75) perlin_vines_length = perlin_vines_length or minetest.get_perlin(435, 4, 0.6, 75)
perlin_vines_upwards = perlin_vines_upwards or minetest.get_perlin(436, 3, 0.6, 10) perlin_vines_upwards = perlin_vines_upwards or minetest.get_perlin(436, 3, 0.6, 10)
perlin_vines_density = perlin_vines_density or minetest.get_perlin(436, 3, 0.6, 500) perlin_vines_density = perlin_vines_density or minetest.get_perlin(436, 3, 0.6, 500)
local junglething local treething
for i=1, 2 do for i=1, 4 do
if i==1 then junglething = jungletree if i==1 then
else junglething = jungleleaves end treething = jungletree
elseif i == 2 then
treething = jungleleaves
elseif i == 3 then
treething = oaktree
elseif i == 4 then
treething = oakleaves
end
for n = 1, #junglething do for n = 1, #treething do
pos = junglething[n] pos = treething[n]
treepos = table.copy(pos) treepos = table.copy(pos)
@ -1177,7 +1218,7 @@ local function generate_jungle_tree_decorations(minp, maxp)
local nn = minetest.get_node(pos).name local nn = minetest.get_node(pos).name
if perlin_vines:get2d(pos) > -0.1 and perlin_vines_fine:get3d(pos) > math.max(0.3333, perlin_vines_density:get2d(pos)) and nn == "air" then if perlin_vines:get2d(pos) > -1.0 and perlin_vines_fine:get3d(pos) > math.max(0.33333, perlin_vines_density:get2d(pos)) and nn == "air" then
local newnode = { local newnode = {
name = "mcl_core:vine", name = "mcl_core:vine",
@ -1198,7 +1239,7 @@ local function generate_jungle_tree_decorations(minp, maxp)
for l=0, length-1 do for l=0, length-1 do
local tnn = minetest.get_node(treepos).name local tnn = minetest.get_node(treepos).name
local nn = minetest.get_node(pos).name local nn = minetest.get_node(pos).name
if (nn == "air" or nn == "mcl_core:jungleleaves") and mcl_core.supports_vines(tnn) then if (nn == "air" or nn == "mcl_core:jungleleaves" or nn == "mcl_core:leaves") and mcl_core.supports_vines(tnn) then
minetest.set_node(pos, newnode) minetest.set_node(pos, newnode)
else else
break break
@ -1555,9 +1596,11 @@ minetest.register_on_generated(function(minp, maxp)
vm:write_to_map() vm:write_to_map()
end end
local biomemap = minetest.get_mapgen_object("biomemap")
-- Generate special decorations -- Generate special decorations
generate_underground_mushrooms(minp, maxp) generate_underground_mushrooms(minp, maxp)
generate_jungle_tree_decorations(minp, maxp) generate_tree_decorations(minp, maxp, biomemap)
generate_nether_decorations(minp, maxp) generate_nether_decorations(minp, maxp)
end) end)