forked from Mineclonia/Mineclonia
Generate podzol when growing large spruce trees
When 4 spruce saplings are put into a 2×2 square, they may grow into a large spruce tree. With this patch, dirt group group nodes nearby that have air above and nodes under the stem are replaced by podzol nodes. Note that this commit uses a different placement method than MineClone2 commit a83a2e9aba122d0fb4f1c120252a0d4eb07a1f10 to create one connected podzol patch instead of randomly scattered nodes. It also places podzol nodes in bulk at once for better performance.
This commit is contained in:
parent
1ce88e7528
commit
6059b79785
|
@ -585,6 +585,69 @@ mcl_core.generate_spruce_tree = function(pos)
|
||||||
minetest.place_schematic({ x = pos.x - 3, y = pos.y - 1, z = pos.z - 3 }, path, "0", nil, false)
|
minetest.place_schematic({ x = pos.x - 3, y = pos.y - 1, z = pos.z - 3 }, path, "0", nil, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local vector_distance_xz = function(a, b)
|
||||||
|
return vector.distance(
|
||||||
|
{ x=a.x, y=0, z=a.z },
|
||||||
|
{ x=b.x, y=0, z=b.z }
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
local podzol_spread_randomizer = PseudoRandom(minetest.get_mapgen_setting("seed"))
|
||||||
|
|
||||||
|
local generate_spruce_podzol = function(pos)
|
||||||
|
local podzol_positions = {}
|
||||||
|
local podzol_positions_xz = {}
|
||||||
|
local add_podzol = function(position)
|
||||||
|
podzol_positions[#podzol_positions+1] = position
|
||||||
|
local x,z = position.x, position.z
|
||||||
|
if nil == podzol_positions_xz[x] then
|
||||||
|
podzol_positions_xz[x] = {}
|
||||||
|
end
|
||||||
|
podzol_positions_xz[x][z] = true
|
||||||
|
end
|
||||||
|
-- add podzol under tree
|
||||||
|
add_podzol( { x=pos.x+0, y=pos.y, z=pos.z+0 } )
|
||||||
|
add_podzol( { x=pos.x+0, y=pos.y, z=pos.z+1 } )
|
||||||
|
add_podzol( { x=pos.x+1, y=pos.y, z=pos.z+0 } )
|
||||||
|
add_podzol( { x=pos.x+1, y=pos.y, z=pos.z+1 } )
|
||||||
|
local corner_1 = { x=pos.x-5, y=pos.y-3, z=pos.z-5 }
|
||||||
|
local corner_2 = { x=pos.x+5, y=pos.y+3, z=pos.z+5 }
|
||||||
|
local dirt_positions = minetest.find_nodes_in_area_under_air(
|
||||||
|
corner_1,
|
||||||
|
corner_2,
|
||||||
|
{ "group:dirt" }
|
||||||
|
)
|
||||||
|
-- sort dirt positions according to distance from origin
|
||||||
|
table.sort(
|
||||||
|
dirt_positions,
|
||||||
|
function(a, b)
|
||||||
|
return vector_distance_xz(pos, a) < vector_distance_xz(pos, b)
|
||||||
|
end
|
||||||
|
)
|
||||||
|
-- spread podzol
|
||||||
|
for j=1, #dirt_positions do
|
||||||
|
local dirt_position = dirt_positions[j]
|
||||||
|
local distance = math.ceil(vector_distance_xz(pos, dirt_position) + 0.5)
|
||||||
|
local k = podzol_spread_randomizer:next(0, distance)
|
||||||
|
local x, z = dirt_position.x, dirt_position.z
|
||||||
|
if (
|
||||||
|
k < (10 - distance) and
|
||||||
|
not (podzol_positions_xz[x] and podzol_positions_xz[x][z]) and (
|
||||||
|
podzol_positions_xz[x] and podzol_positions_xz[x][z-1] or
|
||||||
|
podzol_positions_xz[x] and podzol_positions_xz[x][z+1] or
|
||||||
|
podzol_positions_xz[x-1] and podzol_positions_xz[x-1][z] or
|
||||||
|
podzol_positions_xz[x+1] and podzol_positions_xz[x+1][z]
|
||||||
|
)
|
||||||
|
) then
|
||||||
|
add_podzol(dirt_position)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
minetest.bulk_set_node(
|
||||||
|
podzol_positions,
|
||||||
|
{ name = "mcl_core:podzol" }
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
mcl_core.generate_huge_spruce_tree = function(pos)
|
mcl_core.generate_huge_spruce_tree = function(pos)
|
||||||
local r1 = math.random(1, 2)
|
local r1 = math.random(1, 2)
|
||||||
local r2 = math.random(1, 4)
|
local r2 = math.random(1, 4)
|
||||||
|
@ -601,6 +664,14 @@ mcl_core.generate_huge_spruce_tree = function(pos)
|
||||||
path = minetest.get_modpath("mcl_core") .. "/schematics/mcl_core_spruce_huge_up_"..r2..".mts"
|
path = minetest.get_modpath("mcl_core") .. "/schematics/mcl_core_spruce_huge_up_"..r2..".mts"
|
||||||
end
|
end
|
||||||
minetest.place_schematic(vector.add(pos, offset), path, "0", nil, false)
|
minetest.place_schematic(vector.add(pos, offset), path, "0", nil, false)
|
||||||
|
generate_spruce_podzol(
|
||||||
|
-- position under +x/+z sapling
|
||||||
|
{
|
||||||
|
x = pos.x + offset.x + 4,
|
||||||
|
y = pos.y - 1,
|
||||||
|
z = pos.z + offset.z + 4
|
||||||
|
}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- END of spruce tree functions --
|
-- END of spruce tree functions --
|
||||||
|
|
Loading…
Reference in New Issue