Add rain. Remove mgv6 support. Add humidity noise to control rarity of precipitation. Use MIT source code licence

master
paramat 2017-04-13 23:15:04 +01:00
parent e599566038
commit ecf29afdfe
4 changed files with 134 additions and 144 deletions

View File

@ -1,4 +1,4 @@
snowdrift 0.4.0 by paramat snowdrift 0.5.0 by paramat
For Minetest 0.4.12 and later For Minetest 0.4.12 and later
Depends default Depends default
Licenses: code WTFPL, textures CC BY-SA Licenses: Source code MIT. Media (textures) CC BY-SA (3.0)

244
init.lua
View File

@ -1,18 +1,12 @@
-- Parameters -- Parameters
local PRECSPR = 11 -- Time scale for precipitation variation in minutes local PRECSPR = 11 -- Time scale for precipitation variation in minutes
local PRECTHR = -1 -- Precipitation noise threshold: local PRECOFF = 0.8 -- Precipitation noise threshold offset
-- -1 continuous, -0.3 two thirds the time, local PROCHA = 0.2 -- Per player per globalstep processing chance
-- 0 half the time, 0.3 one third the time, 1 none. local FLAKES = 8 -- Snowflake density
local PROCHA = 0.1 -- Per player per globalstep processing chance local DROPS = 16 -- Rainfall density
local FLAKES = 32 -- Snowflake density local NISVAL = 39 -- Clouds RGB value at night
local NISVAL = 39 -- Snow clouds RGB value at night local DASVAL = 175 -- Clouds RGB value in daytime
local DASVAL = 175 -- Snow clouds RGB value in daytime
-- Stuff
local difsval = DASVAL - NISVAL
local np_prec = { local np_prec = {
offset = 0, offset = 0,
@ -25,77 +19,86 @@ local np_prec = {
--flags = "" --flags = ""
} }
local np_temp, tempthr -- These 2 must match biome heat and humidity noise parameters for a world
local mg_params = minetest.get_mapgen_params()
if mg_params.mgname == "v6" then local np_temp = {
np_temp = { offset = 50,
offset = 0, scale = 50,
scale = 1, spread = {x = 1000, y = 1000, z = 1000},
spread = {x = 500, y = 500, z = 500}, seed = 5349,
seed = 9130, octaves = 3,
octaves = 3, persist = 0.5,
persist = 0.5, lacunarity = 2.0,
lacunarity = 2.0, --flags = ""
--flags = "" }
}
tempthr = -0.4 local np_humid = {
else offset = 50,
np_temp = { scale = 50,
offset = 0, spread = {x = 1000, y = 1000, z = 1000},
scale = 1, seed = 842,
spread = {x = 1000, y = 1000, z = 1000}, octaves = 3,
seed = 5349, persist = 0.5,
octaves = 3, lacunarity = 2.0,
persist = 0.5, --flags = ""
lacunarity = 2.0, }
--flags = ""
}
tempthr = -0.4 -- Stuff
end
local difsval = DASVAL - NISVAL
-- Initialise noise objects to nil
local nobj_temp = nil
local nobj_humid = nil
local nobj_prec = nil
-- Globalstep function -- Globalstep function
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
for _, player in ipairs(minetest.get_connected_players()) do for _, player in ipairs(minetest.get_connected_players()) do
-- randomise and spread processing load -- Randomise and spread processing load
if math.random() > PROCHA then if math.random() > PROCHA then
return return
end end
-- check if in snow biome
local ppos = player:getpos() local ppos = player:getpos()
local pposx = math.floor(ppos.x) local pposx = math.floor(ppos.x)
local pposy = math.floor(ppos.y) local pposy = math.floor(ppos.y)
local pposz = math.floor(ppos.z) local pposz = math.floor(ppos.z)
local nobj_temp = minetest.get_perlin(np_temp)
local nval_temp
if mg_params.mgname == "v6" then
nval_temp = nobj_temp:get2d({x = pposx + 300, y = pposz + 100})
else -- mgv5, mgv7
nval_temp = nobj_temp:get2d({x = pposx, y = pposz})
end
local snowbiome = nval_temp <= tempthr
-- check if snow is currently falling local nobj_temp = nobj_temp or minetest.get_perlin(np_temp)
local nobj_prec = minetest.get_perlin(np_prec) local nobj_humid = nobj_humid or minetest.get_perlin(np_humid)
local snowfall = nobj_prec:get2d({x = os.clock() / 60, y = 0}) >= PRECTHR local nobj_prec = nobj_prec or minetest.get_perlin(np_prec)
-- check if player is outside local nval_temp = nobj_temp: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})
-- Biome system: frozen biomes below heat 35,
-- deserts below humidity 20
local freeze = nval_temp < 35
local precip = nval_prec > (nval_humid - 50) / 50 + PRECOFF
-- 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.05 then
if snowbiome and snowfall then if precip then
-- set sky to snow clouds -- 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
-- first transition (24000 -) 4500, (1 -) 0.1875 -- Sky brightness transitions:
-- last transition (24000 -) 5750, (1 -) 0.2396 -- First transition (24000 -) 4500, (1 -) 0.1875
-- 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
@ -105,84 +108,61 @@ minetest.register_globalstep(function(dtime)
end end
player:set_sky({r = sval, g = sval, b = sval + 16, a = 255}, "plain", {}) player:set_sky({r = sval, g = sval, b = sval + 16, a = 255}, "plain", {})
else -- reset sky to normal else
-- Reset sky to normal
player:set_sky({}, "regular", {}) player:set_sky({}, "regular", {})
end end
end end
if snowbiome and snowfall and outside then if precip and outside then
-- snowfall -- Precipitation
for flake = 1, FLAKES do if freeze then
minetest.add_particle({ -- Snowfall
pos = { for flake = 1, FLAKES do
x = pposx - 48 + math.random(0, 95), minetest.add_particle({
y = pposy + 12 + math.random(), pos = {
z = pposz - 36 + math.random(0, 95) x = pposx - 32 + math.random(0, 63),
}, y = pposy + 10 + math.random(0, 4),
vel = { z = pposz - 26 + math.random(0, 63)
x = -0.1 + math.random() * 0.2, },
y = -1.6 + math.random() * 0.2, vel = {
z = -1.1 + math.random() * 0.2 x = 0.0,
}, y = -2.0,
acc = {x = 0, y = 0, z = 0}, z = -1.0
expirationtime = 16, },
size = 2.8, acc = {x = 0, y = 0, z = 0},
collisiondetection = false, expirationtime = 12,
vertical = false, size = 2.8,
texture = "snowdrift_snowflake" .. math.random(1, 4) .. ".png", collisiondetection = false,
playername = player:get_player_name() vertical = false,
}) texture = "snowdrift_snowflake" .. math.random(1, 4) .. ".png",
playername = player:get_player_name()
})
end
else
-- Rainfall
for flake = 1, DROPS do
minetest.add_particle({
pos = {
x = pposx - 8 + math.random(0, 16),
y = pposy + 6 + math.random(0, 4),
z = pposz - 8 + math.random(0, 16)
},
vel = {
x = 0.0,
y = -8.0,
z = 0.0
},
acc = {x = 0, y = 0, z = 0},
expirationtime = 2,
size = 2.8,
collisiondetection = false,
vertical = true,
texture = "snowdrift_raindrop.png",
playername = player:get_player_name()
})
end
end end
end end
end end
end) end)
--[[ snow settling
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)
-- check under open sky
if minetest.get_node_light({x = sposx, y = pposy + 32, z = sposz}, 0.5) == 15 then
for y = pposy + 48, pposy - 48, -1 do -- find surface
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"
or nodename == "default:water_source" then
break
else -- check node drawtype
local drawtype = minetest.registered_nodes[nodename].drawtype
if drawtype == "normal"
or drawtype == "glasslike"
or drawtype == "glasslike_framed"
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"}
)
end
minetest.add_node(
{x = sposx, y = y + 1, z = sposz},
{name="default:snow"}
)
break
-- 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"})
end
break
else
break
end
end
end
end
end
end --]]

View File

@ -1,14 +1,24 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE License of source code
Version 2, December 2004 ----------------------
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> The MIT License (MIT)
Copyright (C) 2014-2016 paramat
Everyone is permitted to copy and distribute verbatim or modified Permission is hereby granted, free of charge, to any person obtaining a copy of this
copies of this license document, and changing it is allowed as long software and associated documentation files (the "Software"), to deal in the Software
as the name is changed. without restriction, including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE The above copyright notice and this permission notice shall be included in all copies or
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION substantial portions of the Software.
0. You just DO WHAT THE FUCK YOU WANT TO. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
For more details:
https://opensource.org/licenses/MIT

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B