2022-06-19 20:35:49 +00:00
|
|
|
local PARTICLES_COUNT_RAIN = tonumber(minetest.settings:get("mcl_weather_rain_particles")) or 500
|
|
|
|
local PARTICLES_COUNT_THUNDER = tonumber(minetest.settings:get("mcl_weather_thunder_particles")) or 900
|
2017-11-12 00:52:07 +00:00
|
|
|
|
2021-03-16 16:43:32 +00:00
|
|
|
local get_connected_players = minetest.get_connected_players
|
|
|
|
|
2017-11-21 00:35:31 +00:00
|
|
|
mcl_weather.rain = {
|
2021-01-28 07:47:51 +00:00
|
|
|
-- max rain particles created at time
|
|
|
|
particles_count = PARTICLES_COUNT_RAIN,
|
2017-02-20 18:05:26 +00:00
|
|
|
|
2021-01-28 07:47:51 +00:00
|
|
|
-- flag to turn on/off extinguish fire for rain
|
|
|
|
extinguish_fire = true,
|
2017-08-22 16:18:53 +00:00
|
|
|
|
2021-01-28 07:47:51 +00:00
|
|
|
-- flag useful when mixing weathers
|
|
|
|
raining = false,
|
2017-02-20 18:05:26 +00:00
|
|
|
|
2021-01-28 07:47:51 +00:00
|
|
|
-- keeping last timeofday value (rounded).
|
|
|
|
-- Defaulted to non-existing value for initial comparing.
|
|
|
|
sky_last_update = -1,
|
2017-02-20 18:05:26 +00:00
|
|
|
|
2021-01-28 07:47:51 +00:00
|
|
|
init_done = false,
|
2017-02-20 18:05:26 +00:00
|
|
|
}
|
2022-01-30 20:15:51 +00:00
|
|
|
local update_sound={}
|
2022-06-19 20:19:46 +00:00
|
|
|
|
2022-01-30 20:15:51 +00:00
|
|
|
local psdef= {
|
|
|
|
amount = mcl_weather.rain.particles_count,
|
|
|
|
time=0,
|
2022-05-28 00:00:17 +00:00
|
|
|
minpos = vector.new(-15,20,-15),
|
|
|
|
maxpos = vector.new(15,25,15),
|
2022-06-19 20:19:46 +00:00
|
|
|
minvel = vector.new(-2,-17,-2),
|
|
|
|
maxvel = vector.new(2,-8,2),
|
2022-01-30 20:15:51 +00:00
|
|
|
minacc = vector.new(0,0,0),
|
2022-05-28 00:00:17 +00:00
|
|
|
maxacc = vector.new(0,-0.5,0),
|
2022-06-19 20:19:46 +00:00
|
|
|
minexptime = 1,
|
|
|
|
maxexptime = 4,
|
|
|
|
minsize = 4,
|
|
|
|
maxsize= 8,
|
2022-01-30 20:15:51 +00:00
|
|
|
collisiondetection = true,
|
|
|
|
collision_removal = true,
|
|
|
|
vertical = true,
|
|
|
|
}
|
2022-05-28 00:00:17 +00:00
|
|
|
|
|
|
|
local textures = {"weather_pack_rain_raindrop_1.png", "weather_pack_rain_raindrop_2.png"}
|
2017-02-20 18:05:26 +00:00
|
|
|
|
2021-05-25 11:18:12 +00:00
|
|
|
function mcl_weather.rain.sound_handler(player)
|
2021-01-28 07:47:51 +00:00
|
|
|
return minetest.sound_play("weather_rain", {
|
|
|
|
to_player = player:get_player_name(),
|
|
|
|
loop = true,
|
|
|
|
})
|
2017-02-20 18:05:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- set skybox based on time (uses skycolor api)
|
2021-05-25 11:18:12 +00:00
|
|
|
function mcl_weather.rain.set_sky_box()
|
2021-01-28 07:47:51 +00:00
|
|
|
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=135, g=135, b=151},
|
|
|
|
{r=85, g=86, b=98},
|
|
|
|
{r=0, g=0, b=0}})
|
|
|
|
mcl_weather.skycolor.active = true
|
2021-03-16 16:43:32 +00:00
|
|
|
for _, player in pairs(get_connected_players()) do
|
2021-01-28 07:47:51 +00:00
|
|
|
player:set_clouds({color="#5D5D5FE8"})
|
|
|
|
end
|
|
|
|
end
|
2017-02-20 18:05:26 +00:00
|
|
|
end
|
|
|
|
|
2022-01-30 20:15:51 +00:00
|
|
|
-- no no no NO NO f*.. no. no manual particle creatin' PLS!! this sends EVERY particle over the net.
|
2021-05-25 11:18:12 +00:00
|
|
|
function mcl_weather.rain.add_rain_particles(player)
|
2022-01-30 20:15:51 +00:00
|
|
|
mcl_weather.rain.last_rp_count = mcl_weather.rain.particles_count
|
2022-06-19 20:25:50 +00:00
|
|
|
local l = false
|
2022-01-30 20:15:51 +00:00
|
|
|
for k,v in pairs(textures) do
|
|
|
|
psdef.texture=v
|
2022-06-19 20:25:50 +00:00
|
|
|
l = l or mcl_weather.add_spawner_player(player,"rain"..k,psdef)
|
2021-01-28 07:47:51 +00:00
|
|
|
end
|
2022-01-30 20:15:51 +00:00
|
|
|
if l then
|
|
|
|
update_sound[player:get_player_name()]=true
|
2021-01-28 07:47:51 +00:00
|
|
|
end
|
2017-02-20 18:05:26 +00:00
|
|
|
end
|
|
|
|
|
2017-08-22 16:18:53 +00:00
|
|
|
-- register player for rain weather.
|
2017-02-20 18:05:26 +00:00
|
|
|
-- basically needs for origin sky reference and rain sound controls.
|
2021-05-25 11:18:12 +00:00
|
|
|
function mcl_weather.rain.add_player(player)
|
2021-01-28 07:47:51 +00:00
|
|
|
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
|
2022-01-30 20:15:51 +00:00
|
|
|
update_sound[player:get_player_name()]=true
|
2021-01-28 07:47:51 +00:00
|
|
|
end
|
2017-02-20 18:05:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- remove player from player list effected by rain.
|
|
|
|
-- be sure to remove sound before removing player otherwise soundhandler reference will be lost.
|
2021-05-25 11:18:12 +00:00
|
|
|
function mcl_weather.rain.remove_player(player)
|
2021-01-28 07:47:51 +00:00
|
|
|
local player_meta = mcl_weather.players[player:get_player_name()]
|
2021-05-29 14:12:33 +00:00
|
|
|
if player_meta and player_meta.origin_sky then
|
2021-01-28 07:47:51 +00:00
|
|
|
player:set_clouds({color="#FFF0F0E5"})
|
|
|
|
mcl_weather.players[player:get_player_name()] = nil
|
2022-01-30 20:15:51 +00:00
|
|
|
update_sound[player:get_player_name()]=true
|
2021-01-28 07:47:51 +00:00
|
|
|
end
|
2017-02-20 18:05:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- adds and removes rain sound depending how much rain particles around player currently exist.
|
2017-08-22 16:18:53 +00:00
|
|
|
-- have few seconds delay before each check to avoid on/off sound too often
|
2017-02-20 18:05:26 +00:00
|
|
|
-- when player stay on 'edge' where sound should play and stop depending from random raindrop appearance.
|
2021-05-25 11:18:12 +00:00
|
|
|
function mcl_weather.rain.update_sound(player)
|
2022-01-30 20:15:51 +00:00
|
|
|
if not update_sound[player:get_player_name()] then return end
|
2021-01-28 07:47:51 +00:00
|
|
|
local player_meta = mcl_weather.players[player:get_player_name()]
|
2021-05-29 14:12:33 +00:00
|
|
|
if player_meta then
|
|
|
|
if player_meta.sound_updated and player_meta.sound_updated + 5 > minetest.get_gametime() then
|
2021-01-28 07:47:51 +00:00
|
|
|
return false
|
|
|
|
end
|
2017-08-22 16:18:53 +00:00
|
|
|
|
2021-05-29 14:12:33 +00:00
|
|
|
if player_meta.sound_handler then
|
2021-01-28 07:47:51 +00:00
|
|
|
if mcl_weather.rain.last_rp_count == 0 then
|
|
|
|
minetest.sound_fade(player_meta.sound_handler, -0.5, 0.0)
|
|
|
|
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
|
2017-08-22 16:18:53 +00:00
|
|
|
|
2021-01-28 07:47:51 +00:00
|
|
|
player_meta.sound_updated = minetest.get_gametime()
|
|
|
|
end
|
2022-01-30 20:15:51 +00:00
|
|
|
update_sound[player:get_player_name()]=false
|
2017-02-20 18:05:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- rain sound removed from player.
|
2021-05-25 11:18:12 +00:00
|
|
|
function mcl_weather.rain.remove_sound(player)
|
2021-01-28 07:47:51 +00:00
|
|
|
local player_meta = mcl_weather.players[player:get_player_name()]
|
2021-05-29 14:12:33 +00:00
|
|
|
if player_meta and player_meta.sound_handler then
|
2021-01-28 07:47:51 +00:00
|
|
|
minetest.sound_fade(player_meta.sound_handler, -0.5, 0.0)
|
|
|
|
player_meta.sound_handler = nil
|
|
|
|
player_meta.sound_updated = nil
|
|
|
|
end
|
2017-02-20 18:05:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- callback function for removing rain
|
2021-05-25 11:18:12 +00:00
|
|
|
function mcl_weather.rain.clear()
|
2021-01-28 07:47:51 +00:00
|
|
|
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")
|
2021-03-16 16:43:32 +00:00
|
|
|
for _, player in pairs(get_connected_players()) do
|
2021-01-28 07:47:51 +00:00
|
|
|
mcl_weather.rain.remove_sound(player)
|
|
|
|
mcl_weather.rain.remove_player(player)
|
2022-01-30 20:15:51 +00:00
|
|
|
mcl_weather.remove_spawners_player(player)
|
2022-05-26 05:29:28 +00:00
|
|
|
end
|
2017-02-20 18:05:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_globalstep(function(dtime)
|
2021-01-28 07:47:51 +00:00
|
|
|
if mcl_weather.state ~= "rain" then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
mcl_weather.rain.make_weather()
|
2017-02-20 18:05:26 +00:00
|
|
|
end)
|
|
|
|
|
2021-05-25 11:18:12 +00:00
|
|
|
function mcl_weather.rain.make_weather()
|
2021-01-28 07:47:51 +00:00
|
|
|
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
|
2017-02-20 18:05:26 +00:00
|
|
|
|
2021-03-16 16:43:32 +00:00
|
|
|
for _, player in pairs(get_connected_players()) do
|
2022-01-30 20:15:51 +00:00
|
|
|
local pos=player:get_pos()
|
2022-05-28 00:00:17 +00:00
|
|
|
if mcl_weather.is_underwater(player) or not mcl_worlds.has_weather(pos) then
|
2021-01-28 07:47:51 +00:00
|
|
|
mcl_weather.rain.remove_sound(player)
|
2022-01-30 20:15:51 +00:00
|
|
|
mcl_weather.remove_spawners_player(player)
|
2022-05-28 00:00:17 +00:00
|
|
|
else
|
|
|
|
mcl_weather.rain.add_player(player)
|
|
|
|
mcl_weather.rain.add_rain_particles(player)
|
|
|
|
mcl_weather.rain.update_sound(player)
|
2021-01-28 07:47:51 +00:00
|
|
|
end
|
|
|
|
end
|
2017-02-20 18:05:26 +00:00
|
|
|
end
|
|
|
|
|
2017-11-12 00:52:07 +00:00
|
|
|
-- Switch the number of raindrops: "thunder" for many raindrops, otherwise for normal raindrops
|
2021-05-25 11:18:12 +00:00
|
|
|
function mcl_weather.rain.set_particles_mode(mode)
|
2021-01-28 07:47:51 +00:00
|
|
|
if mode == "thunder" then
|
2022-01-30 20:15:51 +00:00
|
|
|
psdef.amount=PARTICLES_COUNT_THUNDER
|
2021-01-28 07:47:51 +00:00
|
|
|
mcl_weather.rain.particles_count = PARTICLES_COUNT_THUNDER
|
|
|
|
else
|
2022-01-30 20:15:51 +00:00
|
|
|
psdef.amount=PARTICLES_COUNT_RAIN
|
2021-01-28 07:47:51 +00:00
|
|
|
mcl_weather.rain.particles_count = PARTICLES_COUNT_RAIN
|
|
|
|
end
|
2017-11-12 00:52:07 +00:00
|
|
|
end
|
|
|
|
|
2017-11-21 00:35:31 +00:00
|
|
|
if mcl_weather.allow_abm then
|
2017-03-02 17:18:59 +00:00
|
|
|
-- ABM for extinguish fire
|
2017-03-01 18:06:16 +00:00
|
|
|
minetest.register_abm({
|
2017-05-14 22:45:54 +00:00
|
|
|
label = "Rain extinguishes fire",
|
2017-03-02 17:18:59 +00:00
|
|
|
nodenames = {"mcl_fire:fire"},
|
2017-11-22 02:04:20 +00:00
|
|
|
interval = 2.0,
|
2017-03-02 17:18:59 +00:00
|
|
|
chance = 2,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
2020-05-09 13:59:39 +00:00
|
|
|
-- Fire is extinguished if in rain or one of 4 neighbors is in rain
|
2017-11-21 00:35:31 +00:00
|
|
|
if mcl_weather.rain.raining and mcl_weather.rain.extinguish_fire then
|
2020-05-09 13:59:39 +00:00
|
|
|
local around = {
|
|
|
|
{ x = 0, y = 0, z = 0 },
|
|
|
|
{ x = -1, y = 0, z = 0 },
|
|
|
|
{ x = 1, y = 0, z = 0 },
|
|
|
|
{ x = 0, y = 0, z = -1 },
|
|
|
|
{ x = 0, y = 0, z = 1 },
|
|
|
|
}
|
|
|
|
for a=1, #around do
|
|
|
|
local apos = vector.add(pos, around[a])
|
|
|
|
if mcl_weather.is_outdoor(apos) then
|
|
|
|
minetest.remove_node(pos)
|
|
|
|
minetest.sound_play("fire_extinguish_flame", {pos = pos, max_hear_distance = 8, gain = 0.1}, true)
|
|
|
|
return
|
|
|
|
end
|
2017-11-22 02:04:20 +00:00
|
|
|
end
|
2017-03-01 18:06:16 +00:00
|
|
|
end
|
2017-11-22 02:04:20 +00:00
|
|
|
end,
|
2017-03-02 17:18:59 +00:00
|
|
|
})
|
2017-03-01 18:06:16 +00:00
|
|
|
|
2017-03-02 17:18:59 +00:00
|
|
|
-- Slowly fill up cauldrons
|
2017-03-01 18:06:16 +00:00
|
|
|
minetest.register_abm({
|
2017-05-14 22:45:54 +00:00
|
|
|
label = "Rain fills cauldrons with water",
|
2017-03-01 18:06:16 +00:00
|
|
|
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)
|
2017-11-30 18:57:06 +00:00
|
|
|
-- Rain is equivalent to a water bottle
|
2017-11-21 00:35:31 +00:00
|
|
|
if mcl_weather.rain.raining and mcl_weather.is_outdoor(pos) then
|
2017-03-01 18:06:16 +00:00
|
|
|
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"})
|
2017-11-30 18:57:06 +00:00
|
|
|
elseif node.name == "mcl_cauldrons:cauldron_1r" then
|
2017-11-30 19:35:21 +00:00
|
|
|
minetest.set_node(pos, {name="mcl_cauldrons:cauldron_2r"})
|
2017-11-30 18:57:06 +00:00
|
|
|
elseif node.name == "mcl_cauldrons:cauldron_2r" then
|
|
|
|
minetest.set_node(pos, {name="mcl_cauldrons:cauldron_3r"})
|
2017-03-01 18:06:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-05-23 12:44:50 +00:00
|
|
|
})
|
2017-03-02 17:24:19 +00:00
|
|
|
|
|
|
|
-- Wetten the soil
|
|
|
|
minetest.register_abm({
|
2017-05-14 22:45:54 +00:00
|
|
|
label = "Rain hydrates farmland",
|
2017-03-02 17:24:19 +00:00
|
|
|
nodenames = {"mcl_farming:soil"},
|
2017-03-02 18:00:49 +00:00
|
|
|
interval = 22.0,
|
|
|
|
chance = 3,
|
2017-03-02 17:24:19 +00:00
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
2017-11-21 00:35:31 +00:00
|
|
|
if mcl_weather.rain.raining and mcl_weather.is_outdoor(pos) then
|
2017-03-02 17:24:19 +00:00
|
|
|
if node.name == "mcl_farming:soil" then
|
|
|
|
minetest.set_node(pos, {name="mcl_farming:soil_wet"})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-05-23 12:44:50 +00:00
|
|
|
})
|
2017-02-20 20:43:10 +00:00
|
|
|
end
|
2017-11-12 04:02:20 +00:00
|
|
|
|
2017-11-21 00:35:31 +00:00
|
|
|
if mcl_weather.reg_weathers.rain == nil then
|
2021-01-28 07:47:51 +00:00
|
|
|
mcl_weather.reg_weathers.rain = {
|
|
|
|
clear = mcl_weather.rain.clear,
|
|
|
|
light_factor = 0.6,
|
|
|
|
-- 10min - 20min
|
|
|
|
min_duration = 600,
|
|
|
|
max_duration = 1200,
|
|
|
|
transitions = {
|
|
|
|
[65] = "none",
|
|
|
|
[70] = "snow",
|
|
|
|
[100] = "thunder",
|
|
|
|
}
|
|
|
|
}
|
2017-11-12 04:02:20 +00:00
|
|
|
end
|