should disable falling snow in deserts

This commit is contained in:
HybridDog 2015-05-01 19:37:29 +02:00
parent 46cf4e907a
commit c8c2fbd013

View File

@ -40,24 +40,26 @@ near torches and lava.
--============================================================= --=============================================================
if snow.enable_snowfall then if not snow.enable_snowfall then
return
end
local weather_legacy local weather_legacy
local read_weather_legacy = function () local read_weather_legacy = function ()
local file = io.open(minetest.get_worldpath().."/weather_v6", "r") local file = io.open(minetest.get_worldpath().."/weather_v6", "r")
if not file then return end if not file then return end
local readweather = file:read() local readweather = file:read()
file:close() file:close()
return readweather return readweather
end end
--Weather for legacy versions of minetest. --Weather for legacy versions of minetest.
local save_weather_legacy = function () local save_weather_legacy = function ()
local file = io.open(minetest.get_worldpath().."/weather_v6", "w+") local file = io.open(minetest.get_worldpath().."/weather_v6", "w+")
file:write(weather_legacy) file:write(weather_legacy)
file:close() file:close()
end end
weather_legacy = read_weather_legacy() or "" weather_legacy = read_weather_legacy() or ""
@ -75,25 +77,36 @@ if snow.enable_snowfall then
end end
end) end)
--Get snow at position. -- copied from meru mod
local get_snow = function(pos) local SEEDDIFF3 = 9130 -- 9130 -- Values should match minetest mapgen desert perlin.
local OCTAVES3 = 3 -- 3
local PERSISTENCE3 = 0.5 -- 0.5
local SCALE3 = 250 -- 250
--Get snow at position.
local get_snow = function(pos)
--Legacy support. --Legacy support.
if weather_legacy == "snow" then if weather_legacy == "snow" then
local perlin1 = minetest.env:get_perlin(112,3, 0.5, 150) local perlin1 = minetest.get_perlin(112,3, 0.5, 150)
if perlin1:get2d( {x=pos.x, y=pos.z} ) > 0.53 then 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=x+150,y=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 return true
else end
return false return false
end end
else
return false
end
end
local addvectors = vector and vector.add local addvectors = vector and vector.add
--Returns a random position between minp and maxp. --Returns a random position between minp and maxp.
local randpos = function (minp, maxp) local randpos = function (minp, maxp)
local x,y,z local x,y,z
if minp.x > maxp.x then if minp.x > maxp.x then
x = math.random(maxp.x,minp.x) else x = math.random(minp.x,maxp.x) end x = math.random(maxp.x,minp.x) else x = math.random(minp.x,maxp.x) end
@ -101,18 +114,18 @@ if snow.enable_snowfall then
if minp.z > maxp.z then if minp.z > maxp.z then
z = math.random(maxp.z,minp.z) else z = math.random(minp.z,maxp.z) end z = math.random(maxp.z,minp.z) else z = math.random(minp.z,maxp.z) end
return {x=x,y=y,z=z} return {x=x,y=y,z=z}
end end
local default_snow_particle = { local default_snow_particle = {
amount = 3, amount = 3,
time = 0.5, time = 0.5,
exptime = 5, exptime = 5,
size = 50, size = 50,
collisiondetection = false, collisiondetection = false,
vertical = false, vertical = false,
} }
local function get_snow_particledef(data) local function get_snow_particledef(data)
for n,i in pairs(default_snow_particle) do for n,i in pairs(default_snow_particle) do
data[n] = data[n] or i data[n] = data[n] or i
end end
@ -122,18 +135,18 @@ if snow.enable_snowfall then
end end
data.texture = "weather_snow.png^[transform"..math.random(0,7) data.texture = "weather_snow.png^[transform"..math.random(0,7)
return data return data
end end
local snow_fall=function (pos, player, animate) local function snow_fall(pos, player, animate)
local ground_y = nil local ground_y = nil
for y=pos.y+10,pos.y+20,1 do for y=pos.y+10,pos.y+20,1 do
local n = minetest.env:get_node({x=pos.x,y=y,z=pos.z}).name local n = minetest.get_node({x=pos.x,y=y,z=pos.z}).name
if n ~= "air" and n ~= "ignore" then if n ~= "air" and n ~= "ignore" then
return return
end end
end end
for y=pos.y+10,pos.y-15,-1 do for y=pos.y+10,pos.y-15,-1 do
local n = minetest.env:get_node({x=pos.x,y=y,z=pos.z}).name local n = minetest.get_node({x=pos.x,y=y,z=pos.z}).name
if n ~= "air" and n ~= "ignore" then if n ~= "air" and n ~= "ignore" then
ground_y = y ground_y = y
break break
@ -161,10 +174,10 @@ if snow.enable_snowfall then
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 end
-- Snow -- Snow
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
for _, player in pairs(minetest.get_connected_players()) do for _, player in pairs(minetest.get_connected_players()) do
local ppos = player:getpos() local ppos = player:getpos()
@ -172,7 +185,7 @@ if snow.enable_snowfall then
local smaxp = addvectors(ppos, {x= 20, y=0, z= 20}) local smaxp = addvectors(ppos, {x= 20, y=0, z= 20})
-- Make sure player is not in a cave/house... -- Make sure player is not in a cave/house...
if get_snow(ppos) and minetest.env:get_node_light(ppos, 0.5) == 15 then if get_snow(ppos) and minetest.get_node_light(ppos, 0.5) == 15 then
local minp = addvectors(ppos, {x=-9, y=3, z=-9}) local minp = addvectors(ppos, {x=-9, y=3, z=-9})
local maxp = addvectors(ppos, {x= 9, y=5, z= 9}) local maxp = addvectors(ppos, {x= 9, y=5, z= 9})
@ -213,15 +226,6 @@ if snow.enable_snowfall then
snow_fall(randpos(sminp, smaxp), player, true) snow_fall(randpos(sminp, smaxp), player, true)
end end
end end
else
if math.random(1,5) == 4 then
snow_fall(randpos(sminp, smaxp), player, true)
end end
end end
end end)
end)
end