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

@ -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 },
@ -21,4 +21,38 @@ local months = {
{ name = "October", days = 31 },
{ 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