1
0
Fork 0

Rename weather_pack mod to mcl_weather

This commit is contained in:
Wuzzy 2017-11-21 01:35:31 +01:00
parent 37668eb1f9
commit 69ade14509
27 changed files with 240 additions and 240 deletions

View File

@ -34,7 +34,7 @@ local revertsky = function(dtime)
return return
end end
skycolor.remove_layer("lightning") mcl_weather.skycolor.remove_layer("lightning")
ps = {} ps = {}
end end
@ -136,8 +136,8 @@ lightning.strike = function(pos)
local name = player:get_player_name() local name = player:get_player_name()
if ps[name] == nil then if ps[name] == nil then
ps[name] = {p = player, sky = sky} ps[name] = {p = player, sky = sky}
skycolor.add_layer("lightning", {{r=255,g=255,b=255}}, true) mcl_weather.skycolor.add_layer("lightning", {{r=255,g=255,b=255}}, true)
skycolor.active = true mcl_weather.skycolor.active = true
end end
end end

View File

@ -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 Weathers included
----------------------- -----------------------
@ -10,13 +10,13 @@ Weathers included
Commands Commands
----------------------- -----------------------
`set_weather <weather>` requires `weather_manager` privilege. `weather <weather>`, requires `weather_manager` privilege.
Dependencies Dependencies
----------------------- -----------------------
Thunder weather requres [lightning](https://github.com/minetest-mods/lightning) mod. 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. 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.

View File

@ -0,0 +1 @@
Weather: Rain, snow, thunderstorm.

View File

@ -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.."/weather_core.lua")
dofile(modpath.."/snow.lua") dofile(modpath.."/snow.lua")
dofile(modpath.."/rain.lua") dofile(modpath.."/rain.lua")

View File

@ -0,0 +1 @@
name = mcl_weather

View File

