mirror of
https://github.com/Splizard/minetest-mod-snow.git
synced 2024-11-13 21:30:17 +01:00
fix snowfall and pines
This commit is contained in:
parent
e990039ea3
commit
7370b142ed
|
@ -80,23 +80,28 @@ local PERSISTENCE3 = 0.5 -- 0.5
|
|||
local SCALE3 = 250 -- 250
|
||||
|
||||
--Get snow at position.
|
||||
local rarity, perlin_scale
|
||||
local function get_snow(pos)
|
||||
--Legacy support.
|
||||
if weather_legacy == "snow" then
|
||||
local perlin1 = minetest.get_perlin(112,3, 0.5, 150)
|
||||
if perlin1:get2d({x=pos.x, y=pos.z}) <= 0.53 then
|
||||
return false
|
||||
end
|
||||
|
||||
-- disable falling snow in desert
|
||||
local desert_perlin = minetest.get_perlin(SEEDDIFF3, OCTAVES3, PERSISTENCE3, SCALE3)
|
||||
local noise3 = desert_perlin:get2d({x=pos.x+150,y=pos.z+50}) -- Offsets must match minetest mapgen desert perlin.
|
||||
if noise3 > 0.35 then -- Smooth transition 0.35 to 0.45.
|
||||
return false
|
||||
end
|
||||
return true
|
||||
if weather_legacy ~= "snow" then
|
||||
return false
|
||||
end
|
||||
return false
|
||||
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
|
||||
end
|
||||
|
||||
-- disable falling snow in desert
|
||||
local desert_perlin = minetest.get_perlin(SEEDDIFF3, OCTAVES3, PERSISTENCE3, SCALE3)
|
||||
local noise3 = desert_perlin:get2d({x=pos.x+150,y=pos.z+50}) -- Offsets must match minetest mapgen desert perlin.
|
||||
if noise3 > 0.35 then -- Smooth transition 0.35 to 0.45.
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local addvectors = vector and vector.add
|
||||
|
@ -159,20 +164,21 @@ local function snow_fall(pos, player, animate)
|
|||
|
||||
pos = {x=pos.x, y=ground_y, z=pos.z}
|
||||
|
||||
if get_snow(pos) then
|
||||
if animate then
|
||||
local spos = {x=pos.x, y=ground_y+10, z=pos.z}
|
||||
minetest.add_particlespawner(get_snow_particledef({
|
||||
minpos = addvectors(spos, {x=-9, y=3, z=-9}),
|
||||
maxpos = addvectors(spos, {x= 9, y=5, z= 9}),
|
||||
vel = {x=0, y=-1, z=-1},
|
||||
acc = {x=0, y=0, z=0},
|
||||
playername = player:get_player_name()
|
||||
}))
|
||||
end
|
||||
snow.place(pos, true)
|
||||
--minetest.place_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="default:snow"}) -- LazyJ
|
||||
if not get_snow(pos) then
|
||||
return
|
||||
end
|
||||
if animate then
|
||||
local spos = {x=pos.x, y=ground_y+10, z=pos.z}
|
||||
minetest.add_particlespawner(get_snow_particledef({
|
||||
minpos = addvectors(spos, {x=-9, y=3, z=-9}),
|
||||
maxpos = addvectors(spos, {x= 9, y=5, z= 9}),
|
||||
vel = {x=0, y=-1, z=-1},
|
||||
acc = {x=0, y=0, z=0},
|
||||
playername = player:get_player_name()
|
||||
}))
|
||||
end
|
||||
snow.place(pos, true)
|
||||
--minetest.place_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="default:snow"}) -- LazyJ
|
||||
end
|
||||
|
||||
-- Snow
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -11,9 +11,12 @@ local np_default = {
|
|||
|
||||
-- 2D noise for coldness
|
||||
|
||||
local mg = snow.mapgen
|
||||
local scale = mg.perlin_scale
|
||||
local np_cold = {
|
||||
offset = 0,
|
||||
scale = 1,
|
||||
spread = {x=scale, y=scale, z=scale},
|
||||
seed = 112,
|
||||
octaves = 3,
|
||||
persist = 0.5
|
||||
|
@ -121,26 +124,11 @@ local function define_contents()
|
|||
replacements = snow.known_plants or {}
|
||||
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
|
||||
if smooth then
|
||||
local smooth_trans_size = 4 --snow.smooth_trans_size
|
||||
smooth_rarity_max = upper_rarity(nosmooth_rarity+smooth_trans_size*2/perlin_scale)
|
||||
smooth_rarity_min = upper_rarity(nosmooth_rarity-smooth_trans_size/perlin_scale)
|
||||
smooth_rarity_dif = smooth_rarity_max-smooth_rarity_min
|
||||
end
|
||||
nosmooth_rarity = upper_rarity(nosmooth_rarity)
|
||||
local smooth_rarity_max = mg.smooth_rarity_max
|
||||
local smooth_rarity_min = mg.smooth_rarity_min
|
||||
local smooth_rarity_dif = mg.smooth_rarity_dif
|
||||
local nosmooth_rarity = mg.nosmooth_rarity
|
||||
|
||||
minetest.register_on_generated(function(minp, maxp, seed)
|
||||
local t1 = os.clock()
|
||||
|
|
Loading…
Reference in New Issue
Block a user