Add hail effect and date functions

This commit is contained in:
Till Affeldt 2020-04-10 05:00:31 +02:00
parent dd8b07056a
commit 6481cf409a
15 changed files with 88 additions and 6 deletions

View File

@ -6,3 +6,4 @@
- Snow flake and rain drop textures CC BY-SA (3.0) by paramat, found in snowdrift mod at https://github.com/paramat/snowdrift
- Snow texture composited from individual snow flakes by paramat. CC-BY-SA (3.0)
- Wind sound CC-BY (3.0) by InspectorJ from https://freesound.org/people/InspectorJ/sounds/376415/
- Hail sound CC0 by ikayuka from https://freesound.org/people/ikayuka/sounds/240742/

View File

@ -52,3 +52,4 @@ dofile(weather_mod.modpath.."/weathers/snow.lua")
dofile(weather_mod.modpath.."/weathers/snow_heavy.lua")
dofile(weather_mod.modpath.."/weathers/storm.lua")
dofile(weather_mod.modpath.."/weathers/sandstorm.lua")
dofile(weather_mod.modpath.."/weathers/hail.lua")

View File

@ -14,5 +14,5 @@ function weather_mod.handle_time_progression()
if time < weather_mod.state.time.last_check then
weather_mod.state.time.day = weather_mod.state.time.day + 1
end
weather_mod.state.last_check = time
weather_mod.state.time.last_check = time
end

View File

@ -1,4 +1,4 @@
local days = {
weather_mod.weekdays = {
"Monday",
"Tuesday",
"Wednesday",
@ -8,7 +8,7 @@ local days = {
"Sunday"
}
local months = {
weather_mod.months = {
{ name = "January", days = 31 },
{ name = "February", days = 28 },
{ name = "March", days = 31 },
@ -22,3 +22,37 @@ local months = {
{ name = "November", days = 30 },
{ name = "December", days = 31 }
}
weather_mod.seasons = {
{ name = "spring" },
{ name = "summer" },
{ name = "autumn" },
{ name = "winter" }
}
function weather_mod.get_weekday()
return (weather_mod.state.time.day - 1) % 7 + 1
end
function weather_mod.get_month()
local day = (weather_mod.state.time.day - 1) % 365 + 1
local sum = 0
for i, month in ipairs(weather_mod.months) do
sum = sum + month.days
if sum >= day then
return i
end
end
end
function weather_mod.get_season()
local month = weather_mod.get_month()
return math.floor((month - 1) / 3 + 1)
end
function weather_mod.print_date()
local weekday = weather_mod.weekdays[weather_mod.get_weekday()]
local date = (weather_mod.state.time.day - 1) % 365 + 1
local month = weather_mod.months[weather_mod.get_month()].name
return weekday .. ", " .. date .. ". " .. month
end

View File

@ -3,6 +3,13 @@ minetest.register_privilege("weather", {
give_to_singleplayer = false
})
minetest.register_chatcommand("date", {
func = function(playername, param)
local date = weather_mod.print_date()
minetest.chat_send_player(playername, date)
end
})
-- Force a weather effect to override environment
minetest.register_chatcommand("set_weather", {
params = "<weather>",

View File

@ -1,5 +1,5 @@
local GSCYCLE = 0.05
local RECALCCYCLE = 0
local RECALCCYCLE = 0.2
weather_mod.weathers = {}
function weather_mod.register_effect(name, config, override)
@ -117,6 +117,7 @@ minetest.register_globalstep(function(dtime)
if timer >= RECALCCYCLE then
weather_mod.set_clouds(player)
weather_mod.set_headwind(player)
weather_mod.handle_time_progression()
end
end
timer = 0

BIN
sounds/weather_hail.ogg Normal file

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

BIN
textures/weather_hail1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 B

BIN
textures/weather_hail2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 B

BIN
textures/weather_hail3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 B

BIN
textures/weather_hail4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 B

BIN
textures/weather_hail5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 311 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

38
weathers/hail.lua Normal file
View File

@ -0,0 +1,38 @@
local name = weather_mod.modname .. ":hail"
local config = {}
config.environment = {
spawn_puddles = true,
lightning = true,
damage = true
}
config.sound = {
name = "weather_hail",
gain = 1
}
config.particles = {
min_pos = {x=-9, y=7, z=-9},
max_pos = {x= 9, y=7, z= 9},
falling_speed=15,
amount=5,
exptime=0.8,
size=1,
textures = {}
}
for i = 1,5,1 do
config.particles.textures[i] = "weather_hail" .. i .. ".png"
end
config.conditions = {
min_height = weather_mod.settings.min_height,
max_height = weather_mod.settings.max_height,
max_heat = 45,
min_humidity = 65,
min_windspeed = 2.5
}
weather_mod.register_effect(name, config)