Rename weather_pack mod to mcl_weather
@ -34,7 +34,7 @@ local revertsky = function(dtime)
|
||||
return
|
||||
end
|
||||
|
||||
skycolor.remove_layer("lightning")
|
||||
mcl_weather.skycolor.remove_layer("lightning")
|
||||
|
||||
ps = {}
|
||||
end
|
||||
@ -136,8 +136,8 @@ lightning.strike = function(pos)
|
||||
local name = player:get_player_name()
|
||||
if ps[name] == nil then
|
||||
ps[name] = {p = player, sky = sky}
|
||||
skycolor.add_layer("lightning", {{r=255,g=255,b=255}}, true)
|
||||
skycolor.active = true
|
||||
mcl_weather.skycolor.add_layer("lightning", {{r=255,g=255,b=255}}, true)
|
||||
mcl_weather.skycolor.active = true
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
weather-pack
|
||||
`mcl_weather`
|
||||
=======================
|
||||
Weather mod for Minetest (http://minetest.net/)
|
||||
Weather mod for MineClone 2. Forked from `weather_pack`.
|
||||
|
||||
Weathers included
|
||||
-----------------------
|
||||
@ -10,13 +10,13 @@ Weathers included
|
||||
|
||||
Commands
|
||||
-----------------------
|
||||
`set_weather <weather>` requires `weather_manager` privilege.
|
||||
`weather <weather>`, requires `weather_manager` privilege.
|
||||
|
||||
Dependencies
|
||||
-----------------------
|
||||
Thunder weather requres [lightning](https://github.com/minetest-mods/lightning) mod.
|
||||
|
||||
Configuration properties
|
||||
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.
|
||||
|
1
mods/ENVIRONMENT/mcl_weather/description.txt
Normal file
@ -0,0 +1 @@
|
||||
Weather: Rain, snow, thunderstorm.
|
@ -1,4 +1,4 @@
|
||||
local modpath = minetest.get_modpath("weather_pack");
|
||||
local modpath = minetest.get_modpath("mcl_weather");
|
||||
dofile(modpath.."/weather_core.lua")
|
||||
dofile(modpath.."/snow.lua")
|
||||
dofile(modpath.."/rain.lua")
|
1
mods/ENVIRONMENT/mcl_weather/mod.conf
Normal file
@ -0,0 +1 @@
|
||||
name = mcl_weather
|
@ -1,7 +1,7 @@
|
||||
local PARTICLES_COUNT_RAIN = 30
|
||||
local PARTICLES_COUNT_THUNDER = 45
|
||||
|
||||
rain = {
|
||||
mcl_weather.rain = {
|
||||
-- max rain particles created at time
|
||||
particles_count = PARTICLES_COUNT_RAIN,
|
||||
|
||||
@ -18,7 +18,7 @@ rain = {
|
||||
init_done = false,
|
||||
}
|
||||
|
||||
rain.sound_handler = function(player)
|
||||
mcl_weather.rain.sound_handler = function(player)
|
||||
return minetest.sound_play("weather_rain", {
|
||||
object = player,
|
||||
max_hear_distance = 2,
|
||||
@ -27,16 +27,16 @@ rain.sound_handler = function(player)
|
||||
end
|
||||
|
||||
-- set skybox based on time (uses skycolor api)
|
||||
rain.set_sky_box = function()
|
||||
if weather.state == "rain" then
|
||||
skycolor.add_layer(
|
||||
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}})
|
||||
skycolor.active = true
|
||||
mcl_weather.skycolor.active = true
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
player:set_clouds({color="#5D5D5FE8"})
|
||||
end
|
||||
@ -45,13 +45,13 @@ end
|
||||
|
||||
-- creating manually parctiles instead of particles spawner because of easier to control
|
||||
-- spawn position.
|
||||
rain.add_rain_particles = function(player)
|
||||
mcl_weather.rain.add_rain_particles = function(player)
|
||||
|
||||
rain.last_rp_count = 0
|
||||
for i=rain.particles_count, 1,-1 do
|
||||
local random_pos_x, random_pos_y, random_pos_z = weather.get_random_pos_by_player_look_dir(player)
|
||||
if weather.is_outdoor({x=random_pos_x, y=random_pos_y, z=random_pos_z}) then
|
||||
rain.last_rp_count = rain.last_rp_count + 1
|
||||
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},
|
||||
@ -61,7 +61,7 @@ rain.add_rain_particles = function(player)
|
||||
collisiondetection = true,
|
||||
collision_removal = true,
|
||||
vertical = true,
|
||||
texture = rain.get_texture(),
|
||||
texture = mcl_weather.rain.get_texture(),
|
||||
playername = player:get_player_name()
|
||||
})
|
||||
end
|
||||
@ -69,7 +69,7 @@ rain.add_rain_particles = function(player)
|
||||
end
|
||||
|
||||
-- Simple random texture getter
|
||||
rain.get_texture = function()
|
||||
mcl_weather.rain.get_texture = function()
|
||||
local texture_name
|
||||
local random_number = math.random()
|
||||
if random_number > 0.33 then
|
||||
@ -84,42 +84,42 @@ end
|
||||
|
||||
-- register player for rain weather.
|
||||
-- basically needs for origin sky reference and rain sound controls.
|
||||
rain.add_player = function(player)
|
||||
if weather.players[player:get_player_name()] == nil then
|
||||
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()}
|
||||
weather.players[player:get_player_name()] = player_meta
|
||||
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.
|
||||
rain.remove_player = function(player)
|
||||
local player_meta = weather.players[player:get_player_name()]
|
||||
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"})
|
||||
weather.players[player:get_player_name()] = nil
|
||||
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.
|
||||
rain.update_sound = function(player)
|
||||
local player_meta = weather.players[player:get_player_name()]
|
||||
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 rain.last_rp_count == 0 then
|
||||
if mcl_weather.rain.last_rp_count == 0 then
|
||||
minetest.sound_stop(player_meta.sound_handler)
|
||||
player_meta.sound_handler = nil
|
||||
end
|
||||
elseif rain.last_rp_count > 0 then
|
||||
player_meta.sound_handler = rain.sound_handler(player)
|
||||
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()
|
||||
@ -127,8 +127,8 @@ rain.update_sound = function(player)
|
||||
end
|
||||
|
||||
-- rain sound removed from player.
|
||||
rain.remove_sound = function(player)
|
||||
local player_meta = weather.players[player:get_player_name()]
|
||||
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
|
||||
@ -136,55 +136,55 @@ rain.remove_sound = function(player)
|
||||
end
|
||||
|
||||
-- callback function for removing rain
|
||||
rain.clear = function()
|
||||
rain.raining = false
|
||||
rain.sky_last_update = -1
|
||||
rain.init_done = false
|
||||
rain.set_particles_mode("rain")
|
||||
skycolor.remove_layer("weather-pack-rain-sky")
|
||||
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
|
||||
rain.remove_sound(player)
|
||||
rain.remove_player(player)
|
||||
mcl_weather.rain.remove_sound(player)
|
||||
mcl_weather.rain.remove_player(player)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
if weather.state ~= "rain" then
|
||||
if mcl_weather.state ~= "rain" then
|
||||
return false
|
||||
end
|
||||
|
||||
rain.make_weather()
|
||||
mcl_weather.rain.make_weather()
|
||||
end)
|
||||
|
||||
rain.make_weather = function()
|
||||
if rain.init_done == false then
|
||||
rain.raining = true
|
||||
rain.set_sky_box()
|
||||
rain.set_particles_mode(weather.mode)
|
||||
rain.init_done = true
|
||||
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 (weather.is_underwater(player) or not mcl_util.has_weather(player:getpos())) then
|
||||
rain.remove_sound(player)
|
||||
if (mcl_weather.is_underwater(player) or not mcl_util.has_weather(player:getpos())) then
|
||||
mcl_weather.rain.remove_sound(player)
|
||||
return false
|
||||
end
|
||||
rain.add_player(player)
|
||||
rain.add_rain_particles(player)
|
||||
rain.update_sound(player)
|
||||
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
|
||||
rain.set_particles_mode = function(mode)
|
||||
mcl_weather.rain.set_particles_mode = function(mode)
|
||||
if mode == "thunder" then
|
||||
rain.particles_count = PARTICLES_COUNT_THUNDER
|
||||
mcl_weather.rain.particles_count = PARTICLES_COUNT_THUNDER
|
||||
else
|
||||
rain.particles_count = PARTICLES_COUNT_RAIN
|
||||
mcl_weather.rain.particles_count = PARTICLES_COUNT_RAIN
|
||||
end
|
||||
end
|
||||
|
||||
if weather.allow_abm then
|
||||
if mcl_weather.allow_abm then
|
||||
-- ABM for extinguish fire
|
||||
minetest.register_abm({
|
||||
label = "Rain extinguishes fire",
|
||||
@ -192,8 +192,8 @@ if weather.allow_abm then
|
||||
interval = 4.0,
|
||||
chance = 2,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
if rain.raining and rain.extinguish_fire then
|
||||
if weather.is_outdoor(pos) then
|
||||
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
|
||||
@ -208,7 +208,7 @@ if weather.allow_abm then
|
||||
interval = 56.0,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
if rain.raining and weather.is_outdoor(pos) then
|
||||
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
|
||||
@ -227,7 +227,7 @@ if weather.allow_abm then
|
||||
interval = 22.0,
|
||||
chance = 3,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
if rain.raining and weather.is_outdoor(pos) then
|
||||
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
|
||||
@ -236,9 +236,9 @@ if weather.allow_abm then
|
||||
})
|
||||
end
|
||||
|
||||
if weather.reg_weathers.rain == nil then
|
||||
weather.reg_weathers.rain = {
|
||||
clear = rain.clear,
|
||||
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,
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
@ -1,4 +1,4 @@
|
||||
skycolor = {
|
||||
mcl_weather.skycolor = {
|
||||
-- Should be activated before do any effect.
|
||||
active = true,
|
||||
|
||||
@ -38,26 +38,26 @@ skycolor = {
|
||||
|
||||
-- To layer to colors table
|
||||
add_layer = function(layer_name, layer_color, instant_update)
|
||||
skycolor.colors[layer_name] = layer_color
|
||||
table.insert(skycolor.layer_names, layer_name)
|
||||
mcl_weather.skycolor.colors[layer_name] = layer_color
|
||||
table.insert(mcl_weather.skycolor.layer_names, layer_name)
|
||||
if (instant_update ~= true) then
|
||||
skycolor.init_transition()
|
||||
mcl_weather.skycolor.init_transition()
|
||||
end
|
||||
skycolor.force_update = true
|
||||
mcl_weather.skycolor.force_update = true
|
||||
end,
|
||||
|
||||
-- Retrieve layer from colors table
|
||||
retrieve_layer = function()
|
||||
local last_layer = skycolor.layer_names[#skycolor.layer_names]
|
||||
return skycolor.colors[last_layer]
|
||||
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(skycolor.layer_names) do
|
||||
for k, name in ipairs(mcl_weather.skycolor.layer_names) do
|
||||
if name == layer_name then
|
||||
table.remove(skycolor.layer_names, k)
|
||||
skycolor.force_update = true
|
||||
table.remove(mcl_weather.skycolor.layer_names, k)
|
||||
mcl_weather.skycolor.force_update = true
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -65,13 +65,13 @@ skycolor = {
|
||||
|
||||
-- Update sky color. If players not specified update sky for all players.
|
||||
update_sky_color = function(players)
|
||||
local color = skycolor.current_sky_layer_color()
|
||||
local color = mcl_weather.skycolor.current_sky_layer_color()
|
||||
if (color == nil) then
|
||||
skycolor.set_default_sky()
|
||||
mcl_weather.skycolor.set_default_sky()
|
||||
return
|
||||
end
|
||||
|
||||
players = skycolor.utils.get_players(players)
|
||||
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)
|
||||
@ -83,34 +83,34 @@ skycolor = {
|
||||
|
||||
-- Returns current layer color in {r, g, b} format
|
||||
current_sky_layer_color = function()
|
||||
if #skycolor.layer_names == 0 then
|
||||
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 * skycolor.max_value.
|
||||
-- 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 * skycolor.max_val)
|
||||
local color = skycolor.utils.convert_to_rgb(skycolor.min_val, skycolor.max_val, rounded_time, skycolor.retrieve_layer())
|
||||
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 #skycolor.layer_names == 0 then
|
||||
skycolor.set_default_sky()
|
||||
if #mcl_weather.skycolor.layer_names == 0 then
|
||||
mcl_weather.skycolor.set_default_sky()
|
||||
return
|
||||
end
|
||||
|
||||
local multiplier = 100
|
||||
local rounded_time = math.floor(skycolor.transition_timer * multiplier)
|
||||
if rounded_time >= skycolor.transition_time * multiplier then
|
||||
skycolor.stop_transition()
|
||||
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 = skycolor.utils.convert_to_rgb(0, skycolor.transition_time * multiplier, rounded_time, skycolor.transition_colors)
|
||||
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 = skycolor.utils.get_players(nil)
|
||||
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)
|
||||
@ -124,7 +124,7 @@ skycolor = {
|
||||
-- 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 = skycolor.utils.get_players(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)
|
||||
@ -137,23 +137,23 @@ skycolor = {
|
||||
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 #skycolor.layer_names < 2 then
|
||||
if #mcl_weather.skycolor.layer_names < 2 then
|
||||
return
|
||||
end
|
||||
|
||||
local transition_start_color = skycolor.utils.get_current_bg_color()
|
||||
local transition_start_color = mcl_weather.skycolor.utils.get_current_bg_color()
|
||||
if (transition_start_color == nil) then
|
||||
return
|
||||
end
|
||||
local transition_end_color = skycolor.current_sky_layer_color()
|
||||
skycolor.transition_colors = {transition_start_color, transition_end_color}
|
||||
skycolor.transition_in_progress = true
|
||||
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()
|
||||
skycolor.transition_in_progress = false
|
||||
skycolor.transition_colors = {}
|
||||
skycolor.transition_timer = 0
|
||||
mcl_weather.skycolor.transition_in_progress = false
|
||||
mcl_weather.skycolor.transition_colors = {}
|
||||
mcl_weather.skycolor.transition_timer = 0
|
||||
end,
|
||||
|
||||
utils = {
|
||||
@ -178,7 +178,7 @@ skycolor = {
|
||||
|
||||
-- Returns first player sky color. I assume that all players are in same color layout.
|
||||
get_current_bg_color = function()
|
||||
local players = skycolor.utils.get_players(nil)
|
||||
local players = mcl_weather.skycolor.utils.get_players(nil)
|
||||
for _, player in ipairs(players) do
|
||||
return player:get_sky()
|
||||
end
|
||||
@ -190,34 +190,34 @@ skycolor = {
|
||||
|
||||
local timer = 0
|
||||
minetest.register_globalstep(function(dtime)
|
||||
if skycolor.active ~= true or #minetest.get_connected_players() == 0 then
|
||||
if mcl_weather.skycolor.active ~= true or #minetest.get_connected_players() == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
if skycolor.smooth_transitions and skycolor.transition_in_progress then
|
||||
skycolor.transition_timer = skycolor.transition_timer + dtime
|
||||
skycolor.update_transition_sky_color()
|
||||
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 skycolor.force_update then
|
||||
skycolor.update_sky_color()
|
||||
skycolor.force_update = false
|
||||
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 >= skycolor.update_interval then
|
||||
skycolor.update_sky_color()
|
||||
if timer >= mcl_weather.skycolor.update_interval then
|
||||
mcl_weather.skycolor.update_sky_color()
|
||||
timer = 0
|
||||
end
|
||||
|
||||
end)
|
||||
|
||||
local initsky = function(player)
|
||||
if (skycolor.active) then
|
||||
skycolor.force_update = true
|
||||
if (mcl_weather.skycolor.active) then
|
||||
mcl_weather.skycolor.force_update = true
|
||||
end
|
||||
|
||||
-- MC-style clouds: Layer 127, thickness 4, fly to the “West”
|
@ -1,16 +1,16 @@
|
||||
snow = {}
|
||||
mcl_weather.snow = {}
|
||||
|
||||
snow.particles_count = 15
|
||||
snow.init_done = false
|
||||
mcl_weather.snow.particles_count = 15
|
||||
mcl_weather.snow.init_done = false
|
||||
|
||||
-- calculates coordinates and draw particles for snow weather
|
||||
snow.add_rain_particles = function(player)
|
||||
rain.last_rp_count = 0
|
||||
for i=snow.particles_count, 1,-1 do
|
||||
local random_pos_x, random_pos_y, random_pos_z = weather.get_random_pos_by_player_look_dir(player)
|
||||
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
|
||||
rain.last_rp_count = rain.last_rp_count + 1
|
||||
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)},
|
||||
@ -20,30 +20,30 @@ snow.add_rain_particles = function(player)
|
||||
collisiondetection = true,
|
||||
collision_removal = true,
|
||||
vertical = true,
|
||||
texture = snow.get_texture(),
|
||||
texture = mcl_weather.snow.get_texture(),
|
||||
playername = player:get_player_name()
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
snow.set_sky_box = function()
|
||||
skycolor.add_layer(
|
||||
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}}
|
||||
)
|
||||
skycolor.active = true
|
||||
mcl_weather.skycolor.active = true
|
||||
end
|
||||
|
||||
snow.clear = function()
|
||||
skycolor.remove_layer("weather-pack-snow-sky")
|
||||
snow.init_done = false
|
||||
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
|
||||
snow.get_texture = function()
|
||||
mcl_weather.snow.get_texture = function()
|
||||
local texture_name
|
||||
local random_number = math.random()
|
||||
if random_number > 0.5 then
|
||||
@ -56,7 +56,7 @@ end
|
||||
|
||||
local timer = 0
|
||||
minetest.register_globalstep(function(dtime)
|
||||
if weather.state ~= "snow" then
|
||||
if mcl_weather.state ~= "snow" then
|
||||
return false
|
||||
end
|
||||
|
||||
@ -67,23 +67,23 @@ minetest.register_globalstep(function(dtime)
|
||||
return
|
||||
end
|
||||
|
||||
if snow.init_done == false then
|
||||
snow.set_sky_box()
|
||||
snow.init_done = true
|
||||
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 (weather.is_underwater(player) or not mcl_util.has_weather(player:getpos())) then
|
||||
if (mcl_weather.is_underwater(player) or not mcl_util.has_weather(player:getpos())) then
|
||||
return false
|
||||
end
|
||||
snow.add_rain_particles(player)
|
||||
mcl_weather.snow.add_snow_particles(player)
|
||||
end
|
||||
end)
|
||||
|
||||
-- register snow weather
|
||||
if weather.reg_weathers.snow == nil then
|
||||
weather.reg_weathers.snow = {
|
||||
clear = snow.clear,
|
||||
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,
|
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 |
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
|
@ -1,4 +1,4 @@
|
||||
weather = {
|
||||
mcl_weather = {
|
||||
-- weather states, 'none' is default, other states depends from active mods
|
||||
state = "none",
|
||||
|
||||
@ -27,9 +27,9 @@ weather = {
|
||||
allow_abm = true,
|
||||
}
|
||||
|
||||
weather.reg_weathers["none"] = {
|
||||
min_duration = weather.min_duration,
|
||||
max_duration = weather.max_duration,
|
||||
mcl_weather.reg_weathers["none"] = {
|
||||
min_duration = mcl_weather.min_duration,
|
||||
max_duration = mcl_weather.max_duration,
|
||||
transitions = {
|
||||
[50] = "rain",
|
||||
[100] = "snow",
|
||||
@ -37,12 +37,12 @@ weather.reg_weathers["none"] = {
|
||||
clear = function() end,
|
||||
}
|
||||
|
||||
weather.get_rand_end_time = function(min_duration, max_duration)
|
||||
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(weather.min_duration, weather.max_duration);
|
||||
r = math.random(mcl_weather.min_duration, mcl_weather.max_duration);
|
||||
end
|
||||
return minetest.get_gametime() + r
|
||||
end
|
||||
@ -50,7 +50,7 @@ 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.
|
||||
weather.is_outdoor = function(pos)
|
||||
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
|
||||
@ -61,7 +61,7 @@ end
|
||||
|
||||
-- checks if player is undewater. This is needed in order to
|
||||
-- turn off weather particles generation.
|
||||
weather.is_underwater = function(player)
|
||||
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,
|
||||
@ -76,7 +76,7 @@ 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.
|
||||
weather.get_random_pos_by_player_look_dir = function(player)
|
||||
mcl_weather.get_random_pos_by_player_look_dir = function(player)
|
||||
local look_dir = player:get_look_dir()
|
||||
local player_pos = player:getpos()
|
||||
|
||||
@ -107,21 +107,21 @@ weather.get_random_pos_by_player_look_dir = function(player)
|
||||
end
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
if weather.auto_mode == false then
|
||||
if mcl_weather.auto_mode == false then
|
||||
return 0
|
||||
end
|
||||
|
||||
if weather.end_time == nil then
|
||||
weather.end_time = weather.get_rand_end_time()
|
||||
if mcl_weather.end_time == nil then
|
||||
mcl_weather.end_time = mcl_weather.get_rand_end_time()
|
||||
end
|
||||
-- recalculate weather
|
||||
if weather.end_time <= minetest.get_gametime() then
|
||||
weather.set_random_weather(weather.state, weather.reg_weathers[weather.state])
|
||||
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)).
|
||||
weather.set_random_weather = function(weather_name, weather_meta)
|
||||
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)
|
||||
@ -133,26 +133,26 @@ weather.set_random_weather = function(weather_name, weather_meta)
|
||||
end
|
||||
end
|
||||
if new_weather then
|
||||
weather.change_weather(new_weather)
|
||||
mcl_weather.change_weather(new_weather)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
weather.change_weather = function(new_weather)
|
||||
if (weather.reg_weathers ~= nil and weather.reg_weathers[new_weather] ~= nil) then
|
||||
if (weather.state ~= nil and weather.reg_weathers[weather.state] ~= nil) then
|
||||
weather.reg_weathers[weather.state].clear()
|
||||
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
|
||||
weather.state = new_weather
|
||||
local weather_meta = weather.reg_weathers[weather.state]
|
||||
weather.end_time = weather.get_rand_end_time(weather_meta.min_duration, weather_meta.max_duration)
|
||||
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
|
||||
|
||||
weather.get_weather = function()
|
||||
return weather.state
|
||||
mcl_weather.get_weather = function()
|
||||
return mcl_weather.state
|
||||
end
|
||||
|
||||
minetest.register_privilege("weather_manager", {
|
||||
@ -175,7 +175,7 @@ minetest.register_chatcommand("weather", {
|
||||
else
|
||||
new_weather = param
|
||||
end
|
||||
local success = weather.change_weather(new_weather)
|
||||
local success = mcl_weather.change_weather(new_weather)
|
||||
if success then
|
||||
return true
|
||||
else
|
||||
@ -190,14 +190,14 @@ minetest.register_chatcommand("toggledownfall", {
|
||||
privs = {weather_manager = true},
|
||||
func = function(name, param)
|
||||
-- Currently rain/thunder/snow: Set weather to clear
|
||||
if weather.state ~= "none" then
|
||||
return weather.change_weather("none")
|
||||
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 weather.change_weather(new[r])
|
||||
return mcl_weather.change_weather(new[r])
|
||||
end
|
||||
end
|
||||
})
|
||||
@ -206,5 +206,5 @@ minetest.register_chatcommand("toggledownfall", {
|
||||
-- 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
|
||||
weather.allow_abm = false
|
||||
mcl_weather.allow_abm = false
|
||||
end
|
@ -1 +0,0 @@
|
||||
Set of weathers for minetest.
|
@ -1 +0,0 @@
|
||||
name = weather_pack
|
@ -1,60 +0,0 @@
|
||||
-- turn off lightning mod 'auto mode'
|
||||
lightning.auto = false
|
||||
|
||||
thunder = {
|
||||
next_strike = 0,
|
||||
min_delay = 3,
|
||||
max_delay = 12,
|
||||
init_done = false,
|
||||
}
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
if weather.state ~= "thunder" then
|
||||
return false
|
||||
end
|
||||
|
||||
rain.set_particles_mode("thunder")
|
||||
rain.make_weather()
|
||||
|
||||
if thunder.init_done == false then
|
||||
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}})
|
||||
skycolor.active = true
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
player:set_clouds({color="#3D3D3FE8"})
|
||||
end
|
||||
thunder.init_done = true
|
||||
end
|
||||
|
||||
if (thunder.next_strike <= minetest.get_gametime()) then
|
||||
lightning.strike()
|
||||
local delay = math.random(thunder.min_delay, thunder.max_delay)
|
||||
thunder.next_strike = minetest.get_gametime() + delay
|
||||
end
|
||||
|
||||
end)
|
||||
|
||||
thunder.clear = function()
|
||||
rain.clear()
|
||||
skycolor.remove_layer("weather-pack-thunder-sky")
|
||||
skycolor.remove_layer("lightning")
|
||||
thunder.init_done = false
|
||||
end
|
||||
|
||||
-- register thunderstorm weather
|
||||
if weather.reg_weathers.thunder == nil then
|
||||
weather.reg_weathers.thunder = {
|
||||
clear = thunder.clear,
|
||||
-- 10min - 20min
|
||||
min_duration = 600,
|
||||
max_duration = 1200,
|
||||
transitions = {
|
||||
[100] = "rain",
|
||||
}
|
||||
}
|
||||
end
|
@ -3,4 +3,4 @@ mcl_util?
|
||||
mcl_wool?
|
||||
mcl_dye?
|
||||
mcl_tnt?
|
||||
weather_pack?
|
||||
mcl_weather?
|
||||
|
@ -5,7 +5,7 @@ local enable_respawn = minetest.settings:get_bool("enable_bed_respawn")
|
||||
if enable_respawn == nil then
|
||||
enable_respawn = true
|
||||
end
|
||||
local weather_mod = minetest.get_modpath("weather_pack") ~= nil
|
||||
local weather_mod = minetest.get_modpath("mcl_weather") ~= nil
|
||||
|
||||
-- Helper functions
|
||||
|
||||
@ -148,8 +148,8 @@ end
|
||||
|
||||
function mcl_beds.skip_thunderstorm()
|
||||
-- Skip thunderstorm
|
||||
if weather_mod and weather.get_weather() == "thunder" then
|
||||
weather.change_weather("none")
|
||||
if weather_mod and mcl_weather.get_weather() == "thunder" then
|
||||
mcl_weather.change_weather("none")
|
||||
-- Sleep for a half day (=minimum thunderstorm duration)
|
||||
minetest.set_timeofday((minetest.get_timeofday() + 0.5) % 1)
|
||||
return true
|
||||
@ -174,7 +174,7 @@ function mcl_beds.on_rightclick(pos, player)
|
||||
local tod = minetest.get_timeofday() * 24000
|
||||
|
||||
-- Values taken from Minecraft Wiki with offset of +6000
|
||||
if tod < 18541 and tod > 5458 and (not weather_mod or (weather.get_weather() ~= "thunder")) then
|
||||
if tod < 18541 and tod > 5458 and (not weather_mod or (mcl_weather.get_weather() ~= "thunder")) then
|
||||
if mcl_beds.player[name] then
|
||||
lay_down(player, nil, nil, false)
|
||||
end
|
||||
|
@ -2,6 +2,6 @@ mcl_core
|
||||
mcl_sounds
|
||||
mcl_wool
|
||||
mcl_torches
|
||||
weather_pack
|
||||
mcl_weather
|
||||
mobs_mc
|
||||
doc?
|
||||
|
@ -88,8 +88,8 @@ minetest.register_abm({
|
||||
-- The decay branch (make farmland dry or turn back to dirt)
|
||||
|
||||
-- Don't decay while it's raining
|
||||
if rain.raining then
|
||||
if weather.is_outdoor(pos) then
|
||||
if mcl_weather.rain.raining then
|
||||
if mcl_weather.is_outdoor(pos) then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
@ -6,4 +6,4 @@ mcl_hunger
|
||||
mcl_death_messages
|
||||
mcl_playerinfo
|
||||
3d_armor?
|
||||
weather_pack
|
||||
mcl_weather
|
||||
|
@ -157,7 +157,7 @@ minetest.register_globalstep(function(dtime)
|
||||
local _, dim = mcl_util.y_to_layer(pos.y)
|
||||
-- Set dimension skies.
|
||||
-- FIXME: Sky handling in MCL2 is held together with lots of duct tape.
|
||||
-- This only works beause weather_pack currently does not touch the sky for players below the height used for this check.
|
||||
-- This only works beause mcl_weather currently does not touch the sky for players below the height used for this check.
|
||||
-- There should be a real skybox API.
|
||||
if dim == "void" then
|
||||
player:set_sky("#000000", "plain", nil, false)
|
||||
@ -167,7 +167,7 @@ minetest.register_globalstep(function(dtime)
|
||||
elseif dim == "nether" then
|
||||
player:set_sky("#300808", "plain", nil, false)
|
||||
else
|
||||
skycolor.update_sky_color({player})
|
||||
mcl_weather.skycolor.update_sky_color({player})
|
||||
end
|
||||
if void_deadly then
|
||||
-- Player is deep into the void, deal void damage
|
||||
|