10
README.md
@ -32,14 +32,14 @@ Authors of media files:
|
||||
TeddyDesTodes:
|
||||
Snowflakes licensed under CC-BY-SA 3.0 by from weather branch at https://github.com/TeddyDesTodes/minetest/tree/weather
|
||||
|
||||
* `snow_snowflake1.png` - CC-BY-SA 3.0
|
||||
* `snow_snowflake2.png` - CC-BY-SA 3.0
|
||||
* `weather_pack_snow_snowflake1.png` - CC-BY-SA 3.0
|
||||
* `weather_pack_snow_snowflake2.png` - CC-BY-SA 3.0
|
||||
|
||||
xeranas:
|
||||
|
||||
* `rain_raindrop_1.png` - CC-0
|
||||
* `rain_raindrop_2.png` - CC-0
|
||||
* `rain_raindrop_3.png` - CC-0
|
||||
* `weather_pack_rain_raindrop_1.png` - CC-0
|
||||
* `weather_pack_rain_raindrop_2.png` - CC-0
|
||||
* `weather_pack_rain_raindrop_3.png` - CC-0
|
||||
|
||||
inchadney (http://freesound.org/people/inchadney/):
|
||||
|
||||
|
1
depends.txt
Normal file
@ -0,0 +1 @@
|
||||
lightning?
|
12
init.lua
Normal file
@ -0,0 +1,12 @@
|
||||
local modpath = minetest.get_modpath("weather_pack");
|
||||
dofile(modpath.."/weather_core.lua")
|
||||
dofile(modpath.."/snow.lua")
|
||||
dofile(modpath.."/rain.lua")
|
||||
|
||||
if minetest.get_modpath("lightning") ~= nil then
|
||||
dofile(modpath.."/thunder.lua")
|
||||
end
|
||||
|
||||
if minetest.get_modpath("skycolor") == nil then
|
||||
dofile(modpath.."/skycolor.lua")
|
||||
end
|
@ -21,32 +21,16 @@ rain.sound_handler = function(player)
|
||||
})
|
||||
end
|
||||
|
||||
-- set skybox based on time (darker if night lighter otherwise)
|
||||
-- set skybox based on time (uses skycolor api)
|
||||
rain.set_sky_box = function(player)
|
||||
local current_time = minetest.get_timeofday()
|
||||
local diff = math.abs(rain.sky_last_update - math.floor(current_time * 10))
|
||||
-- don't need update sky if time does not change significantly
|
||||
if diff < 1 then
|
||||
return
|
||||
end
|
||||
|
||||
local color_table = {}
|
||||
color_table[0] = {r=6, g=8, b=8}
|
||||
color_table[1] = {r=16, g=23, b=23}
|
||||
color_table[2] = {r=32, g=46, b=46}
|
||||
color_table[3] = {r=48, g=69, b=69}
|
||||
color_table[4] = {r=64, g=92, b=92}
|
||||
color_table[5] = {r=70, g=100, b=100}
|
||||
color_table[6] = {r=64, g=92, b=92}
|
||||
color_table[7] = {r=48, g=69, b=69}
|
||||
color_table[8] = {r=32, g=46, b=46}
|
||||
color_table[9] = {r=16, g=23, b=23}
|
||||
|
||||
local timeofday = current_time
|
||||
local rounded_time = math.floor(timeofday * 10)
|
||||
|
||||
player:set_sky(color_table[rounded_time], "plain", nil)
|
||||
rain.sky_last_update = rounded_time
|
||||
skycolor.colors = {
|
||||
{r=0, g=0, b=0},
|
||||
{r=85, g=86, b=98},
|
||||
{r=152, g=150, b=159},
|
||||
{r=85, g=86, b=98},
|
||||
{r=0, g=0, b=0},
|
||||
}
|
||||
skycolor.active = true
|
||||
end
|
||||
|
||||
-- creating manually parctiles instead of particles spawner because of easier to control
|
||||
@ -79,11 +63,11 @@ rain.get_texture = function()
|
||||
local texture_name
|
||||
local random_number = math.random()
|
||||
if random_number > 0.33 then
|
||||
texture_name = "rain_raindrop_1.png"
|
||||
texture_name = "weather_pack_rain_raindrop_1.png"
|
||||
elseif random_number > 0.66 then
|
||||
texture_name = "rain_raindrop_2.png"
|
||||
texture_name = "weather_pack_rain_raindrop_2.png"
|
||||
else
|
||||
texture_name = "rain_raindrop_3.png"
|
||||
texture_name = "weather_pack_rain_raindrop_3.png"
|
||||
end
|
||||
return texture_name;
|
||||
end
|
||||
@ -144,6 +128,9 @@ end
|
||||
rain.clear = function()
|
||||
rain.raining = false
|
||||
rain.sky_last_update = -1
|
||||
skycolor.active = false
|
||||
skycolor.colors = {}
|
||||
skycolor.set_default_sky()
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
rain.remove_sound(player)
|
||||
rain.remove_player(player)
|
||||
@ -160,12 +147,12 @@ end)
|
||||
|
||||
rain.make_weather = function()
|
||||
rain.raining = true
|
||||
rain.set_sky_box()
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
if (weather.is_underwater(player)) then
|
||||
return false
|
||||
end
|
||||
rain.add_player(player)
|
||||
rain.set_sky_box(player)
|
||||
rain.add_rain_particles(player)
|
||||
rain.update_sound(player)
|
||||
end
|
@ -1 +0,0 @@
|
||||
weather_core
|
@ -1,3 +0,0 @@
|
||||
-- init file for rain
|
||||
local modpath = minetest.get_modpath("rain");
|
||||
dofile(modpath.."/rain.lua")
|
71
skycolor.lua
Normal file
@ -0,0 +1,71 @@
|
||||
skycolor = {
|
||||
-- Should be activated before do any effect.
|
||||
active = false,
|
||||
|
||||
-- Update interval.
|
||||
update_interval = 15,
|
||||
|
||||
-- Main sky colors: starts from midnight to midnight.
|
||||
colors = {},
|
||||
|
||||
-- Update sky color. If players not specified update sky for all players.
|
||||
update_sky_color = function(players)
|
||||
local timeofday = minetest.get_timeofday()
|
||||
local rounded_time = math.floor(timeofday * 1000)
|
||||
local color = skycolor.utils.convert_to_rgb(0, 1000, rounded_time, skycolor.colors)
|
||||
|
||||
if players == nil or #players == 0 then
|
||||
players = minetest.get_connected_players()
|
||||
end
|
||||
for _, player in ipairs(players) do
|
||||
player:set_sky(color, "plain", nil)
|
||||
end
|
||||
|
||||
end,
|
||||
|
||||
-- Reset sky color to game default. If players not specified update sky for all players.
|
||||
set_default_sky = function(players)
|
||||
if players == nil or #players == 0 then
|
||||
players = minetest.get_connected_players()
|
||||
end
|
||||
for _, player in ipairs(players) do
|
||||
player:set_sky(nil, "regular", nil)
|
||||
end
|
||||
end,
|
||||
|
||||
utils = {
|
||||
convert_to_rgb = function(minval, maxval, current_val, colors)
|
||||
local max_index = #colors - 1
|
||||
local val = (current_val-minval) / (maxval-minval) * max_index + 1.0
|
||||
local index1 = math.floor(val)
|
||||
local index2 = math.min(math.floor(val)+1, max_index + 1)
|
||||
local f = val - index1
|
||||
local c1 = colors[index1]
|
||||
local c2 = colors[index2]
|
||||
return {r=math.floor(c1.r + f*(c2.r - c1.r)), g=math.floor(c1.g + f*(c2.g-c1.g)), b=math.floor(c1.b + f*(c2.b - c1.b))}
|
||||
end
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
local timer = -1
|
||||
minetest.register_globalstep(function(dtime)
|
||||
if skycolor.active ~= true then
|
||||
return
|
||||
end
|
||||
|
||||
-- exceptional first time update
|
||||
if timer <= 0 then
|
||||
skycolor.update_sky_color()
|
||||
timer = 0
|
||||
return
|
||||
end
|
||||
|
||||
-- regular updates based on iterval
|
||||
timer = timer + dtime;
|
||||
if timer >= skycolor.update_interval then
|
||||
skycolor.update_sky_color()
|
||||
timer = 0
|
||||
end
|
||||
|
||||
end)
|
@ -26,14 +26,29 @@ snow.add_rain_particles = function(player)
|
||||
end
|
||||
end
|
||||
|
||||
snow.set_sky_box = function()
|
||||
skycolor.colors = {
|
||||
{r=0, g=0, b=0},
|
||||
{r=241, g=244, b=249},
|
||||
{r=0, g=0, b=0},
|
||||
}
|
||||
skycolor.active = true
|
||||
end
|
||||
|
||||
snow.clear = function()
|
||||
skycolor.active = false
|
||||
skycolor.colors = {}
|
||||
skycolor.set_default_sky()
|
||||
end
|
||||
|
||||
-- Simple random texture getter
|
||||
snow.get_texture = function()
|
||||
local texture_name
|
||||
local random_number = math.random()
|
||||
if random_number > 0.5 then
|
||||
texture_name = "snow_snowflake1.png"
|
||||
texture_name = "weather_pack_snow_snowflake1.png"
|
||||
else
|
||||
texture_name = "snow_snowflake2.png"
|
||||
texture_name = "weather_pack_snow_snowflake2.png"
|
||||
end
|
||||
return texture_name;
|
||||
end
|
||||
@ -43,6 +58,7 @@ minetest.register_globalstep(function(dtime)
|
||||
return false
|
||||
end
|
||||
|
||||
snow.set_sky_box()
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
if (weather.is_underwater(player)) then
|
||||
return false
|
||||
@ -55,6 +71,6 @@ end)
|
||||
if weather.reg_weathers.snow == nil then
|
||||
weather.reg_weathers.snow = {
|
||||
chance = 10,
|
||||
clear = function() end
|
||||
clear = snow.clear
|
||||
}
|
||||
end
|
@ -1 +0,0 @@
|
||||
weather_core
|
@ -1,3 +0,0 @@
|
||||
-- init file for snow
|
||||
local modpath = minetest.get_modpath("snow");
|
||||
dofile(modpath.."/snow.lua")
|
Before Width: | Height: | Size: 296 B After Width: | Height: | Size: 296 B |
Before Width: | Height: | Size: 209 B After Width: | Height: | Size: 209 B |
Before Width: | Height: | Size: 220 B After Width: | Height: | Size: 220 B |
Before Width: | Height: | Size: 192 B After Width: | Height: | Size: 192 B |
Before Width: | Height: | Size: 195 B After Width: | Height: | Size: 195 B |
@ -1,3 +0,0 @@
|
||||
weather_core
|
||||
rain
|
||||
lightning?
|
@ -1,5 +0,0 @@
|
||||
-- init file for thunder
|
||||
if minetest.get_modpath("lightning") ~= nil then
|
||||
local modpath = minetest.get_modpath("thunder");
|
||||
dofile(modpath.."/thunder.lua")
|
||||
end
|
@ -1,3 +0,0 @@
|
||||
-- init file for weather_core
|
||||
local modpath = minetest.get_modpath("weather_core");
|
||||
dofile(modpath.."/weather_core.lua")
|