mirror of
https://github.com/Splizard/minetest-mod-snow.git
synced 2024-12-29 16:00:16 +01:00
fix snowfall and pines
This commit is contained in:
parent
e990039ea3
commit
7370b142ed
@ -80,11 +80,18 @@ local PERSISTENCE3 = 0.5 -- 0.5
|
|||||||
local SCALE3 = 250 -- 250
|
local SCALE3 = 250 -- 250
|
||||||
|
|
||||||
--Get snow at position.
|
--Get snow at position.
|
||||||
|
local rarity, perlin_scale
|
||||||
local function get_snow(pos)
|
local function get_snow(pos)
|
||||||
--Legacy support.
|
--Legacy support.
|
||||||
if weather_legacy == "snow" then
|
if weather_legacy ~= "snow" then
|
||||||
local perlin1 = minetest.get_perlin(112,3, 0.5, 150)
|
return false
|
||||||
if perlin1:get2d({x=pos.x, y=pos.z}) <= 0.53 then
|
end
|
||||||
|
if not rarity then
|
||||||
|
rarity = snow.mapgen.smooth_rarity_min
|
||||||
|
perlin_scale = snow.mapgen.perlin_scale
|
||||||
|
end
|
||||||
|
local perlin1 = minetest.get_perlin(112,3, 0.5, perlin_scale)
|
||||||
|
if perlin1:get2d({x=pos.x, y=pos.z}) < rarity then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -95,8 +102,6 @@ local function get_snow(pos)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local addvectors = vector and vector.add
|
local addvectors = vector and vector.add
|
||||||
@ -159,7 +164,9 @@ local function snow_fall(pos, player, animate)
|
|||||||
|
|
||||||
pos = {x=pos.x, y=ground_y, z=pos.z}
|
pos = {x=pos.x, y=ground_y, z=pos.z}
|
||||||
|
|
||||||
if get_snow(pos) then
|
if not get_snow(pos) then
|
||||||
|
return
|
||||||
|
end
|
||||||
if animate then
|
if animate then
|
||||||
local spos = {x=pos.x, y=ground_y+10, z=pos.z}
|
local spos = {x=pos.x, y=ground_y+10, z=pos.z}
|
||||||
minetest.add_particlespawner(get_snow_particledef({
|
minetest.add_particlespawner(get_snow_particledef({
|
||||||
@ -172,7 +179,6 @@ local function snow_fall(pos, player, animate)
|
|||||||
end
|
end
|
||||||
snow.place(pos, true)
|
snow.place(pos, true)
|
||||||
--minetest.place_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="default:snow"}) -- LazyJ
|
--minetest.place_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="default:snow"}) -- LazyJ
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Snow
|
-- Snow
|
||||||
|
@ -13,6 +13,32 @@ saplings grow into trees. --]]
|
|||||||
-- Part 1: To disable the mapgen, add the *starting* comment under this line.
|
-- 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.
|
--Identify the mapgen.
|
||||||
minetest.register_on_mapgen_init(function(MapgenParams)
|
minetest.register_on_mapgen_init(function(MapgenParams)
|
||||||
local mgname = MapgenParams.mgname
|
local mgname = MapgenParams.mgname
|
||||||
@ -31,8 +57,6 @@ end)
|
|||||||
-- To complete the commenting-out add the *closing* comment under this line.
|
-- To complete the commenting-out add the *closing* comment under this line.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local pine_tree = {
|
local pine_tree = {
|
||||||
axiom="TABff",
|
axiom="TABff",
|
||||||
rules_a="[&T+f+ff+ff+ff+f]GA",
|
rules_a="[&T+f+ff+ff+ff+f]GA",
|
||||||
@ -66,7 +90,6 @@ local xmas_tree = {
|
|||||||
--Makes pine tree
|
--Makes pine tree
|
||||||
function snow.make_pine(pos,snow,xmas)
|
function snow.make_pine(pos,snow,xmas)
|
||||||
local minetest = minetest
|
local minetest = minetest
|
||||||
local perlin1 = minetest.get_perlin(112,3, 0.5, 150)
|
|
||||||
local try_node = function(pos, node)
|
local try_node = function(pos, node)
|
||||||
local n = minetest.get_node(pos).name
|
local n = minetest.get_node(pos).name
|
||||||
if n == "air"
|
if n == "air"
|
||||||
@ -95,7 +118,7 @@ function snow.make_pine(pos,snow,xmas)
|
|||||||
if xmas then
|
if xmas then
|
||||||
try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="snow:star_lit"}) -- Added lit star. ~ LazyJ
|
try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="snow:star_lit"}) -- Added lit star. ~ LazyJ
|
||||||
elseif snow
|
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"})
|
try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="default:snow"})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -109,7 +132,7 @@ function snow.voxelmanip_pine(pos,a,data)
|
|||||||
local c_pinetree = minetest.get_content_id("default:pinetree")
|
local c_pinetree = minetest.get_content_id("default:pinetree")
|
||||||
local c_air = minetest.get_content_id("air")
|
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
|
for z = -1,1 do
|
||||||
local z = pos.z + z
|
local z = pos.z + z
|
||||||
for x = -1,1 do
|
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
|
data[a:index(x,pos.y+i,z)] = c_pine_needles
|
||||||
if x ~= 0
|
if x ~= 0
|
||||||
and z ~= 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)
|
local abovenode = a:index(x,pos.y+i+1,z)
|
||||||
data[abovenode] = c_snow
|
data[abovenode] = c_snow
|
||||||
end
|
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-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
|
||||||
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
|
data[a:index(x+1,y+1,z)] = c_snow
|
||||||
end
|
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
|
data[a:index(x-1,y+1,z)] = c_snow
|
||||||
end
|
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
|
data[a:index(x,y+1,z+1)] = c_snow
|
||||||
end
|
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
|
data[a:index(x,y+1,z-1)] = c_snow
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -153,7 +176,7 @@ function snow.voxelmanip_pine(pos,a,data)
|
|||||||
end
|
end
|
||||||
data[a:index(pos.x,pos.y+5,pos.z)] = c_pine_needles
|
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
|
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
|
data[a:index(pos.x,pos.y+7,pos.z)] = c_snow
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -11,9 +11,12 @@ local np_default = {
|
|||||||
|
|
||||||
-- 2D noise for coldness
|
-- 2D noise for coldness
|
||||||
|
|
||||||
|
local mg = snow.mapgen
|
||||||
|
local scale = mg.perlin_scale
|
||||||
local np_cold = {
|
local np_cold = {
|
||||||
offset = 0,
|
offset = 0,
|
||||||
scale = 1,
|
scale = 1,
|
||||||
|
spread = {x=scale, y=scale, z=scale},
|
||||||
seed = 112,
|
seed = 112,
|
||||||
octaves = 3,
|
octaves = 3,
|
||||||
persist = 0.5
|
persist = 0.5
|
||||||
@ -121,26 +124,11 @@ local function define_contents()
|
|||||||
replacements = snow.known_plants or {}
|
replacements = snow.known_plants or {}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 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
|
|
||||||
np_cold.spread = {x=perlin_scale, y=perlin_scale, z=perlin_scale}
|
|
||||||
local smooth_rarity_max, smooth_rarity_min, smooth_rarity_dif
|
|
||||||
local smooth = snow.smooth_biomes
|
local smooth = snow.smooth_biomes
|
||||||
if smooth then
|
local smooth_rarity_max = mg.smooth_rarity_max
|
||||||
local smooth_trans_size = 4 --snow.smooth_trans_size
|
local smooth_rarity_min = mg.smooth_rarity_min
|
||||||
smooth_rarity_max = upper_rarity(nosmooth_rarity+smooth_trans_size*2/perlin_scale)
|
local smooth_rarity_dif = mg.smooth_rarity_dif
|
||||||
smooth_rarity_min = upper_rarity(nosmooth_rarity-smooth_trans_size/perlin_scale)
|
local nosmooth_rarity = mg.nosmooth_rarity
|
||||||
smooth_rarity_dif = smooth_rarity_max-smooth_rarity_min
|
|
||||||
end
|
|
||||||
nosmooth_rarity = upper_rarity(nosmooth_rarity)
|
|
||||||
|
|
||||||
minetest.register_on_generated(function(minp, maxp, seed)
|
minetest.register_on_generated(function(minp, maxp, seed)
|
||||||
local t1 = os.clock()
|
local t1 = os.clock()
|
||||||
|
Loading…
Reference in New Issue
Block a user