forked from mtcontrib/minetest-mod-snow
Change to L-systems for treegen.
This commit is contained in:
parent
80190d334e
commit
f57ce08962
87
mapgen.lua
87
mapgen.lua
|
@ -1,15 +1,38 @@
|
|||
local pine_tree = {
|
||||
axiom="TABff",
|
||||
rules_a="[&T+f+ff+ff+ff+f]GA",
|
||||
rules_b="[&T+f+Gf+Gf+Gf]GB",
|
||||
trunk="default:tree",
|
||||
leaves="snow:needles",
|
||||
angle=90,
|
||||
iterations=1,
|
||||
random_level=0,
|
||||
trunk_type="single",
|
||||
thin_branches=true,
|
||||
}
|
||||
local xmas_tree = {
|
||||
axiom="TABff",
|
||||
rules_a="[&T+f+ff+ff+ff+f]GA",
|
||||
rules_b="[&T+f+Gf+Gf+Gf]GB",
|
||||
trunk="default:tree",
|
||||
leaves="snow:needles_decorated",
|
||||
angle=90,
|
||||
iterations=1,
|
||||
random_level=0,
|
||||
trunk_type="single",
|
||||
thin_branches=true,
|
||||
}
|
||||
|
||||
--Makes pine tree
|
||||
function snow.make_pine(pos,snow,xmas)
|
||||
local env = minetest.env
|
||||
local perlin1 = env:get_perlin(112,3, 0.5, 150)
|
||||
local try_node = function(pos, node)
|
||||
local n = env:get_node(pos).name
|
||||
if n == "air" or n == "snow:needles" or n == "default:leaves" or n == "snow:sapling_pine" or n == "snow:snow" or "snow:needles_decorated" then
|
||||
if n == "air" or n == "ignore" then
|
||||
env:add_node(pos,node)
|
||||
end
|
||||
end
|
||||
local leaves = "snow:needles"
|
||||
if xmas then leaves = "snow:needles_decorated" end
|
||||
--Clear ground.
|
||||
for x=-1,1 do
|
||||
for z=-1,1 do
|
||||
|
@ -21,48 +44,24 @@ function snow.make_pine(pos,snow,xmas)
|
|||
end
|
||||
end
|
||||
end
|
||||
--Make tree.
|
||||
for i=0, 4 do
|
||||
local env = minetest.env
|
||||
if i==1 or i==2 then
|
||||
for x=-1,1 do
|
||||
for z=-1,1 do
|
||||
local x = pos.x + x
|
||||
local z = pos.z + z
|
||||
try_node({x=x,y=pos.y+i,z=z},{name=leaves})
|
||||
if snow and x ~= 0 and z ~= 0 and perlin1:get2d({x=x,y=z}) > 0.53 then
|
||||
try_node({x=x,y=pos.y+i+1,z=z},{name="snow:snow"})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if i==3 or i==4 then
|
||||
local x = pos.x
|
||||
local y = pos.y+i
|
||||
local z = pos.z
|
||||
try_node({x=x+1,y=y,z=z},{name=leaves})
|
||||
try_node({x=x-1,y=y,z=z},{name=leaves})
|
||||
try_node({x=x,y=y,z=z+1},{name=leaves})
|
||||
try_node({x=x,y=y,z=z-1},{name=leaves})
|
||||
if snow then
|
||||
if perlin1:get2d({x=x+1,y=z}) > 0.53 then
|
||||
try_node({x=x+1,y=y+1,z=z},{name="snow:snow"})
|
||||
end
|
||||
if perlin1:get2d({x=x+1,y=z}) > 0.53 then
|
||||
try_node({x=x-1,y=y+1,z=z},{name="snow:snow"})
|
||||
end
|
||||
if perlin1:get2d({x=x,y=z+1}) > 0.53 then
|
||||
try_node({x=x,y=y+1,z=z+1},{name="snow:snow"})
|
||||
end
|
||||
if perlin1:get2d({x=x,y=z-1}) > 0.53 then
|
||||
try_node({x=x,y=y+1,z=z-1},{name="snow:snow"})
|
||||
end
|
||||
end
|
||||
end
|
||||
try_node({x=pos.x,y=pos.y+i,z=pos.z},{name="default:tree"})
|
||||
if xmas then
|
||||
env:remove_node(pos)
|
||||
minetest.env:spawn_tree(pos, xmas_tree)
|
||||
else
|
||||
minetest.env:spawn_tree(pos, pine_tree)
|
||||
end
|
||||
if snow then
|
||||
local x,z = pos.x,pos.z
|
||||
try_node({x=x+1,y=pos.y+3,z=z+1},{name="snow:snow"})
|
||||
try_node({x=x-1,y=pos.y+3,z=z-1},{name="snow:snow"})
|
||||
try_node({x=x-1,y=pos.y+3,z=z+1},{name="snow:snow"})
|
||||
try_node({x=x+1,y=pos.y+3,z=z-1},{name="snow:snow"})
|
||||
|
||||
try_node({x=x+1,y=pos.y+5,z=z},{name="snow:snow"})
|
||||
try_node({x=x-1,y=pos.y+5,z=z},{name="snow:snow"})
|
||||
try_node({x=x,y=pos.y+5,z=z+1},{name="snow:snow"})
|
||||
try_node({x=x,y=pos.y+5,z=z-1},{name="snow:snow"})
|
||||
end
|
||||
try_node({x=pos.x,y=pos.y+5,z=pos.z},{name=leaves})
|
||||
try_node({x=pos.x,y=pos.y+6,z=pos.z},{name=leaves})
|
||||
if xmas then
|
||||
try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="snow:star"})
|
||||
elseif snow and perlin1:get2d({x=pos.x,y=pos.z}) > 0.53 then
|
||||
|
|
Loading…
Reference in New Issue
Block a user