Version 0.6.0. Only spawn particles under open sky (light == 15) and use collision detection

master
paramat 2018-07-24 18:46:04 +01:00
parent 67f04e72fa
commit aa1ae896ef
2 changed files with 66 additions and 67 deletions

View File

@ -1,10 +1,10 @@
snowdrift 0.5.2 by paramat snowdrift 0.6.0 by paramat
For Minetest 0.4.15 and later For Minetest 0.4.15 and later
Depends default Depends: default
Licenses: Licenses
Source code: --------
MIT by paramat Source code: MIT by paramat
Media: Media:
Textures CC BY-SA (3.0) by paramat Textures CC BY-SA (3.0) by paramat
Sounds CC BY (3.0) by inchadney Sounds CC BY (3.0) by inchadney

123
init.lua
View File

@ -4,16 +4,15 @@ local YLIMIT = 1 -- Set to world's water level
-- Particles are timed to disappear at this y -- Particles are timed to disappear at this y
-- Particles do not spawn when player's head is below this y -- Particles do not spawn when player's head is 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 = 10---0.4 -- Precipitation offset, higher = rains more often
local GSCYCLE = 0.5 -- Globalstep cycle (seconds) local GSCYCLE = 0.5 -- Globalstep cycle (seconds)
local FLAKES = 32 -- Snowflakes per cycle local FLAKPOS = 48 -- Snowflake light-tested positions per cycle
local DROPS = 128 -- Raindrops per cycle local DROPPOS = 192 -- Raindrop light-tested positions per cycle
local RAINGAIN = 0.2 -- Rain sound volume local RAINGAIN = 0.2 -- Rain sound volume
local COLLIDE = false -- Whether particles collide with nodes
local NISVAL = 39 -- Clouds RGB value at night local NISVAL = 39 -- Clouds RGB value at night
local DASVAL = 175 -- Clouds RGB value in daytime local DASVAL = 175 -- Clouds RGB value in daytime
local FRADIUS = 48 -- Radius in which flakes are created local FLAKRAD = 32 -- Radius in which flakes are created
local DRADIUS = 24 -- Radius in which drops are created local DROPRAD = 16 -- Radius in which drops are created
local np_prec = { local np_prec = {
offset = 0, offset = 0,
@ -23,7 +22,7 @@ local np_prec = {
octaves = 1, octaves = 1,
persist = 0, persist = 0,
lacunarity = 2.0, lacunarity = 2.0,
--flags = "" flags = "defaults"
} }
-- These 2 must match biome heat and humidity noise parameters for a world -- These 2 must match biome heat and humidity noise parameters for a world
@ -36,7 +35,7 @@ local np_temp = {
octaves = 3, octaves = 3,
persist = 0.5, persist = 0.5,
lacunarity = 2.0, lacunarity = 2.0,
--flags = "" flags = "defaults"
} }
local np_humid = { local np_humid = {
@ -47,7 +46,7 @@ local np_humid = {
octaves = 3, octaves = 3,
persist = 0.5, persist = 0.5,
lacunarity = 2.0, lacunarity = 2.0,
--flags = "" flags = "defaults"
} }
@ -81,10 +80,11 @@ 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()
-- Predict player position as slightly behind the CYCLE interval. -- Predict player position as slightly behind the CYCLE interval.
-- Assume scheduling gets behind slighly (the 1.5), this also tested well. -- Assume scheduling gets behind slighly (the 1.5).
local ppos = vector.add(player:getpos(), local ppos = vector.add(player:getpos(),
vector.multiply(player:get_player_velocity(), GSCYCLE * 1.5)) vector.multiply(player:get_player_velocity(), GSCYCLE * 1.5))
local pposy = math.floor(ppos.y) + 2 -- Precipitation when swimming -- Point just above player head, for precipitation when swimming
local pposy = math.floor(ppos.y) + 2
if pposy >= YLIMIT - 2 then if pposy >= YLIMIT - 2 then
local pposx = math.floor(ppos.x) local pposx = math.floor(ppos.x)
local pposz = math.floor(ppos.z) local pposz = math.floor(ppos.z)
@ -96,6 +96,7 @@ minetest.register_globalstep(function(dtime)
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})
-- TODO global so move to before player loop
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,
@ -110,9 +111,6 @@ minetest.register_globalstep(function(dtime)
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
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
@ -145,7 +143,7 @@ minetest.register_globalstep(function(dtime)
end end
end end
if not precip or not outside or freeze then if not precip 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])
@ -153,59 +151,60 @@ minetest.register_globalstep(function(dtime)
end end
end end
if precip and outside then if precip then
-- Precipitation -- Precipitation
if freeze then if freeze then
-- Snowfall -- Snowfall
local extime = math.min((pposy + 12 - YLIMIT) / 2, 9) for flake = 1, FLAKPOS do
for flake = 1, FLAKES do local spawnx = pposx - FLAKRAD +
minetest.add_particle({ math.random(0, FLAKRAD * 2)
pos = { local spawnz = pposz - FLAKRAD +
x = pposx - FRADIUS + math.random(0, FRADIUS * 2), math.random(0, FLAKRAD * 2)
y = pposy + 12, if minetest.get_node_light(
z = pposz - FRADIUS + math.random(0, FRADIUS * 2) {x = spawnx, y = pposy + 10, z = spawnz},
}, 0.5) == 15 then
velocity = { local spawny = pposy + 10 + math.random(0, 40) / 10
x = (-20 + math.random(0, 40)) / 100, local extime = math.min((spawny - YLIMIT) / 2, 10)
y = -2.0, minetest.add_particle({
z = (-20 + math.random(0, 40)) / 100 pos = {x = spawnx, y = spawny, z = spawnz},
}, velocity = {x = 0, y = -2.0, z = 0},
acceleration = {x = 0, y = 0, z = 0}, acceleration = {x = 0, y = 0, z = 0},
expirationtime = extime, expirationtime = extime,
size = 2.8, size = 2.8,
collisiondetection = COLLIDE, collisiondetection = true,
collision_removal = true, collision_removal = true,
vertical = false, vertical = false,
texture = "snowdrift_snowflake" .. texture = "snowdrift_snowflake" ..
math.random(1, 12) .. ".png", math.random(1, 12) .. ".png",
playername = player:get_player_name() playername = player:get_player_name()
}) })
end
end end
else else
-- Rainfall -- Rainfall
for drop = 1, DROPS do for drop = 1, DROPPOS do
local spawny = pposy + 10 + math.random(0, 40) / 10 local spawnx = pposx - DROPRAD +
local extime = math.min((spawny - YLIMIT) / 10, 1.8) math.random(0, DROPRAD * 2)
minetest.add_particle({ local spawnz = pposz - DROPRAD +
pos = { math.random(0, DROPRAD * 2)
x = pposx - DRADIUS + math.random(0, DRADIUS * 2), if minetest.get_node_light(
y = spawny, {x = spawnx, y = pposy + 10, z = spawnz},
z = pposz - DRADIUS + math.random(0, DRADIUS * 2) 0.5) == 15 then
}, local spawny = pposy + 10 + math.random(0, 40) / 10
velocity = { local extime = math.min((spawny - YLIMIT) / 10, 2)
x = 0.0, minetest.add_particle({
y = -10.0, pos = {x = spawnx, y = spawny, z = spawnz},
z = 0.0 velocity = {x = 0.0, y = -10.0, z = 0.0},
}, acceleration = {x = 0, y = 0, z = 0},
acceleration = {x = 0, y = 0, z = 0}, expirationtime = extime,
expirationtime = extime, size = 2.8,
size = 2.8, collisiondetection = true,
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 end
if not handles[player_name] then if not handles[player_name] then