Remove rain. Darken sky in snow biomes. Auto detect mapgen to set noise parameters. Cleanup code. Make flake number finely adjustable

master
paramat 2015-09-02 06:31:38 +01:00
parent c42ad19c9a
commit 5215470195
3 changed files with 72 additions and 125 deletions

View File

@ -1,4 +1,4 @@
snowdrift 0.3.0 by paramat
For latest stable Minetest and back to 0.4.9 dev after 13/01/14
snowdrift 0.4.0 by paramat
For Minetest 0.4.12 and later
Depends default
Licenses: code WTFPL, textures CC BY-SA

193
init.lua
View File

@ -1,50 +1,40 @@
-- snowdrift 0.3.0 by paramat
-- For latest stable Minetest and back to 0.4.9 dev after 13/01/14
-- Depends default
-- Licenses: code WTFPL, textures CC BY-SA
-- snowfall heaviness parameter
-- rain off by default
-- snow and rain heavier by default
-- update particle spawn format
-- Parameters
local SCALP = 11 -- Time scale for precipitation in minutes
local PRET = -1 -- -1 to 1. Precipitation threshold: 1 none, -1 continuous, -0.3 two thirds the time, 0 half the time, 0.3 one third the time
local PPPCHA = 0.1 -- 0 to 1. Per player processing chance. Controls and randomizes processing load
local SCALP = 11 -- Time scale for precipitation variation in minutes
local PRET = -1 -- -1 to 1. Precipitation threshold:
-- 1 none, -1 continuous, -0.3 two thirds the time,
-- 0 half the time, 0.3 one third the time.
local PPPCHA = 0.1 -- 0 to 1. Per player processing chance.
-- Controls and randomizes processing load.
local SETCHA = 0.2 -- 0 to 1. Snow settling chance
local FLAKES = 2 -- Snowfall heaviness. Try 1 on slower computers
local DROPS = 32 -- Rainfall heaviness. Reduce on slower computers
local SNOW = true -- Snowfall below temperature threshold
local FLAKES = 8 -- Snowfall heaviness. Try 1 on slower computers.
local SETTLE = false -- Snow collects on ground within 32 nodes of player
local RAIN = false -- Rain above humidity threshold
local THOVER = false -- Instead use a temperature and humidity system with
-- snow in overlap of cold and humid areas, else rain in humid areas
-- Temperature noise parameters
local SEEDT = 112 -- 112 These are default noise parameters from snow mod by Splizard
local OCTAT = 3 -- 3 use these for snowfall in those snow biomes
local PERST = 0.5 -- 0.5
local SCALT = 150 -- 150
local TET = -0.53 -- -0.53 Temperature threshold for snow. Negative because here this noise is temperature, in snow mod it's coldness
-- Humidity noise parameters
local SEEDH = 72384 -- 72384 These are default noise parameters for mapgen V6 humidity
local OCTAH = 4 -- 4 note these cause rain in deserts
local PERSH = 0.66 -- 0.66
local SCALH = 500 -- 500
local HUT = 0 -- Humidity threshold for rain
-- Stuff
-- Detect mapgen to select noise parameters
local TSEED, TOCTA, TPERS, TSCAL, TTHR
local mg_params = minetest.get_mapgen_params()
if mg_params.mgname == "v6" then
TSEED = 9130
TOCTA = 3
TPERS = 0.5
TSCAL = 500
TTHR = -0.4
else
TSEED = 5349
TOCTA = 3
TPERS = 0.5
TSCAL = 1000
TTHR = -0.4
end
snowdrift = {}
-- Globalstep function
minetest.register_globalstep(function(dtime)
local perlinp = minetest.get_perlin(813, 1, 0.5, SCALP)
if perlinp:get2d({x = os.clock()/60, y = 0}) < PRET then
if perlinp:get2d({x = os.clock() / 60, y = 0}) < PRET then
return
end
for _, player in ipairs(minetest.get_connected_players()) do
@ -55,93 +45,54 @@ minetest.register_globalstep(function(dtime)
if minetest.get_node_light(ppos, 0.5) ~= 15 then
return
end
local pposx = math.floor(ppos.x)
local pposy = math.floor(ppos.y)
local pposz = math.floor(ppos.z)
local snow = false
local rain = false
local perlint = minetest.get_perlin(TSEED, TOCTA, TPERS, TSCAL)
local noiset
local noiseh
if SNOW or THOVER then
local perlint = minetest.get_perlin(SEEDT, OCTAT, PERST, SCALT)
if mg_params.mgname == "v6" then
noiset = perlint:get2d({x = pposx + 300, y = pposz + 100})
else
noiset = perlint:get2d({x = pposx, y = pposz})
end
if RAIN or THOVER then
local perlinh = minetest.get_perlin(SEEDH, OCTAH, PERSH, SCALH)
noiseh = perlinh:get2d({x = pposx, y = pposz})
end
if THOVER then
if noiset < TET and noiseh > HUT then
snow = true
elseif noiseh > HUT then
rain = true
if noiset <= TTHR then
-- TODO set sky darkness depending on time of day
-- set number of flakes from TTHR - noiset
if math.random() < 0.1 then
player:set_sky({r = 143, g = 143, b = 143, a = 255}, "plain", {})
end
elseif SNOW then
if -noiset < TET then -- negative sign because snow mod noise is 'coldness'
snow = true
elseif RAIN then
if noiseh > HUT then
rain = true
end
end
elseif RAIN then
if noiseh > HUT then
rain = true
end
end
if snow then
for flake = 1, FLAKES do
minetest.add_particle({
pos = {x=pposx-32+math.random(0,63), y=pposy+16, z=pposz-16+math.random(0,63)},
vel = {x=math.random()/5-0.1, y=math.random()/5-1.1, z=math.random()/5-1.1},
acc = {x=math.random()/50-0.01, y=math.random()/50-0.01, z=math.random()/50-0.01},
pos = {
x = pposx - 32 + math.random(0,63),
y = pposy + 16,
z = pposz - 16 + math.random(0,63)
},
vel = {
x = math.random() * 0.2 - 0.1,
y = math.random() * 0.2 - 1.1,
z = math.random() * 0.2 - 1.1
},
acc = {x = 0, y = 0, z = 0},
expirationtime = 32,
size = 2.8,
collisiondetection = false,
vertical = false,
texture = "snowdrift_snowflake1.png",
playername = player:get_player_name(),
})
minetest.add_particle({
pos = {x=pposx-32+math.random(0,63), y=pposy+16, z=pposz-16+math.random(0,63)},
vel = {x=math.random()/5-0.1, y=math.random()/5-1.1, z=math.random()/5-1.1},
acc = {x=math.random()/50-0.01, y=math.random()/50-0.01, z=math.random()/50-0.01},
expirationtime = 32,
size = 2.8,
collisiondetection = false,
vertical = false,
texture = "snowdrift_snowflake2.png",
playername = player:get_player_name(),
})
minetest.add_particle({
pos = {x=pposx-32+math.random(0,63), y=pposy+16, z=pposz-16+math.random(0,63)},
vel = {x=math.random()/5-0.1, y=math.random()/5-1.1, z=math.random()/5-1.1},
acc = {x=math.random()/50-0.01, y=math.random()/50-0.01, z=math.random()/50-0.01},
expirationtime = 32,
size = 2.8,
collisiondetection = false,
vertical = false,
texture = "snowdrift_snowflake3.png",
playername = player:get_player_name(),
})
minetest.add_particle({
pos = {x=pposx-32+math.random(0,63), y=pposy+16, z=pposz-16+math.random(0,63)},
vel = {x=math.random()/5-0.1, y=math.random()/5-1.1, z=math.random()/5-1.1},
acc = {x=math.random()/50-0.01, y=math.random()/50-0.01, z=math.random()/50-0.01},
expirationtime = 32,
size = 2.8,
collisiondetection = false,
vertical = false,
texture = "snowdrift_snowflake4.png",
playername = player:get_player_name(),
texture = "snowdrift_snowflake" .. math.random(1, 4) .. ".png",
playername = player:get_player_name()
})
end
if SETTLE and math.random() < SETCHA then -- settling snow
local sposx = pposx - 32 + math.random(0, 63)
local sposz = pposz - 32 + math.random(0, 63)
if minetest.get_node_light({x=sposx, y=pposy+32, z=sposz}, 0.5) == 15 then -- check under open sky
-- check under open sky
if minetest.get_node_light({x = sposx, y = pposy + 32, z = sposz}, 0.5) == 15 then
for y = pposy + 32, pposy - 64, -1 do -- find surface
local nodename = minetest.get_node({x=sposx, y=y, z=sposz}).name
local nodename = minetest.get_node({x = sposx, y = y, z = sposz}).name
if nodename ~= "air" and nodename ~= "ignore" then
if nodename == "default:desert_sand" -- no snow on these
or nodename == "default:desert_stone"
@ -155,14 +106,23 @@ minetest.register_globalstep(function(dtime)
or drawtype == "allfaces"
or drawtype == "allfaces_optional" then
if nodename == "default:dirt_with_grass" then
minetest.add_node({x=sposx, y=y, z=sposz}, {name="default:dirt_with_snow"})
minetest.add_node(
{x = sposx, y = y, z = sposz},
{name="default:dirt_with_snow"}
)
end
minetest.add_node({x=sposx, y=y+1, z=sposz}, {name="default:snow"})
minetest.add_node(
{x = sposx, y = y + 1, z = sposz},
{name="default:snow"}
)
break
elseif drawtype == "plantlike" then -- dirt with snow added under plants
local unodename = minetest.get_node({x=sposx, y=y-1, z=sposz}).name
-- dirt with snow added under plants
elseif drawtype == "plantlike" then
local unodename = minetest.get_node(
{x = sposx, y = y - 1, z = sposz}).name
if unodename == "default:dirt_with_grass" then
minetest.add_node({x=sposx, y=y-1, z=sposz}, {name="default:dirt_with_snow"})
minetest.add_node({x = sposx, y = y - 1, z = sposz},
{name="default:dirt_with_snow"})
end
break
else
@ -173,21 +133,8 @@ minetest.register_globalstep(function(dtime)
end
end
end
elseif math.random() < 0.1 then
player:set_sky({}, "regular", {})
end
if rain then
for drop = 1, DROPS do
minetest.add_particle({
pos = {x=pposx-24+math.random(0,48), y=pposy+16, z=pposz-24+math.random(0,48)},
vel = {x=0, y=-8, z=-1},
acc = {x=0, y=0, z=0},
expirationtime = 4,
size = 2.8,
collisiondetection = false,
vertical = false,
texture = "snowdrift_raindrop.png",
playername = player:get_player_name(),
})
end
end
end
end)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 180 B