fix snowfall and pines

This commit is contained in:
HybridDog
2015-06-21 12:49:27 +02:00
parent e990039ea3
commit 7370b142ed
3 changed files with 74 additions and 57 deletions

View File

@ -13,6 +13,32 @@ saplings grow into trees. --]]
-- Part 1: To disable the mapgen, add the *starting* comment under this line.
snow.mapgen = snow.mapgen or {}
local mg = snow.mapgen
-- perlin noise "hills" are not peaks but looking like sinus curve
local function upper_rarity(rarity)
return math.sign(rarity)*math.sin(math.abs(rarity)*math.pi/2)
end
local rarity = 18 --snow.mapgen_rarity
local size = 210 --snow.mapgen_size
local nosmooth_rarity = 1-rarity/50
local perlin_scale = size*100/rarity
mg.perlin_scale = perlin_scale
local smooth_rarity_max, smooth_rarity_min, smooth_rarity_dif
local smooth = snow.smooth_biomes
if smooth then
local smooth_trans_size = 4 --snow.smooth_trans_size
mg.smooth_rarity_max = upper_rarity(nosmooth_rarity+smooth_trans_size*2/perlin_scale)
mg.smooth_rarity_min = upper_rarity(nosmooth_rarity-smooth_trans_size/perlin_scale)
mg.smooth_rarity_dif = mg.smooth_rarity_max-mg.smooth_rarity_min
end
nosmooth_rarity = upper_rarity(nosmooth_rarity)
mg.nosmooth_rarity = nosmooth_rarity
--Identify the mapgen.
minetest.register_on_mapgen_init(function(MapgenParams)
local mgname = MapgenParams.mgname
@ -31,8 +57,6 @@ end)
-- To complete the commenting-out add the *closing* comment under this line.
local pine_tree = {
axiom="TABff",
rules_a="[&T+f+ff+ff+ff+f]GA",
@ -66,7 +90,6 @@ local xmas_tree = {
--Makes pine tree
function snow.make_pine(pos,snow,xmas)
local minetest = minetest
local perlin1 = minetest.get_perlin(112,3, 0.5, 150)
local try_node = function(pos, node)
local n = minetest.get_node(pos).name
if n == "air"
@ -95,7 +118,7 @@ function snow.make_pine(pos,snow,xmas)
if xmas then
try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="snow:star_lit"}) -- Added lit star. ~ LazyJ
elseif snow
and perlin1:get2d({x=pos.x,y=pos.z}) > 0.53 then
and minetest.get_perlin(112,3, 0.5, perlin_scale):get2d({x=pos.x,y=pos.z}) > nosmooth_rarity then
try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="default:snow"})
end
end
@ -109,7 +132,7 @@ function snow.voxelmanip_pine(pos,a,data)
local c_pinetree = minetest.get_content_id("default:pinetree")
local c_air = minetest.get_content_id("air")
local perlin1 = minetest.get_perlin(112,3, 0.5, 150)
local perlin1 = minetest.get_perlin(112,3, 0.5, perlin_scale)
for z = -1,1 do
local z = pos.z + z
for x = -1,1 do
@ -120,7 +143,7 @@ function snow.voxelmanip_pine(pos,a,data)
data[a:index(x,pos.y+i,z)] = c_pine_needles
if x ~= 0
and z ~= 0
and perlin1:get2d({x=x,y=z}) > 0.53 then
and perlin1:get2d({x=x,y=z}) > nosmooth_rarity then
local abovenode = a:index(x,pos.y+i+1,z)
data[abovenode] = c_snow
end
@ -135,16 +158,16 @@ function snow.voxelmanip_pine(pos,a,data)
data[a:index(x-1,y,z)] = c_pine_needles
data[a:index(x,y,z+1)] = c_pine_needles
data[a:index(x,y,z-1)] = c_pine_needles
if perlin1:get2d({x=x+1,y=z}) > 0.53 then
if perlin1:get2d({x=x+1,y=z}) > nosmooth_rarity then
data[a:index(x+1,y+1,z)] = c_snow
end
if perlin1:get2d({x=x+1,y=z}) > 0.53 then
if perlin1:get2d({x=x+1,y=z}) > nosmooth_rarity then
data[a:index(x-1,y+1,z)] = c_snow
end
if perlin1:get2d({x=x,y=z+1}) > 0.53 then
if perlin1:get2d({x=x,y=z+1}) > nosmooth_rarity then
data[a:index(x,y+1,z+1)] = c_snow
end
if perlin1:get2d({x=x,y=z-1}) > 0.53 then
if perlin1:get2d({x=x,y=z-1}) > nosmooth_rarity then
data[a:index(x,y+1,z-1)] = c_snow
end
end
@ -153,7 +176,7 @@ function snow.voxelmanip_pine(pos,a,data)
end
data[a:index(pos.x,pos.y+5,pos.z)] = c_pine_needles
data[a:index(pos.x,pos.y+6,pos.z)] = c_pine_needles
if perlin1:get2d({x=pos.x,y=pos.z}) > 0.53 then
if perlin1:get2d({x=pos.x,y=pos.z}) > nosmooth_rarity then
data[a:index(pos.x,pos.y+7,pos.z)] = c_snow
end
end