@ -1,7 +1,7 @@
local PARTICLES_COUNT_RAIN = 30 local PARTICLES_COUNT_RAIN = 30
local PARTICLES_COUNT_THUNDER = 45 local PARTICLES_COUNT_THUNDER = 45
rain = { mcl_weather.rain = {
-- max rain particles created at time -- max rain particles created at time
particles_count = PARTICLES_COUNT_RAIN, particles_count = PARTICLES_COUNT_RAIN,
@ -18,7 +18,7 @@ rain = {
init_done = false, init_done = false,
} }
rain.sound_handler = function(player) mcl_weather.rain.sound_handler = function(player)
return minetest.sound_play("weather_rain", { return minetest.sound_play("weather_rain", {
object = player, object = player,
max_hear_distance = 2, max_hear_distance = 2,
@ -27,16 +27,16 @@ rain.sound_handler = function(player)
end end
-- set skybox based on time (uses skycolor api) -- set skybox based on time (uses skycolor api)
rain.set_sky_box = function() mcl_weather.rain.set_sky_box = function()
if weather.state == "rain" then if mcl_weather.state == "rain" then
skycolor.add_layer( mcl_weather.skycolor.add_layer(
"weather-pack-rain-sky", "weather-pack-rain-sky",
{{r=0, g=0, b=0}, {{r=0, g=0, b=0},
{r=85, g=86, b=98}, {r=85, g=86, b=98},
{r=175, g=175, b=191}, {r=175, g=175, b=191},
{r=85, g=86, b=98}, {r=85, g=86, b=98},
{r=0, g=0, b=0}}) {r=0, g=0, b=0}})
skycolor.active = true mcl_weather.skycolor.active = true
for _, player in pairs(minetest.get_connected_players()) do for _, player in pairs(minetest.get_connected_players()) do
player:set_clouds({color="#5D5D5FE8"}) player:set_clouds({color="#5D5D5FE8"})
end end
@ -45,13 +45,13 @@ end
-- creating manually parctiles instead of particles spawner because of easier to control -- creating manually parctiles instead of particles spawner because of easier to control
-- spawn position. -- spawn position.
rain.add_rain_particles = function(player) mcl_weather.rain.add_rain_particles = function(player)
rain.last_rp_count = 0 mcl_weather.rain.last_rp_count = 0
for i=rain.particles_count, 1,-1 do for i=mcl_weather.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) local random_pos_x, random_pos_y, random_pos_z = mcl_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 if mcl_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 = mcl_weather.rain.last_rp_count + 1
minetest.add_particle({ minetest.add_particle({
pos = {x=random_pos_x, y=random_pos_y, z=random_pos_z}, pos = {x=random_pos_x, y=random_pos_y, z=random_pos_z},
velocity = {x=0, y=-10, z=0}, velocity = {x=0, y=-10, z=0},
@ -61,7 +61,7 @@ rain.add_rain_particles = function(player)
collisiondetection = true, collisiondetection = true,
collision_removal = true, collision_removal = true,
vertical = true, vertical = true,
texture = rain.get_texture(), texture = mcl_weather.rain.get_texture(),
playername = player:get_player_name() playername = player:get_player_name()
}) })
end end
@ -69,7 +69,7 @@ rain.add_rain_particles = function(player)
end end
-- Simple random texture getter -- Simple random texture getter
rain.get_texture = function() mcl_weather.rain.get_texture = function()
local texture_name local texture_name
local random_number = math.random() local random_number = math.random()
if random_number > 0.33 then if random_number > 0.33 then
@ -84,42 +84,42 @@ end
-- register player for rain weather. -- register player for rain weather.
-- basically needs for origin sky reference and rain sound controls. -- basically needs for origin sky reference and rain sound controls.
rain.add_player = function(player) mcl_weather.rain.add_player = function(player)
if weather.players[player:get_player_name()] == nil then if mcl_weather.players[player:get_player_name()] == nil then
local player_meta = {} local player_meta = {}
player_meta.origin_sky = {player:get_sky()} 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
end end
-- remove player from player list effected by rain. -- remove player from player list effected by rain.
-- be sure to remove sound before removing player otherwise soundhandler reference will be lost. -- be sure to remove sound before removing player otherwise soundhandler reference will be lost.
rain.remove_player = function(player) mcl_weather.rain.remove_player = function(player)
local player_meta = weather.players[player:get_player_name()] local player_meta = mcl_weather.players[player:get_player_name()]
if player_meta ~= nil and player_meta.origin_sky ~= nil then 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_sky(player_meta.origin_sky[1], player_meta.origin_sky[2], player_meta.origin_sky[3], true)
player:set_clouds({color="#FFF0F0E5"}) player:set_clouds({color="#FFF0F0E5"})
weather.players[player:get_player_name()] = nil mcl_weather.players[player:get_player_name()] = nil
end end
end end
-- adds and removes rain sound depending how much rain particles around player currently exist. -- 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 -- 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. -- when player stay on 'edge' where sound should play and stop depending from random raindrop appearance.
rain.update_sound = function(player) mcl_weather.rain.update_sound = function(player)
local player_meta = weather.players[player:get_player_name()] local player_meta = mcl_weather.players[player:get_player_name()]
if player_meta ~= nil then if player_meta ~= nil then
if player_meta.sound_updated ~= nil and player_meta.sound_updated + 5 > minetest.get_gametime() then if player_meta.sound_updated ~= nil and player_meta.sound_updated + 5 > minetest.get_gametime() then
return false return false
end end
if player_meta.sound_handler ~= nil then 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) minetest.sound_stop(player_meta.sound_handler)
player_meta.sound_handler = nil player_meta.sound_handler = nil
end end
elseif rain.last_rp_count > 0 then elseif mcl_weather.rain.last_rp_count > 0 then
player_meta.sound_handler = rain.sound_handler(player) player_meta.sound_handler = mcl_weather.rain.sound_handler(player)
end end
player_meta.sound_updated = minetest.get_gametime() player_meta.sound_updated = minetest.get_gametime()
@ -127,8 +127,8 @@ rain.update_sound = function(player)
end end
-- rain sound removed from player. -- rain sound removed from player.
rain.remove_sound = function(player) mcl_weather.rain.remove_sound = function(player)
local player_meta = weather.players[player:get_player_name()] local player_meta = mcl_weather.players[player:get_player_name()]
if player_meta ~= nil and player_meta.sound_handler ~= nil then if player_meta ~= nil and player_meta.sound_handler ~= nil then
minetest.sound_stop(player_meta.sound_handler) minetest.sound_stop(player_meta.sound_handler)
player_meta.sound_handler = nil player_meta.sound_handler = nil
@ -136,55 +136,55 @@ rain.remove_sound = function(player)
end end
-- callback function for removing rain -- callback function for removing rain
rain.clear = function() mcl_weather.rain.clear = function()
rain.raining = false mcl_weather.rain.raining = false
rain.sky_last_update = -1 mcl_weather.rain.sky_last_update = -1
rain.init_done = false mcl_weather.rain.init_done = false
rain.set_particles_mode("rain") mcl_weather.rain.set_particles_mode("rain")
skycolor.remove_layer("weather-pack-rain-sky") mcl_weather.skycolor.remove_layer("weather-pack-rain-sky")
for _, player in ipairs(minetest.get_connected_players()) do for _, player in ipairs(minetest.get_connected_players()) do
rain.remove_sound(player) mcl_weather.rain.remove_sound(player)
rain.remove_player(player) mcl_weather.rain.remove_player(player)
end end
end end
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
if weather.state ~= "rain" then if mcl_weather.state ~= "rain" then
return false return false
end end
rain.make_weather() mcl_weather.rain.make_weather()
end) end)
rain.make_weather = function() mcl_weather.rain.make_weather = function()
if rain.init_done == false then if mcl_weather.rain.init_done == false then
rain.raining = true mcl_weather.rain.raining = true
rain.set_sky_box() mcl_weather.rain.set_sky_box()
rain.set_particles_mode(weather.mode) mcl_weather.rain.set_particles_mode(mcl_weather.mode)
rain.init_done = true mcl_weather.rain.init_done = true
end end
for _, player in ipairs(minetest.get_connected_players()) do 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
rain.remove_sound(player) mcl_weather.rain.remove_sound(player)
return false return false
end end
rain.add_player(player) mcl_weather.rain.add_player(player)
rain.add_rain_particles(player) mcl_weather.rain.add_rain_particles(player)
rain.update_sound(player) mcl_weather.rain.update_sound(player)
end end
end end
-- Switch the number of raindrops: "thunder" for many raindrops, otherwise for normal raindrops -- 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 if mode == "thunder" then
rain.particles_count = PARTICLES_COUNT_THUNDER mcl_weather.rain.particles_count = PARTICLES_COUNT_THUNDER
else else
rain.particles_count = PARTICLES_COUNT_RAIN mcl_weather.rain.particles_count = PARTICLES_COUNT_RAIN
end end
end end
if weather.allow_abm then if mcl_weather.allow_abm then
-- ABM for extinguish fire -- ABM for extinguish fire
minetest.register_abm({ minetest.register_abm({
label = "Rain extinguishes fire", label = "Rain extinguishes fire",
@ -192,8 +192,8 @@ if weather.allow_abm then
interval = 4.0, interval = 4.0,
chance = 2, chance = 2,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
if rain.raining and rain.extinguish_fire then if mcl_weather.rain.raining and mcl_weather.rain.extinguish_fire then
if weather.is_outdoor(pos) then if mcl_weather.is_outdoor(pos) then
minetest.remove_node(pos) minetest.remove_node(pos)
minetest.sound_play("fire_extinguish_flame", {pos = pos, max_hear_distance = 16, gain = 0.15}) minetest.sound_play("fire_extinguish_flame", {pos = pos, max_hear_distance = 16, gain = 0.15})
end end
@ -208,7 +208,7 @@ if weather.allow_abm then
interval = 56.0, interval = 56.0,
chance = 1, chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider) 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 if node.name == "mcl_cauldrons:cauldron" then
minetest.set_node(pos, {name="mcl_cauldrons:cauldron_1"}) minetest.set_node(pos, {name="mcl_cauldrons:cauldron_1"})
elseif node.name == "mcl_cauldrons:cauldron_1" then elseif node.name == "mcl_cauldrons:cauldron_1" then
@ -227,7 +227,7 @@ if weather.allow_abm then
interval = 22.0, interval = 22.0,
chance = 3, chance = 3,
action = function(pos, node, active_object_count, active_object_count_wider) 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 if node.name == "mcl_farming:soil" then
minetest.set_node(pos, {name="mcl_farming:soil_wet"}) minetest.set_node(pos, {name="mcl_farming:soil_wet"})
end end
@ -236,9 +236,9 @@ if weather.allow_abm then
}) })
end end
if weather.reg_weathers.rain == nil then if mcl_weather.reg_weathers.rain == nil then
weather.reg_weathers.rain = { mcl_weather.reg_weathers.rain = {
clear = rain.clear, clear = mcl_weather.rain.clear,
-- 10min - 20min -- 10min - 20min
min_duration = 600, min_duration = 600,
max_duration = 1200, max_duration = 1200,

View File

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB

View File

@ -1,4 +1,4 @@
skycolor = { mcl_weather.skycolor = {
-- Should be activated before do any effect. -- Should be activated before do any effect.
active = true, active = true,
@ -38,26 +38,26 @@ skycolor = {
-- To layer to colors table -- To layer to colors table
add_layer = function(layer_name, layer_color, instant_update) add_layer = function(layer_name, layer_color, instant_update)
skycolor.colors[layer_name] = layer_color mcl_weather.skycolor.colors[layer_name] = layer_color
table.insert(skycolor.layer_names, layer_name) table.insert(mcl_weather.skycolor.layer_names, layer_name)
if (instant_update ~= true) then if (instant_update ~= true) then
skycolor.init_transition() mcl_weather.skycolor.init_transition()
end end
skycolor.force_update = true mcl_weather.skycolor.force_update = true
end, end,
-- Retrieve layer from colors table -- Retrieve layer from colors table
retrieve_layer = function() retrieve_layer = function()
local last_layer = skycolor.layer_names[#skycolor.layer_names] local last_layer = mcl_weather.skycolor.layer_names[#mcl_weather.skycolor.layer_names]
return skycolor.colors[last_layer] return mcl_weather.skycolor.colors[last_layer]
end, end,
-- Remove layer from colors table -- Remove layer from colors table
remove_layer = function(layer_name) 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 if name == layer_name then
table.remove(skycolor.layer_names, k) table.remove(mcl_weather.skycolor.layer_names, k)
skycolor.force_update = true mcl_weather.skycolor.force_update = true
return return
end end
end end
@ -65,13 +65,13 @@ skycolor = {
-- Update sky color. If players not specified update sky for all players. -- Update sky color. If players not specified update sky for all players.
update_sky_color = function(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 if (color == nil) then
skycolor.set_default_sky() mcl_weather.skycolor.set_default_sky()
return return
end end
players = skycolor.utils.get_players(players) players = mcl_weather.skycolor.utils.get_players(players)
for _, player in ipairs(players) do for _, player in ipairs(players) do
local pos = player:getpos() local pos = player:getpos()
local _, dim = mcl_util.y_to_layer(pos.y) local _, dim = mcl_util.y_to_layer(pos.y)
@ -83,34 +83,34 @@ skycolor = {
-- Returns current layer color in {r, g, b} format -- Returns current layer color in {r, g, b} format
current_sky_layer_color = function() current_sky_layer_color = function()
if #skycolor.layer_names == 0 then if #mcl_weather.skycolor.layer_names == 0 then
return nil return nil
end 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 timeofday = minetest.get_timeofday()
local rounded_time = math.floor(timeofday * skycolor.max_val) local rounded_time = math.floor(timeofday * mcl_weather.skycolor.max_val)
local color = skycolor.utils.convert_to_rgb(skycolor.min_val, skycolor.max_val, rounded_time, skycolor.retrieve_layer()) 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 return color
end, end,
-- Initialy used only on -- Initialy used only on
update_transition_sky_color = function() update_transition_sky_color = function()
if #skycolor.layer_names == 0 then if #mcl_weather.skycolor.layer_names == 0 then
skycolor.set_default_sky() mcl_weather.skycolor.set_default_sky()
return return
end end
local multiplier = 100 local multiplier = 100
local rounded_time = math.floor(skycolor.transition_timer * multiplier) local rounded_time = math.floor(mcl_weather.skycolor.transition_timer * multiplier)
if rounded_time >= skycolor.transition_time * multiplier then if rounded_time >= mcl_weather.skycolor.transition_time * multiplier then
skycolor.stop_transition() mcl_weather.skycolor.stop_transition()
return return
end 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 for _, player in ipairs(players) do
local pos = player:getpos() local pos = player:getpos()
local _, dim = mcl_util.y_to_layer(pos.y) 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 -- Could be sometimes useful but not recomended to use in general case as there may be other color layers
-- which needs to preserve. -- which needs to preserve.
set_default_sky = function(players) 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 for _, player in ipairs(players) do
local pos = player:getpos() local pos = player:getpos()
local _, dim = mcl_util.y_to_layer(pos.y) local _, dim = mcl_util.y_to_layer(pos.y)
@ -137,23 +137,23 @@ skycolor = {
init_transition = function() init_transition = function()
-- sadly default sky returns unpredictible colors so transition mode becomes usable only for user defined color layers -- 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. -- 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 return
end 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 if (transition_start_color == nil) then
return return
end end
local transition_end_color = skycolor.current_sky_layer_color() local transition_end_color = mcl_weather.skycolor.current_sky_layer_color()
skycolor.transition_colors = {transition_start_color, transition_end_color} mcl_weather.skycolor.transition_colors = {transition_start_color, transition_end_color}
skycolor.transition_in_progress = true mcl_weather.skycolor.transition_in_progress = true
end, end,
stop_transition = function() stop_transition = function()
skycolor.transition_in_progress = false mcl_weather.skycolor.transition_in_progress = false
skycolor.transition_colors = {} mcl_weather.skycolor.transition_colors = {}
skycolor.transition_timer = 0 mcl_weather.skycolor.transition_timer = 0
end, end,
utils = { utils = {
@ -178,7 +178,7 @@ skycolor = {
-- Returns first player sky color. I assume that all players are in same color layout. -- Returns first player sky color. I assume that all players are in same color layout.
get_current_bg_color = function() 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 for _, player in ipairs(players) do
return player:get_sky() return player:get_sky()
end end
@ -190,34 +190,34 @@ skycolor = {
local timer = 0 local timer = 0
minetest.register_globalstep(function(dtime) 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 return
end end
if skycolor.smooth_transitions and skycolor.transition_in_progress then if mcl_weather.skycolor.smooth_transitions and mcl_weather.skycolor.transition_in_progress then
skycolor.transition_timer = skycolor.transition_timer + dtime mcl_weather.skycolor.transition_timer = mcl_weather.skycolor.transition_timer + dtime
skycolor.update_transition_sky_color() mcl_weather.skycolor.update_transition_sky_color()
return return
end end
if skycolor.force_update then if mcl_weather.skycolor.force_update then
skycolor.update_sky_color() mcl_weather.skycolor.update_sky_color()
skycolor.force_update = false mcl_weather.skycolor.force_update = false
return return
end end
-- regular updates based on iterval -- regular updates based on iterval
timer = timer + dtime; timer = timer + dtime;
if timer >= skycolor.update_interval then if timer >= mcl_weather.skycolor.update_interval then
skycolor.update_sky_color() mcl_weather.skycolor.update_sky_color()
timer = 0 timer = 0
end end
end) end)
local initsky = function(player) local initsky = function(player)
if (skycolor.active) then if (mcl_weather.skycolor.active) then
skycolor.force_update = true mcl_weather.skycolor.force_update = true
end end
-- MC-style clouds: Layer 127, thickness 4, fly to the “West” -- MC-style clouds: Layer 127, thickness 4, fly to the “West”

View File

@ -1,16 +1,16 @@
snow = {} mcl_weather.snow = {}
snow.particles_count = 15 mcl_weather.snow.particles_count = 15
snow.init_done = false mcl_weather.snow.init_done = false
-- calculates coordinates and draw particles for snow weather -- calculates coordinates and draw particles for snow weather
snow.add_rain_particles = function(player) mcl_weather.snow.add_snow_particles = function(player)
rain.last_rp_count = 0 mcl_weather.rain.last_rp_count = 0
for i=snow.particles_count, 1,-1 do for i=mcl_weather.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) 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) 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 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({ minetest.add_particle({
pos = {x=random_pos_x, y=random_pos_y, z=random_pos_z}, 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)}, 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, collisiondetection = true,
collision_removal = true, collision_removal = true,
vertical = true, vertical = true,
texture = snow.get_texture(), texture = mcl_weather.snow.get_texture(),
playername = player:get_player_name() playername = player:get_player_name()
}) })
end end
end end
end end
snow.set_sky_box = function() mcl_weather.snow.set_sky_box = function()
skycolor.add_layer( mcl_weather.skycolor.add_layer(
"weather-pack-snow-sky", "weather-pack-snow-sky",
{{r=0, g=0, b=0}, {{r=0, g=0, b=0},
{r=241, g=244, b=249}, {r=241, g=244, b=249},
{r=0, g=0, b=0}} {r=0, g=0, b=0}}
) )
skycolor.active = true mcl_weather.skycolor.active = true
end end
snow.clear = function() mcl_weather.snow.clear = function()
skycolor.remove_layer("weather-pack-snow-sky") mcl_weather.skycolor.remove_layer("weather-pack-snow-sky")
snow.init_done = false mcl_weather.snow.init_done = false
end end
-- Simple random texture getter -- Simple random texture getter
snow.get_texture = function() mcl_weather.snow.get_texture = function()
local texture_name local texture_name
local random_number = math.random() local random_number = math.random()
if random_number > 0.5 then if random_number > 0.5 then
@ -56,7 +56,7 @@ end
local timer = 0 local timer = 0
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
if weather.state ~= "snow" then if mcl_weather.state ~= "snow" then
return false return false
end end
@ -67,23 +67,23 @@ minetest.register_globalstep(function(dtime)
return return
end end
if snow.init_done == false then if mcl_weather.snow.init_done == false then
snow.set_sky_box() mcl_weather.snow.set_sky_box()
snow.init_done = true mcl_weather.snow.init_done = true
end end
for _, player in ipairs(minetest.get_connected_players()) do 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 return false
end end
snow.add_rain_particles(player) mcl_weather.snow.add_snow_particles(player)
end end
end) end)
-- register snow weather -- register snow weather
if weather.reg_weathers.snow == nil then if mcl_weather.reg_weathers.snow == nil then
weather.reg_weathers.snow = { mcl_weather.reg_weathers.snow = {
clear = snow.clear, clear = mcl_weather.snow.clear,
-- 10min - 20min -- 10min - 20min
min_duration = 600, min_duration = 600,
max_duration = 1200, max_duration = 1200,

View 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

View File

@ -1,4 +1,4 @@
weather = { mcl_weather = {
-- weather states, 'none' is default, other states depends from active mods -- weather states, 'none' is default, other states depends from active mods
state = "none", state = "none",
@ -27,9 +27,9 @@ weather = {
allow_abm = true, allow_abm = true,
} }
weather.reg_weathers["none"] = { mcl_weather.reg_weathers["none"] = {
min_duration = weather.min_duration, min_duration = mcl_weather.min_duration,
max_duration = weather.max_duration, max_duration = mcl_weather.max_duration,
transitions = { transitions = {
[50] = "rain", [50] = "rain",
[100] = "snow", [100] = "snow",
@ -37,12 +37,12 @@ weather.reg_weathers["none"] = {
clear = function() end, 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 local r
if min_duration ~= nil and max_duration ~= nil then if min_duration ~= nil and max_duration ~= nil then
r = math.random(min_duration, max_duration); r = math.random(min_duration, max_duration);
else else
r = math.random(weather.min_duration, weather.max_duration); r = math.random(mcl_weather.min_duration, mcl_weather.max_duration);
end end
return minetest.get_gametime() + r return minetest.get_gametime() + r
end end
@ -50,7 +50,7 @@ end
-- Returns true if pos is outdoor. -- Returns true if pos is outdoor.
-- Outdoor is defined as any node in the Overworld under open sky. -- 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. -- 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 cpos = {x=pos.x, y=pos.y+1, z=pos.z}
local _, dim = mcl_util.y_to_layer(cpos.y) local _, dim = mcl_util.y_to_layer(cpos.y)
if minetest.get_node_light(cpos, 0.5) == 15 and dim == "overworld" then 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 -- checks if player is undewater. This is needed in order to
-- turn off weather particles generation. -- turn off weather particles generation.
weather.is_underwater = function(player) mcl_weather.is_underwater = function(player)
local ppos = player:getpos() local ppos = player:getpos()
local offset = player:get_eye_offset() local offset = player:get_eye_offset()
local player_eye_pos = {x = ppos.x + offset.x, 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. -- 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. -- 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 look_dir = player:get_look_dir()
local player_pos = player:getpos() local player_pos = player:getpos()
@ -107,21 +107,21 @@ weather.get_random_pos_by_player_look_dir = function(player)
end end
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
if weather.auto_mode == false then if mcl_weather.auto_mode == false then
return 0 return 0
end end
if weather.end_time == nil then if mcl_weather.end_time == nil then
weather.end_time = weather.get_rand_end_time() mcl_weather.end_time = mcl_weather.get_rand_end_time()
end end
-- recalculate weather -- recalculate weather
if weather.end_time <= minetest.get_gametime() then if mcl_weather.end_time <= minetest.get_gametime() then
weather.set_random_weather(weather.state, weather.reg_weathers[weather.state]) mcl_weather.set_random_weather(mcl_weather.state, mcl_weather.reg_weathers[mcl_weather.state])
end end
end) end)
-- Sets random weather (which could be 'none' (no weather)). -- 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 if (weather_meta ~= nil) then
local transitions = weather_meta.transitions local transitions = weather_meta.transitions
local random_roll = math.random(0,100) local random_roll = math.random(0,100)
@ -133,26 +133,26 @@ weather.set_random_weather = function(weather_name, weather_meta)
end end
end end
if new_weather then if new_weather then
weather.change_weather(new_weather) mcl_weather.change_weather(new_weather)
end end
end end
end end
weather.change_weather = function(new_weather) mcl_weather.change_weather = function(new_weather)
if (weather.reg_weathers ~= nil and weather.reg_weathers[new_weather] ~= nil) then if (mcl_weather.reg_weathers ~= nil and mcl_weather.reg_weathers[new_weather] ~= nil) then
if (weather.state ~= nil and weather.reg_weathers[weather.state] ~= nil) then if (mcl_weather.state ~= nil and mcl_weather.reg_weathers[mcl_weather.state] ~= nil) then
weather.reg_weathers[weather.state].clear() mcl_weather.reg_weathers[mcl_weather.state].clear()
end end
weather.state = new_weather mcl_weather.state = new_weather
local weather_meta = weather.reg_weathers[weather.state] local weather_meta = mcl_weather.reg_weathers[mcl_weather.state]
weather.end_time = weather.get_rand_end_time(weather_meta.min_duration, weather_meta.max_duration) mcl_weather.end_time = mcl_weather.get_rand_end_time(weather_meta.min_duration, weather_meta.max_duration)
return true return true
end end
return false return false
end end
weather.get_weather = function() mcl_weather.get_weather = function()
return weather.state return mcl_weather.state
end end
minetest.register_privilege("weather_manager", { minetest.register_privilege("weather_manager", {
@ -175,7 +175,7 @@ minetest.register_chatcommand("weather", {
else else
new_weather = param new_weather = param
end end
local success = weather.change_weather(new_weather) local success = mcl_weather.change_weather(new_weather)
if success then if success then
return true return true
else else
@ -190,14 +190,14 @@ minetest.register_chatcommand("toggledownfall", {
privs = {weather_manager = true}, privs = {weather_manager = true},
func = function(name, param) func = function(name, param)
-- Currently rain/thunder/snow: Set weather to clear -- Currently rain/thunder/snow: Set weather to clear
if weather.state ~= "none" then if mcl_weather.state ~= "none" then
return weather.change_weather("none") return mcl_weather.change_weather("none")
-- Currently clear: Set weather randomly to rain/thunder/snow -- Currently clear: Set weather randomly to rain/thunder/snow
else else
local new = { "rain", "thunder", "snow" } local new = { "rain", "thunder", "snow" }
local r = math.random(1, #new) local r = math.random(1, #new)
return weather.change_weather(new[r]) return mcl_weather.change_weather(new[r])
end end
end end
}) })
@ -206,5 +206,5 @@ minetest.register_chatcommand("toggledownfall", {
-- Weather mods expected to be use this flag before registering ABM. -- Weather mods expected to be use this flag before registering ABM.
local weather_allow_abm = minetest.settings:get_bool("weather_allow_abm") local weather_allow_abm = minetest.settings:get_bool("weather_allow_abm")
if weather_allow_abm ~= nil and weather_allow_abm == false then if weather_allow_abm ~= nil and weather_allow_abm == false then
weather.allow_abm = false mcl_weather.allow_abm = false
end end

View File

@ -1 +0,0 @@
Set of weathers for minetest.

View File

@ -1 +0,0 @@
name = weather_pack

View File

@ -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

View File

@ -3,4 +3,4 @@ mcl_util?
mcl_wool? mcl_wool?
mcl_dye? mcl_dye?
mcl_tnt? mcl_tnt?
weather_pack? mcl_weather?

View File

@ -5,7 +5,7 @@ local enable_respawn = minetest.settings:get_bool("enable_bed_respawn")
if enable_respawn == nil then if enable_respawn == nil then
enable_respawn = true enable_respawn = true
end end
local weather_mod = minetest.get_modpath("weather_pack") ~= nil local weather_mod = minetest.get_modpath("mcl_weather") ~= nil
-- Helper functions -- Helper functions
@ -148,8 +148,8 @@ end
function mcl_beds.skip_thunderstorm() function mcl_beds.skip_thunderstorm()
-- Skip thunderstorm -- Skip thunderstorm
if weather_mod and weather.get_weather() == "thunder" then if weather_mod and mcl_weather.get_weather() == "thunder" then
weather.change_weather("none") mcl_weather.change_weather("none")
-- Sleep for a half day (=minimum thunderstorm duration) -- Sleep for a half day (=minimum thunderstorm duration)
minetest.set_timeofday((minetest.get_timeofday() + 0.5) % 1) minetest.set_timeofday((minetest.get_timeofday() + 0.5) % 1)
return true return true
@ -174,7 +174,7 @@ function mcl_beds.on_rightclick(pos, player)
local tod = minetest.get_timeofday() * 24000 local tod = minetest.get_timeofday() * 24000
-- Values taken from Minecraft Wiki with offset of +6000 -- 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 if mcl_beds.player[name] then
lay_down(player, nil, nil, false) lay_down(player, nil, nil, false)
end end

View File

@ -2,6 +2,6 @@ mcl_core
mcl_sounds mcl_sounds
mcl_wool mcl_wool
mcl_torches mcl_torches
weather_pack mcl_weather
mobs_mc mobs_mc
doc? doc?

View File

@ -88,8 +88,8 @@ minetest.register_abm({
-- The decay branch (make farmland dry or turn back to dirt) -- The decay branch (make farmland dry or turn back to dirt)
-- Don't decay while it's raining -- Don't decay while it's raining
if rain.raining then if mcl_weather.rain.raining then
if weather.is_outdoor(pos) then if mcl_weather.is_outdoor(pos) then
return return
end end
end end

View File

@ -6,4 +6,4 @@ mcl_hunger
mcl_death_messages mcl_death_messages
mcl_playerinfo mcl_playerinfo
3d_armor? 3d_armor?
weather_pack mcl_weather

View File

@ -157,7 +157,7 @@ minetest.register_globalstep(function(dtime)
local _, dim = mcl_util.y_to_layer(pos.y) local _, dim = mcl_util.y_to_layer(pos.y)
-- Set dimension skies. -- Set dimension skies.
-- FIXME: Sky handling in MCL2 is held together with lots of duct tape. -- 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. -- There should be a real skybox API.
if dim == "void" then if dim == "void" then
player:set_sky("#000000", "plain", nil, false) player:set_sky("#000000", "plain", nil, false)
@ -167,7 +167,7 @@ minetest.register_globalstep(function(dtime)
elseif dim == "nether" then elseif dim == "nether" then
player:set_sky("#300808", "plain", nil, false) player:set_sky("#300808", "plain", nil, false)
else else
skycolor.update_sky_color({player}) mcl_weather.skycolor.update_sky_color({player})
end end
if void_deadly then if void_deadly then
-- Player is deep into the void, deal void damage -- Player is deep into the void, deal void damage