Disable under a y limit set by parameter, usually set to a world's water level
parent
78b6e10d73
commit
fcb0537b32
235
init.lua
235
init.lua
|
@ -1,5 +1,7 @@
|
||||||
-- Parameters
|
-- Parameters
|
||||||
|
|
||||||
|
local YLIMIT = 1 -- Set to world's water level or level of lowest open area,
|
||||||
|
-- calculations are disabled below this y.
|
||||||
local PRECSPR = 6 -- Time scale for precipitation variation in minutes
|
local PRECSPR = 6 -- Time scale for precipitation variation in minutes
|
||||||
local PRECOFF = -0.4 -- Precipitation offset, higher = rains more often
|
local PRECOFF = -0.4 -- Precipitation offset, higher = rains more often
|
||||||
local GSCYCLE = 0.5 -- Globalstep cycle (seconds)
|
local GSCYCLE = 0.5 -- Globalstep cycle (seconds)
|
||||||
|
@ -75,137 +77,142 @@ minetest.register_globalstep(function(dtime)
|
||||||
|
|
||||||
for _, player in ipairs(minetest.get_connected_players()) do
|
for _, player in ipairs(minetest.get_connected_players()) do
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
|
|
||||||
local ppos = player:getpos()
|
local ppos = player:getpos()
|
||||||
local pposx = math.floor(ppos.x)
|
|
||||||
local pposy = math.floor(ppos.y) + 2 -- Precipitation when swimming
|
local pposy = math.floor(ppos.y) + 2 -- Precipitation when swimming
|
||||||
local pposz = math.floor(ppos.z)
|
if pposy >= YLIMIT then
|
||||||
local ppos = {x = pposx, y = pposy, z = pposz}
|
local pposx = math.floor(ppos.x)
|
||||||
|
local pposz = math.floor(ppos.z)
|
||||||
|
local ppos = {x = pposx, y = pposy, z = pposz}
|
||||||
|
|
||||||
local nobj_temp = nobj_temp or minetest.get_perlin(np_temp)
|
local nobj_temp = nobj_temp or minetest.get_perlin(np_temp)
|
||||||
local nobj_humid = nobj_humid or minetest.get_perlin(np_humid)
|
local nobj_humid = nobj_humid or minetest.get_perlin(np_humid)
|
||||||
local nobj_prec = nobj_prec or minetest.get_perlin(np_prec)
|
local nobj_prec = nobj_prec or minetest.get_perlin(np_prec)
|
||||||
|
|
||||||
local nval_temp = nobj_temp:get2d({x = pposx, y = pposz})
|
local nval_temp = nobj_temp:get2d({x = pposx, y = pposz})
|
||||||
local nval_humid = nobj_humid:get2d({x = pposx, y = pposz})
|
local nval_humid = nobj_humid:get2d({x = pposx, y = pposz})
|
||||||
local nval_prec = nobj_prec:get2d({x = os.clock() / 60, y = 0})
|
local nval_prec = nobj_prec:get2d({x = os.clock() / 60, y = 0})
|
||||||
|
|
||||||
-- Biome system: Frozen biomes below heat 35,
|
-- Biome system: Frozen biomes below heat 35,
|
||||||
-- deserts below line 14 * t - 95 * h = -1496
|
-- deserts below line 14 * t - 95 * h = -1496
|
||||||
-- h = (14 * t + 1496) / 95
|
-- h = (14 * t + 1496) / 95
|
||||||
-- h = 14/95 * t + 1496/95
|
-- h = 14/95 * t + 1496/95
|
||||||
-- where 14/95 is gradient and 1496/95 is y intersection
|
-- where 14/95 is gradient and 1496/95 is y intersection
|
||||||
-- h - 14/95 t = 1496/95 y intersection
|
-- h - 14/95 t = 1496/95 y intersection
|
||||||
-- so area above line is
|
-- so area above line is
|
||||||
-- h - 14/95 t > 1496/95
|
-- h - 14/95 t > 1496/95
|
||||||
local freeze = nval_temp < 35
|
local freeze = nval_temp < 35
|
||||||
local precip = nval_prec < (nval_humid - 50) / 50 + PRECOFF and
|
local precip = nval_prec < (nval_humid - 50) / 50 + PRECOFF and
|
||||||
nval_humid - grad * nval_temp > yint
|
nval_humid - grad * nval_temp > yint
|
||||||
|
|
||||||
-- Check if player is outside
|
-- Check if player is outside
|
||||||
local outside = minetest.get_node_light(ppos, 0.5) == 15
|
local outside = minetest.get_node_light(ppos, 0.5) == 15
|
||||||
|
|
||||||
-- Occasionally reset player sky
|
-- Occasionally reset player sky
|
||||||
if math.random() < 0.1 then
|
if math.random() < 0.1 then
|
||||||
if precip then
|
if precip then
|
||||||
-- Set overcast sky
|
-- Set overcast sky
|
||||||
local sval
|
local sval
|
||||||
local time = minetest.get_timeofday()
|
local time = minetest.get_timeofday()
|
||||||
if time >= 0.5 then
|
if time >= 0.5 then
|
||||||
time = 1 - time
|
time = 1 - time
|
||||||
end
|
end
|
||||||
-- Sky brightness transitions:
|
-- Sky brightness transitions:
|
||||||
-- First transition (24000 -) 4500, (1 -) 0.1875
|
-- First transition (24000 -) 4500, (1 -) 0.1875
|
||||||
-- Last transition (24000 -) 5750, (1 -) 0.2396
|
-- Last transition (24000 -) 5750, (1 -) 0.2396
|
||||||
if time <= 0.1875 then
|
if time <= 0.1875 then
|
||||||
sval = NISVAL
|
sval = NISVAL
|
||||||
elseif time >= 0.2396 then
|
elseif time >= 0.2396 then
|
||||||
sval = DASVAL
|
sval = DASVAL
|
||||||
|
else
|
||||||
|
sval = math.floor(NISVAL + ((time - 0.1875) / 0.0521) * difsval)
|
||||||
|
end
|
||||||
|
|
||||||
|
player:set_sky({r = sval, g = sval, b = sval + 16, a = 255}, "plain", {})
|
||||||
else
|
else
|
||||||
sval = math.floor(NISVAL + ((time - 0.1875) / 0.0521) * difsval)
|
-- Reset sky to normal
|
||||||
|
player:set_sky({}, "regular", {})
|
||||||
end
|
end
|
||||||
|
|
||||||
player:set_sky({r = sval, g = sval, b = sval + 16, a = 255}, "plain", {})
|
|
||||||
else
|
|
||||||
-- Reset sky to normal
|
|
||||||
player:set_sky({}, "regular", {})
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if not precip or not outside or freeze then
|
if not precip or not outside or freeze then
|
||||||
if handles[player_name] then
|
if handles[player_name] then
|
||||||
-- Stop sound if playing
|
-- Stop sound if playing
|
||||||
minetest.sound_stop(handles[player_name])
|
minetest.sound_stop(handles[player_name])
|
||||||
handles[player_name] = nil
|
handles[player_name] = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if precip and outside then
|
if precip and outside then
|
||||||
-- Precipitation
|
-- Precipitation
|
||||||
if freeze then
|
if freeze then
|
||||||
-- Snowfall
|
-- Snowfall
|
||||||
for flake = 1, FLAKES do
|
for flake = 1, FLAKES do
|
||||||
minetest.add_particle({
|
minetest.add_particle({
|
||||||
pos = {
|
pos = {
|
||||||
x = pposx - 24 + math.random(0, 47),
|
x = pposx - 24 + math.random(0, 47),
|
||||||
y = pposy + 8 + math.random(0, 1),
|
y = pposy + 8 + math.random(0, 1),
|
||||||
z = pposz - 20 + math.random(0, 47)
|
z = pposz - 20 + math.random(0, 47)
|
||||||
},
|
},
|
||||||
vel = {
|
vel = {
|
||||||
x = 0.0,
|
x = 0.0,
|
||||||
y = -2.0,
|
y = -2.0,
|
||||||
z = -1.0
|
z = -1.0
|
||||||
},
|
},
|
||||||
acc = {x = 0, y = 0, z = 0},
|
acc = {x = 0, y = 0, z = 0},
|
||||||
expirationtime = 8.5,
|
expirationtime = 8.5,
|
||||||
size = 2.8,
|
size = 2.8,
|
||||||
collisiondetection = COLLIDE,
|
collisiondetection = COLLIDE,
|
||||||
collision_removal = true,
|
collision_removal = true,
|
||||||
vertical = false,
|
vertical = false,
|
||||||
texture = "snowdrift_snowflake" .. math.random(1, 4) .. ".png",
|
texture = "snowdrift_snowflake" .. math.random(1, 4) .. ".png",
|
||||||
playername = player:get_player_name()
|
playername = player:get_player_name()
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- Rainfall
|
-- Rainfall
|
||||||
for flake = 1, DROPS do
|
for flake = 1, DROPS do
|
||||||
minetest.add_particle({
|
minetest.add_particle({
|
||||||
pos = {
|
pos = {
|
||||||
x = pposx - 8 + math.random(0, 16),
|
x = pposx - 8 + math.random(0, 16),
|
||||||
y = pposy + 8 + math.random(0, 5),
|
y = pposy + 8 + math.random(0, 5),
|
||||||
z = pposz - 8 + math.random(0, 16)
|
z = pposz - 8 + math.random(0, 16)
|
||||||
},
|
},
|
||||||
vel = {
|
vel = {
|
||||||
x = 0.0,
|
x = 0.0,
|
||||||
y = -10.0,
|
y = -10.0,
|
||||||
z = 0.0
|
z = 0.0
|
||||||
},
|
},
|
||||||
acc = {x = 0, y = 0, z = 0},
|
acc = {x = 0, y = 0, z = 0},
|
||||||
expirationtime = 2.1,
|
expirationtime = 2.1,
|
||||||
size = 2.8,
|
size = 2.8,
|
||||||
collisiondetection = COLLIDE,
|
collisiondetection = COLLIDE,
|
||||||
collision_removal = true,
|
collision_removal = true,
|
||||||
vertical = true,
|
vertical = true,
|
||||||
texture = "snowdrift_raindrop.png",
|
texture = "snowdrift_raindrop.png",
|
||||||
playername = player:get_player_name()
|
playername = player:get_player_name()
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
if not handles[player_name] then
|
if not handles[player_name] then
|
||||||
-- Start sound if not playing
|
-- Start sound if not playing
|
||||||
local handle = minetest.sound_play(
|
local handle = minetest.sound_play(
|
||||||
"snowdrift_rain",
|
"snowdrift_rain",
|
||||||
{
|
{
|
||||||
to_player = player_name,
|
to_player = player_name,
|
||||||
gain = RAINGAIN,
|
gain = RAINGAIN,
|
||||||
loop = true,
|
loop = true,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
if handle then
|
if handle then
|
||||||
handles[player_name] = handle
|
handles[player_name] = handle
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
elseif handles[player_name] then
|
||||||
|
-- Stop sound when player goes under y limit
|
||||||
|
minetest.sound_stop(handles[player_name])
|
||||||
|
handles[player_name] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Reference in New Issue