Rename weather_pack mod to mcl_weather
This commit is contained in:
parent
37668eb1f9
commit
69ade14509
27 changed files with 240 additions and 240 deletions
47
mods/ENVIRONMENT/mcl_weather/README.md
Normal file
47
mods/ENVIRONMENT/mcl_weather/README.md
Normal file
|
@ -0,0 +1,47 @@
|
|||
`mcl_weather`
|
||||
=======================
|
||||
Weather mod for MineClone 2. Forked from `weather_pack`.
|
||||
|
||||
Weathers included
|
||||
-----------------------
|
||||
* rain
|
||||
* snow
|
||||
* thunder
|
||||
|
||||
Commands
|
||||
-----------------------
|
||||
`weather <weather>`, requires `weather_manager` privilege.
|
||||
|
||||
Dependencies
|
||||
-----------------------
|
||||
Thunder weather requres [lightning](https://github.com/minetest-mods/lightning) mod.
|
||||
|
||||
Configuration prope, ties
|
||||
-----------------------
|
||||
Weather mod for indoor check depends on sunlight propogation check. Some nodes (e.g. glass block) propogates sunlight and thus weather particles will go through it. To change that set `weather_allow_override_nodes=true` in `minetest.conf` file. Be aware that just few nodes will be override and these blocks needs to be re-builded to take effect. Maybe in future other 'cheap' way to check indoor will be available.
|
||||
|
||||
Weather mod mostly relies on particles generation however for some small things ABM may be used. Users which do not want it can disable ABM with property `weather_allow_abm=false`.
|
||||
|
||||
License of source code:
|
||||
-----------------------
|
||||
LGPL 2.1+
|
||||
|
||||
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
|
||||
|
||||
* `weather_pack_snow_snowflake1.png` - CC-BY-SA 3.0
|
||||
* `weather_pack_snow_snowflake2.png` - CC-BY-SA 3.0
|
||||
|
||||
xeranas:
|
||||
|
||||
* `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/):
|
||||
|
||||
* `weather_rain.ogg` - CC-BY-SA 3.0 (cut from http://freesound.org/people/inchadney/sounds/58835/)
|
||||
|
3
mods/ENVIRONMENT/mcl_weather/depends.txt
Normal file
3
mods/ENVIRONMENT/mcl_weather/depends.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
mcl_init
|
||||
mcl_util
|
||||
lightning?
|
1
mods/ENVIRONMENT/mcl_weather/description.txt
Normal file
1
mods/ENVIRONMENT/mcl_weather/description.txt
Normal file
|
@ -0,0 +1 @@
|
|||
Weather: Rain, snow, thunderstorm.
|
13
mods/ENVIRONMENT/mcl_weather/init.lua
Normal file
13
mods/ENVIRONMENT/mcl_weather/init.lua
Normal file
|
@ -0,0 +1,13 @@
|
|||
local modpath = minetest.get_modpath("mcl_weather");
|
||||
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 not located then embeded skycolor mod version will be loaded.
|
||||
if minetest.get_modpath("skycolor") == nil then
|
||||
dofile(modpath.."/skycolor.lua")
|
||||
end
|
1
mods/ENVIRONMENT/mcl_weather/mod.conf
Normal file
1
mods/ENVIRONMENT/mcl_weather/mod.conf
Normal file
|
@ -0,0 +1 @@
|
|||
name = mcl_weather
|
251
mods/ENVIRONMENT/mcl_weather/rain.lua
Normal file
251
mods/ENVIRONMENT/mcl_weather/rain.lua
Normal file
|
@ -0,0 +1,251 @@
|
|||
local PARTICLES_COUNT_RAIN = 30
|
||||
local PARTICLES_COUNT_THUNDER = 45
|
||||
|
||||
mcl_weather.rain = {
|
||||
-- max rain particles created at time
|
||||
particles_count = PARTICLES_COUNT_RAIN,
|
||||
|
||||
-- flag to turn on/off extinguish fire for rain
|
||||
extinguish_fire = true,
|
||||
|
||||
-- flag useful when mixing weathers
|
||||
raining = false,
|
||||
|
||||
-- keeping last timeofday value (rounded).
|
||||
-- Defaulted to non-existing value for initial comparing.
|
||||
sky_last_update = -1,
|
||||
|
||||
init_done = false,
|
||||
}
|
||||
|
||||
mcl_weather.rain.sound_handler = function(player)
|
||||
return minetest.sound_play("weather_rain", {
|
||||
object = player,
|
||||
max_hear_distance = 2,
|
||||
loop = true,
|
||||
})
|
||||
end
|
||||
|
||||
-- set skybox based on time (uses skycolor api)
|
||||
mcl_weather.rain.set_sky_box = function()
|
||||
if mcl_weather.state == "rain" then
|
||||
mcl_weather.skycolor.add_layer(
|
||||
"weather-pack-rain-sky",
|
||||
{{r=0, g=0, b=0},
|
||||
{r=85, g=86, b=98},
|
||||
{r=175, g=175, b=191},
|
||||
{r=85, g=86, b=98},
|
||||
{r=0, g=0, b=0}})
|
||||
mcl_weather.skycolor.active = true
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
player:set_clouds({color="#5D5D5FE8"})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- creating manually parctiles instead of particles spawner because of easier to control
|
||||
-- spawn position.
|
||||
mcl_weather.rain.add_rain_particles = function(player)
|
||||
|
||||
mcl_weather.rain.last_rp_count = 0
|
||||
for i=mcl_weather.rain.particles_count, 1,-1 do
|
||||
local random_pos_x, random_pos_y, random_pos_z = mcl_weather.get_random_pos_by_player_look_dir(player)
|
||||
if mcl_weather.is_outdoor({x=random_pos_x, y=random_pos_y, z=random_pos_z}) then
|
||||
mcl_weather.rain.last_rp_count = mcl_weather.rain.last_rp_count + 1
|
||||
minetest.add_particle({
|
||||
pos = {x=random_pos_x, y=random_pos_y, z=random_pos_z},
|
||||
velocity = {x=0, y=-10, z=0},
|
||||
acceleration = {x=0, y=-30, z=0},
|
||||
expirationtime = 0.2,
|
||||
size = math.random(0.5, 3),
|
||||
collisiondetection = true,
|
||||
collision_removal = true,
|
||||
vertical = true,
|
||||
texture = mcl_weather.rain.get_texture(),
|
||||
playername = player:get_player_name()
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Simple random texture getter
|
||||
mcl_weather.rain.get_texture = function()
|
||||
local texture_name
|
||||
local random_number = math.random()
|
||||
if random_number > 0.33 then
|
||||
texture_name = "weather_pack_rain_raindrop_1.png"
|
||||
elseif random_number > 0.66 then
|
||||
texture_name = "weather_pack_rain_raindrop_2.png"
|
||||
else
|
||||
texture_name = "weather_pack_rain_raindrop_3.png"
|
||||
end
|
||||
return texture_name;
|
||||
end
|
||||
|
||||
-- register player for rain weather.
|
||||
-- basically needs for origin sky reference and rain sound controls.
|
||||
mcl_weather.rain.add_player = function(player)
|
||||
if mcl_weather.players[player:get_player_name()] == nil then
|
||||
local player_meta = {}
|
||||
player_meta.origin_sky = {player:get_sky()}
|
||||
mcl_weather.players[player:get_player_name()] = player_meta
|
||||
end
|
||||
end
|
||||
|
||||
-- remove player from player list effected by rain.
|
||||
-- be sure to remove sound before removing player otherwise soundhandler reference will be lost.
|
||||
mcl_weather.rain.remove_player = function(player)
|
||||
local player_meta = mcl_weather.players[player:get_player_name()]
|
||||
if player_meta ~= nil and player_meta.origin_sky ~= nil then
|
||||
player:set_sky(player_meta.origin_sky[1], player_meta.origin_sky[2], player_meta.origin_sky[3], true)
|
||||
player:set_clouds({color="#FFF0F0E5"})
|
||||
mcl_weather.players[player:get_player_name()] = nil
|
||||
end
|
||||
end
|
||||
|
||||
-- adds and removes rain sound depending how much rain particles around player currently exist.
|
||||
-- have few seconds delay before each check to avoid on/off sound too often
|
||||
-- when player stay on 'edge' where sound should play and stop depending from random raindrop appearance.
|
||||
mcl_weather.rain.update_sound = function(player)
|
||||
local player_meta = mcl_weather.players[player:get_player_name()]
|
||||
if player_meta ~= nil then
|
||||
if player_meta.sound_updated ~= nil and player_meta.sound_updated + 5 > minetest.get_gametime() then
|
||||
return false
|
||||
end
|
||||
|
||||
if player_meta.sound_handler ~= nil then
|
||||
if mcl_weather.rain.last_rp_count == 0 then
|
||||
minetest.sound_stop(player_meta.sound_handler)
|
||||
player_meta.sound_handler = nil
|
||||
end
|
||||
elseif mcl_weather.rain.last_rp_count > 0 then
|
||||
player_meta.sound_handler = mcl_weather.rain.sound_handler(player)
|
||||
end
|
||||
|
||||
player_meta.sound_updated = minetest.get_gametime()
|
||||
end
|
||||
end
|
||||
|
||||
-- rain sound removed from player.
|
||||
mcl_weather.rain.remove_sound = function(player)
|
||||
local player_meta = mcl_weather.players[player:get_player_name()]
|
||||
if player_meta ~= nil and player_meta.sound_handler ~= nil then
|
||||
minetest.sound_stop(player_meta.sound_handler)
|
||||
player_meta.sound_handler = nil
|
||||
end
|
||||
end
|
||||
|
||||
-- callback function for removing rain
|
||||
mcl_weather.rain.clear = function()
|
||||
mcl_weather.rain.raining = false
|
||||
mcl_weather.rain.sky_last_update = -1
|
||||
mcl_weather.rain.init_done = false
|
||||
mcl_weather.rain.set_particles_mode("rain")
|
||||
mcl_weather.skycolor.remove_layer("weather-pack-rain-sky")
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
mcl_weather.rain.remove_sound(player)
|
||||
mcl_weather.rain.remove_player(player)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
if mcl_weather.state ~= "rain" then
|
||||
return false
|
||||
end
|
||||
|
||||
mcl_weather.rain.make_weather()
|
||||
end)
|
||||
|
||||
mcl_weather.rain.make_weather = function()
|
||||
if mcl_weather.rain.init_done == false then
|
||||
mcl_weather.rain.raining = true
|
||||
mcl_weather.rain.set_sky_box()
|
||||
mcl_weather.rain.set_particles_mode(mcl_weather.mode)
|
||||
mcl_weather.rain.init_done = true
|
||||
end
|
||||
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
if (mcl_weather.is_underwater(player) or not mcl_util.has_weather(player:getpos())) then
|
||||
mcl_weather.rain.remove_sound(player)
|
||||
return false
|
||||
end
|
||||
mcl_weather.rain.add_player(player)
|
||||
mcl_weather.rain.add_rain_particles(player)
|
||||
mcl_weather.rain.update_sound(player)
|
||||
end
|
||||
end
|
||||
|
||||
-- Switch the number of raindrops: "thunder" for many raindrops, otherwise for normal raindrops
|
||||
mcl_weather.rain.set_particles_mode = function(mode)
|
||||
if mode == "thunder" then
|
||||
mcl_weather.rain.particles_count = PARTICLES_COUNT_THUNDER
|
||||
else
|
||||
mcl_weather.rain.particles_count = PARTICLES_COUNT_RAIN
|
||||
end
|
||||
end
|
||||
|
||||
if mcl_weather.allow_abm then
|
||||
-- ABM for extinguish fire
|
||||
minetest.register_abm({
|
||||
label = "Rain extinguishes fire",
|
||||
nodenames = {"mcl_fire:fire"},
|
||||
interval = 4.0,
|
||||
chance = 2,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
if mcl_weather.rain.raining and mcl_weather.rain.extinguish_fire then
|
||||
if mcl_weather.is_outdoor(pos) then
|
||||
minetest.remove_node(pos)
|
||||
minetest.sound_play("fire_extinguish_flame", {pos = pos, max_hear_distance = 16, gain = 0.15})
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
-- Slowly fill up cauldrons
|
||||
minetest.register_abm({
|
||||
label = "Rain fills cauldrons with water",
|
||||
nodenames = {"mcl_cauldrons:cauldron", "mcl_cauldrons:cauldron_1", "mcl_cauldrons:cauldron_2"},
|
||||
interval = 56.0,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
if mcl_weather.rain.raining and mcl_weather.is_outdoor(pos) then
|
||||
if node.name == "mcl_cauldrons:cauldron" then
|
||||
minetest.set_node(pos, {name="mcl_cauldrons:cauldron_1"})
|
||||
elseif node.name == "mcl_cauldrons:cauldron_1" then
|
||||
minetest.set_node(pos, {name="mcl_cauldrons:cauldron_2"})
|
||||
elseif node.name == "mcl_cauldrons:cauldron_2" then
|
||||
minetest.set_node(pos, {name="mcl_cauldrons:cauldron_3"})
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
-- Wetten the soil
|
||||
minetest.register_abm({
|
||||
label = "Rain hydrates farmland",
|
||||
nodenames = {"mcl_farming:soil"},
|
||||
interval = 22.0,
|
||||
chance = 3,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
if mcl_weather.rain.raining and mcl_weather.is_outdoor(pos) then
|
||||
if node.name == "mcl_farming:soil" then
|
||||
minetest.set_node(pos, {name="mcl_farming:soil_wet"})
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
if mcl_weather.reg_weathers.rain == nil then
|
||||
mcl_weather.reg_weathers.rain = {
|
||||
clear = mcl_weather.rain.clear,
|
||||
-- 10min - 20min
|
||||
min_duration = 600,
|
||||
max_duration = 1200,
|
||||
transitions = {
|
||||
[65] = "none",
|
||||
[70] = "snow",
|
||||
[100] = "thunder",
|
||||
}
|
||||
}
|
||||
end
|
BIN
mods/ENVIRONMENT/mcl_weather/screenshot.png
Normal file
BIN
mods/ENVIRONMENT/mcl_weather/screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
228
mods/ENVIRONMENT/mcl_weather/skycolor.lua
Normal file
228
mods/ENVIRONMENT/mcl_weather/skycolor.lua
Normal file
|
@ -0,0 +1,228 @@
|
|||
mcl_weather.skycolor = {
|
||||
-- Should be activated before do any effect.
|
||||
active = true,
|
||||
|
||||
-- To skip update interval
|
||||
force_update = true,
|
||||
|
||||
-- Update interval.
|
||||
update_interval = 15,
|
||||
|
||||
-- Main sky colors: starts from midnight to midnight.
|
||||
-- Please do not set directly. Use add_layer instead.
|
||||
colors = {},
|
||||
|
||||
-- min value which will be used in color gradient, usualy its first user given color in 'pure' color.
|
||||
min_val = 0,
|
||||
|
||||
-- number of colors while constructing gradient of user given colors
|
||||
max_val = 1000,
|
||||
|
||||
-- Enables smooth transition between existing sky color and target.
|
||||
smooth_transitions = true,
|
||||
|
||||
-- Transition between current sky color and new user given.
|
||||
transition_in_progress = false,
|
||||
|
||||
-- Transition colors are generated automaticly during initialization.
|
||||
transition_colors = {},
|
||||
|
||||
-- Time where transition between current color and user given will be done
|
||||
transition_time = 15,
|
||||
|
||||
-- Tracks how much time passed during transition
|
||||
transition_timer = 0,
|
||||
|
||||
-- Table for tracking layer order
|
||||
layer_names = {},
|
||||
|
||||
-- To layer to colors table
|
||||
add_layer = function(layer_name, layer_color, instant_update)
|
||||
mcl_weather.skycolor.colors[layer_name] = layer_color
|
||||
table.insert(mcl_weather.skycolor.layer_names, layer_name)
|
||||
if (instant_update ~= true) then
|
||||
mcl_weather.skycolor.init_transition()
|
||||
end
|
||||
mcl_weather.skycolor.force_update = true
|
||||
end,
|
||||
|
||||
-- Retrieve layer from colors table
|
||||
retrieve_layer = function()
|
||||
local last_layer = mcl_weather.skycolor.layer_names[#mcl_weather.skycolor.layer_names]
|
||||
return mcl_weather.skycolor.colors[last_layer]
|
||||
end,
|
||||
|
||||
-- Remove layer from colors table
|
||||
remove_layer = function(layer_name)
|
||||
for k, name in ipairs(mcl_weather.skycolor.layer_names) do
|
||||
if name == layer_name then
|
||||
table.remove(mcl_weather.skycolor.layer_names, k)
|
||||
mcl_weather.skycolor.force_update = true
|
||||
return
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
-- Update sky color. If players not specified update sky for all players.
|
||||
update_sky_color = function(players)
|
||||
local color = mcl_weather.skycolor.current_sky_layer_color()
|
||||
if (color == nil) then
|
||||
mcl_weather.skycolor.set_default_sky()
|
||||
return
|
||||
end
|
||||
|
||||
players = mcl_weather.skycolor.utils.get_players(players)
|
||||
for _, player in ipairs(players) do
|
||||
local pos = player:getpos()
|
||||
local _, dim = mcl_util.y_to_layer(pos.y)
|
||||
if dim == "overworld" then
|
||||
player:set_sky(color, "plain", nil, true)
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
-- Returns current layer color in {r, g, b} format
|
||||
current_sky_layer_color = function()
|
||||
if #mcl_weather.skycolor.layer_names == 0 then
|
||||
return nil
|
||||
end
|
||||
|
||||
-- min timeofday value 0; max timeofday value 1. So sky color gradient range will be between 0 and 1 * mcl_weather.skycolor.max_val.
|
||||
local timeofday = minetest.get_timeofday()
|
||||
local rounded_time = math.floor(timeofday * mcl_weather.skycolor.max_val)
|
||||
local color = mcl_weather.skycolor.utils.convert_to_rgb(mcl_weather.skycolor.min_val, mcl_weather.skycolor.max_val, rounded_time, mcl_weather.skycolor.retrieve_layer())
|
||||
return color
|
||||
end,
|
||||
|
||||
-- Initialy used only on
|
||||
update_transition_sky_color = function()
|
||||
if #mcl_weather.skycolor.layer_names == 0 then
|
||||
mcl_weather.skycolor.set_default_sky()
|
||||
return
|
||||
end
|
||||
|
||||
local multiplier = 100
|
||||
local rounded_time = math.floor(mcl_weather.skycolor.transition_timer * multiplier)
|
||||
if rounded_time >= mcl_weather.skycolor.transition_time * multiplier then
|
||||
mcl_weather.skycolor.stop_transition()
|
||||
return
|
||||
end
|
||||
|
||||
local color = mcl_weather.skycolor.utils.convert_to_rgb(0, mcl_weather.skycolor.transition_time * multiplier, rounded_time, mcl_weather.skycolor.transition_colors)
|
||||
|
||||
local players = mcl_weather.skycolor.utils.get_players(nil)
|
||||
for _, player in ipairs(players) do
|
||||
local pos = player:getpos()
|
||||
local _, dim = mcl_util.y_to_layer(pos.y)
|
||||
if dim == "overworld" then
|
||||
player:set_sky(color, "plain", nil, true)
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
-- Reset sky color to game default. If players not specified update sky for all players.
|
||||
-- Could be sometimes useful but not recomended to use in general case as there may be other color layers
|
||||
-- which needs to preserve.
|
||||
set_default_sky = function(players)
|
||||
local players = mcl_weather.skycolor.utils.get_players(players)
|
||||
for _, player in ipairs(players) do
|
||||
local pos = player:getpos()
|
||||
local _, dim = mcl_util.y_to_layer(pos.y)
|
||||
if dim == "overworld" then
|
||||
player:set_sky(nil, "regular", nil, true)
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
init_transition = function()
|
||||
-- sadly default sky returns unpredictible colors so transition mode becomes usable only for user defined color layers
|
||||
-- Here '2' means that one color layer existed before new added and transition is posible.
|
||||
if #mcl_weather.skycolor.layer_names < 2 then
|
||||
return
|
||||
end
|
||||
|
||||
local transition_start_color = mcl_weather.skycolor.utils.get_current_bg_color()
|
||||
if (transition_start_color == nil) then
|
||||
return
|
||||
end
|
||||
local transition_end_color = mcl_weather.skycolor.current_sky_layer_color()
|
||||
mcl_weather.skycolor.transition_colors = {transition_start_color, transition_end_color}
|
||||
mcl_weather.skycolor.transition_in_progress = true
|
||||
end,
|
||||
|
||||
stop_transition = function()
|
||||
mcl_weather.skycolor.transition_in_progress = false
|
||||
mcl_weather.skycolor.transition_colors = {}
|
||||
mcl_weather.skycolor.transition_timer = 0
|
||||
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,
|
||||
|
||||
-- Simply getter. Ether returns user given players list or get all connected players if none provided
|
||||
get_players = function(players)
|
||||
if players == nil or #players == 0 then
|
||||
players = minetest.get_connected_players()
|
||||
end
|
||||
return players
|
||||
end,
|
||||
|
||||
-- Returns first player sky color. I assume that all players are in same color layout.
|
||||
get_current_bg_color = function()
|
||||
local players = mcl_weather.skycolor.utils.get_players(nil)
|
||||
for _, player in ipairs(players) do
|
||||
return player:get_sky()
|
||||
end
|
||||
return nil
|
||||
end
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
local timer = 0
|
||||
minetest.register_globalstep(function(dtime)
|
||||
if mcl_weather.skycolor.active ~= true or #minetest.get_connected_players() == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
if mcl_weather.skycolor.smooth_transitions and mcl_weather.skycolor.transition_in_progress then
|
||||
mcl_weather.skycolor.transition_timer = mcl_weather.skycolor.transition_timer + dtime
|
||||
mcl_weather.skycolor.update_transition_sky_color()
|
||||
return
|
||||
end
|
||||
|
||||
if mcl_weather.skycolor.force_update then
|
||||
mcl_weather.skycolor.update_sky_color()
|
||||
mcl_weather.skycolor.force_update = false
|
||||
return
|
||||
end
|
||||
|
||||
-- regular updates based on iterval
|
||||
timer = timer + dtime;
|
||||
if timer >= mcl_weather.skycolor.update_interval then
|
||||
mcl_weather.skycolor.update_sky_color()
|
||||
timer = 0
|
||||
end
|
||||
|
||||
end)
|
||||
|
||||
local initsky = function(player)
|
||||
if (mcl_weather.skycolor.active) then
|
||||
mcl_weather.skycolor.force_update = true
|
||||
end
|
||||
|
||||
-- MC-style clouds: Layer 127, thickness 4, fly to the “West”
|
||||
player:set_clouds({height=mcl_util.layer_to_y(127), speed={x=-2, y=0}, thickness=4, color="#FFF0FEF"})
|
||||
end
|
||||
|
||||
minetest.register_on_joinplayer(initsky)
|
||||
minetest.register_on_respawnplayer(initsky)
|
97
mods/ENVIRONMENT/mcl_weather/snow.lua
Normal file
97
mods/ENVIRONMENT/mcl_weather/snow.lua
Normal file
|
@ -0,0 +1,97 @@
|
|||
mcl_weather.snow = {}
|
||||
|
||||
mcl_weather.snow.particles_count = 15
|
||||
mcl_weather.snow.init_done = false
|
||||
|
||||
-- calculates coordinates and draw particles for snow weather
|
||||
mcl_weather.snow.add_snow_particles = function(player)
|
||||
mcl_weather.rain.last_rp_count = 0
|
||||
for i=mcl_weather.snow.particles_count, 1,-1 do
|
||||
local random_pos_x, random_pos_y, random_pos_z = mcl_weather.get_random_pos_by_player_look_dir(player)
|
||||
random_pos_y = math.random() + math.random(player:getpos().y - 1, player:getpos().y + 7)
|
||||
if minetest.get_node_light({x=random_pos_x, y=random_pos_y, z=random_pos_z}, 0.5) == 15 then
|
||||
mcl_weather.rain.last_rp_count = mcl_weather.rain.last_rp_count + 1
|
||||
minetest.add_particle({
|
||||
pos = {x=random_pos_x, y=random_pos_y, z=random_pos_z},
|
||||
velocity = {x = math.random(-1,-0.5), y = math.random(-2,-1), z = math.random(-1,-0.5)},
|
||||
acceleration = {x = math.random(-1,-0.5), y=-0.5, z = math.random(-1,-0.5)},
|
||||
expirationtime = 2.0,
|
||||
size = math.random(0.5, 2),
|
||||
collisiondetection = true,
|
||||
collision_removal = true,
|
||||
vertical = true,
|
||||
texture = mcl_weather.snow.get_texture(),
|
||||
playername = player:get_player_name()
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
mcl_weather.snow.set_sky_box = function()
|
||||
mcl_weather.skycolor.add_layer(
|
||||
"weather-pack-snow-sky",
|
||||
{{r=0, g=0, b=0},
|
||||
{r=241, g=244, b=249},
|
||||
{r=0, g=0, b=0}}
|
||||
)
|
||||
mcl_weather.skycolor.active = true
|
||||
end
|
||||
|
||||
mcl_weather.snow.clear = function()
|
||||
mcl_weather.skycolor.remove_layer("weather-pack-snow-sky")
|
||||
mcl_weather.snow.init_done = false
|
||||
end
|
||||
|
||||
-- Simple random texture getter
|
||||
mcl_weather.snow.get_texture = function()
|
||||
local texture_name
|
||||
local random_number = math.random()
|
||||
if random_number > 0.5 then
|
||||
texture_name = "weather_pack_snow_snowflake1.png"
|
||||
else
|
||||
texture_name = "weather_pack_snow_snowflake2.png"
|
||||
end
|
||||
return texture_name;
|
||||
end
|
||||
|
||||
local timer = 0
|
||||
minetest.register_globalstep(function(dtime)
|
||||
if mcl_weather.state ~= "snow" then
|
||||
return false
|
||||
end
|
||||
|
||||
timer = timer + dtime;
|
||||
if timer >= 0.5 then
|
||||
timer = 0
|
||||
else
|
||||
return
|
||||
end
|
||||
|
||||
if mcl_weather.snow.init_done == false then
|
||||
mcl_weather.snow.set_sky_box()
|
||||
mcl_weather.snow.init_done = true
|
||||
end
|
||||
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
if (mcl_weather.is_underwater(player) or not mcl_util.has_weather(player:getpos())) then
|
||||
return false
|
||||
end
|
||||
mcl_weather.snow.add_snow_particles(player)
|
||||
end
|
||||
end)
|
||||
|
||||
-- register snow weather
|
||||
if mcl_weather.reg_weathers.snow == nil then
|
||||
mcl_weather.reg_weathers.snow = {
|
||||
clear = mcl_weather.snow.clear,
|
||||
-- 10min - 20min
|
||||
min_duration = 600,
|
||||
max_duration = 1200,
|
||||
transitions = {
|
||||
[65] = "none",
|
||||
[80] = "rain",
|
||||
[100] = "thunder",
|
||||
}
|
||||
}
|
||||
end
|
||||
|
BIN
mods/ENVIRONMENT/mcl_weather/sounds/weather_rain.ogg
Normal file
BIN
mods/ENVIRONMENT/mcl_weather/sounds/weather_rain.ogg
Normal file
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 296 B |
Binary file not shown.
After Width: | Height: | Size: 209 B |
Binary file not shown.
After Width: | Height: | Size: 220 B |
Binary file not shown.
After Width: | Height: | Size: 192 B |
Binary file not shown.
After Width: | Height: | Size: 195 B |
60
mods/ENVIRONMENT/mcl_weather/thunder.lua
Normal file
60
mods/ENVIRONMENT/mcl_weather/thunder.lua
Normal file
|
@ -0,0 +1,60 @@
|
|||
-- turn off lightning mod 'auto mode'
|
||||
lightning.auto = false
|
||||
|
||||
mcl_weather.thunder = {
|
||||
next_strike = 0,
|
||||
min_delay = 3,
|
||||
max_delay = 12,
|
||||
init_done = false,
|
||||
}
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
if mcl_weather.get_weather() ~= "thunder" then
|
||||
return false
|
||||
end
|
||||
|
||||
mcl_weather.rain.set_particles_mode("thunder")
|
||||
mcl_weather.rain.make_weather()
|
||||
|
||||
if mcl_weather.thunder.init_done == false then
|
||||
mcl_weather.skycolor.add_layer(
|
||||
"weather-pack-thunder-sky",
|
||||
{{r=0, g=0, b=0},
|
||||
{r=40, g=40, b=40},
|
||||
{r=85, g=86, b=86},
|
||||
{r=40, g=40, b=40},
|
||||
{r=0, g=0, b=0}})
|
||||
mcl_weather.skycolor.active = true
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
player:set_clouds({color="#3D3D3FE8"})
|
||||
end
|
||||
mcl_weather.thunder.init_done = true
|
||||
end
|
||||
|
||||
if (mcl_weather.thunder.next_strike <= minetest.get_gametime()) then
|
||||
lightning.strike()
|
||||
local delay = math.random(mcl_weather.thunder.min_delay, mcl_weather.thunder.max_delay)
|
||||
mcl_weather.thunder.next_strike = minetest.get_gametime() + delay
|
||||
end
|
||||
|
||||
end)
|
||||
|
||||
mcl_weather.thunder.clear = function()
|
||||
mcl_weather.rain.clear()
|
||||
mcl_weather.skycolor.remove_layer("weather-pack-thunder-sky")
|
||||
mcl_weather.skycolor.remove_layer("lightning")
|
||||
mcl_weather.thunder.init_done = false
|
||||
end
|
||||
|
||||
-- register thunderstorm weather
|
||||
if mcl_weather.reg_weathers.thunder == nil then
|
||||
mcl_weather.reg_weathers.thunder = {
|
||||
clear = mcl_weather.thunder.clear,
|
||||
-- 10min - 20min
|
||||
min_duration = 600,
|
||||
max_duration = 1200,
|
||||
transitions = {
|
||||
[100] = "rain",
|
||||
}
|
||||
}
|
||||
end
|
210
mods/ENVIRONMENT/mcl_weather/weather_core.lua
Normal file
210
mods/ENVIRONMENT/mcl_weather/weather_core.lua
Normal file
|
@ -0,0 +1,210 @@
|
|||
mcl_weather = {
|
||||
-- weather states, 'none' is default, other states depends from active mods
|
||||
state = "none",
|
||||
|
||||
-- player list for saving player meta info
|
||||
players = {},
|
||||
|
||||
-- default weather recalculation interval
|
||||
check_interval = 300,
|
||||
|
||||
-- weather min duration
|
||||
min_duration = 600,
|
||||
|
||||
-- weather max duration
|
||||
max_duration = 9000,
|
||||
|
||||
-- weather calculated end time
|
||||
end_time = nil,
|
||||
|
||||
-- registered weathers
|
||||
reg_weathers = {},
|
||||
|
||||
-- automaticly calculates intervals and swap weathers
|
||||
auto_mode = true,
|
||||
|
||||
-- global flag to disable/enable ABM logic.
|
||||
allow_abm = true,
|
||||
}
|
||||
|
||||
mcl_weather.reg_weathers["none"] = {
|
||||
min_duration = mcl_weather.min_duration,
|
||||
max_duration = mcl_weather.max_duration,
|
||||
transitions = {
|
||||
[50] = "rain",
|
||||
[100] = "snow",
|
||||
},
|
||||
clear = function() end,
|
||||
}
|
||||
|
||||
mcl_weather.get_rand_end_time = function(min_duration, max_duration)
|
||||
local r
|
||||
if min_duration ~= nil and max_duration ~= nil then
|
||||
r = math.random(min_duration, max_duration);
|
||||
else
|
||||
r = math.random(mcl_weather.min_duration, mcl_weather.max_duration);
|
||||
end
|
||||
return minetest.get_gametime() + r
|
||||
end
|
||||
|
||||
-- Returns true if pos is outdoor.
|
||||
-- Outdoor is defined as any node in the Overworld under open sky.
|
||||
-- FIXME: Nodes below glass also count as “outdoor”, this should not be the case.
|
||||
mcl_weather.is_outdoor = function(pos)
|
||||
local cpos = {x=pos.x, y=pos.y+1, z=pos.z}
|
||||
local _, dim = mcl_util.y_to_layer(cpos.y)
|
||||
if minetest.get_node_light(cpos, 0.5) == 15 and dim == "overworld" then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- checks if player is undewater. This is needed in order to
|
||||
-- turn off weather particles generation.
|
||||
mcl_weather.is_underwater = function(player)
|
||||
local ppos = player:getpos()
|
||||
local offset = player:get_eye_offset()
|
||||
local player_eye_pos = {x = ppos.x + offset.x,
|
||||
y = ppos.y + offset.y + 1.5,
|
||||
z = ppos.z + offset.z}
|
||||
local node_level = minetest.get_node_level(player_eye_pos)
|
||||
if node_level == 8 or node_level == 7 then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- trying to locate position for particles by player look direction for performance reason.
|
||||
-- it is costly to generate many particles around player so goal is focus mainly on front view.
|
||||
mcl_weather.get_random_pos_by_player_look_dir = function(player)
|
||||
local look_dir = player:get_look_dir()
|
||||
local player_pos = player:getpos()
|
||||
|
||||
local random_pos_x = 0
|
||||
local random_pos_y = 0
|
||||
local random_pos_z = 0
|
||||
|
||||
if look_dir.x > 0 then
|
||||
if look_dir.z > 0 then
|
||||
random_pos_x = math.random() + math.random(player_pos.x - 2.5, player_pos.x + 5)
|
||||
random_pos_z = math.random() + math.random(player_pos.z - 2.5, player_pos.z + 5)
|
||||
else
|
||||
random_pos_x = math.random() + math.random(player_pos.x - 2.5, player_pos.x + 5)
|
||||
random_pos_z = math.random() + math.random(player_pos.z - 5, player_pos.z + 2.5)
|
||||
end
|
||||
else
|
||||
if look_dir.z > 0 then
|
||||
random_pos_x = math.random() + math.random(player_pos.x - 5, player_pos.x + 2.5)
|
||||
random_pos_z = math.random() + math.random(player_pos.z - 2.5, player_pos.z + 5)
|
||||
else
|
||||
random_pos_x = math.random() + math.random(player_pos.x - 5, player_pos.x + 2.5)
|
||||
random_pos_z = math.random() + math.random(player_pos.z - 5, player_pos.z + 2.5)
|
||||
end
|
||||
end
|
||||
|
||||
random_pos_y = math.random() + math.random(player_pos.y + 1, player_pos.y + 3)
|
||||
return random_pos_x, random_pos_y, random_pos_z
|
||||
end
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
if mcl_weather.auto_mode == false then
|
||||
return 0
|
||||
end
|
||||
|
||||
if mcl_weather.end_time == nil then
|
||||
mcl_weather.end_time = mcl_weather.get_rand_end_time()
|
||||
end
|
||||
-- recalculate weather
|
||||
if mcl_weather.end_time <= minetest.get_gametime() then
|
||||
mcl_weather.set_random_weather(mcl_weather.state, mcl_weather.reg_weathers[mcl_weather.state])
|
||||
end
|
||||
end)
|
||||
|
||||
-- Sets random weather (which could be 'none' (no weather)).
|
||||
mcl_weather.set_random_weather = function(weather_name, weather_meta)
|
||||
if (weather_meta ~= nil) then
|
||||
local transitions = weather_meta.transitions
|
||||
local random_roll = math.random(0,100)
|
||||
local new_weather
|
||||
for v, weather in pairs(transitions) do
|
||||
if random_roll < v then
|
||||
new_weather = weather
|
||||
break
|
||||
end
|
||||
end
|
||||
if new_weather then
|
||||
mcl_weather.change_weather(new_weather)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
mcl_weather.change_weather = function(new_weather)
|
||||
if (mcl_weather.reg_weathers ~= nil and mcl_weather.reg_weathers[new_weather] ~= nil) then
|
||||
if (mcl_weather.state ~= nil and mcl_weather.reg_weathers[mcl_weather.state] ~= nil) then
|
||||
mcl_weather.reg_weathers[mcl_weather.state].clear()
|
||||
end
|
||||
mcl_weather.state = new_weather
|
||||
local weather_meta = mcl_weather.reg_weathers[mcl_weather.state]
|
||||
mcl_weather.end_time = mcl_weather.get_rand_end_time(weather_meta.min_duration, weather_meta.max_duration)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
mcl_weather.get_weather = function()
|
||||
return mcl_weather.state
|
||||
end
|
||||
|
||||
minetest.register_privilege("weather_manager", {
|
||||
description = "Gives ability to control weather",
|
||||
give_to_singleplayer = false
|
||||
})
|
||||
|
||||
-- Weather command definition. Set
|
||||
minetest.register_chatcommand("weather", {
|
||||
params = "clear | rain | snow | thunder",
|
||||
description = "Changes the weather to the specified parameter.",
|
||||
privs = {weather_manager = true},
|
||||
func = function(name, param)
|
||||
if (param == "") then
|
||||
return false, "Error: No weather specified."
|
||||
end
|
||||
local new_weather
|
||||
if param == "clear" then
|
||||
new_weather = "none"
|
||||
else
|
||||
new_weather = param
|
||||
end
|
||||
local success = mcl_weather.change_weather(new_weather)
|
||||
if success then
|
||||
return true
|
||||
else
|
||||
return false, "Error: Invalid weather specified. Use “clear”, “rain”, “snow” or “thunder”."
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("toggledownfall", {
|
||||
params = "",
|
||||
description = "Toggles between clear weather and weather with downfall (randomly rain, thunderstorm or snow)",
|
||||
privs = {weather_manager = true},
|
||||
func = function(name, param)
|
||||
-- Currently rain/thunder/snow: Set weather to clear
|
||||
if mcl_weather.state ~= "none" then
|
||||
return mcl_weather.change_weather("none")
|
||||
|
||||
-- Currently clear: Set weather randomly to rain/thunder/snow
|
||||
else
|
||||
local new = { "rain", "thunder", "snow" }
|
||||
local r = math.random(1, #new)
|
||||
return mcl_weather.change_weather(new[r])
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
-- Configuration setting which allows user to disable ABM for weathers (if they use it).
|
||||
-- Weather mods expected to be use this flag before registering ABM.
|
||||
local weather_allow_abm = minetest.settings:get_bool("weather_allow_abm")
|
||||
if weather_allow_abm ~= nil and weather_allow_abm == false then
|
||||
mcl_weather.allow_abm = false
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue