Fix mcl_music: play to all players, play every day, overworld only

This commit is contained in:
kay27 2022-01-21 18:49:16 +04:00 committed by Gitea
parent 419d61edde
commit 1894d8c5f0
2 changed files with 32 additions and 28 deletions

View File

@ -25,6 +25,11 @@ local function stop()
end end
local function play() local function play()
local spec = {
name = pianowtune,
gain = 0.3,
pitch = 1.0,
}
local new_weather_state = mcl_weather.get_weather() local new_weather_state = mcl_weather.get_weather()
local was_good_weather = weather_state == "none" or weather_state == "clear" local was_good_weather = weather_state == "none" or weather_state == "clear"
weather_state = new_weather_state weather_state = new_weather_state
@ -32,45 +37,44 @@ local function play()
local is_weather_changed = weather_state ~= new_weather_state local is_weather_changed = weather_state ~= new_weather_state
if is_weather_changed or not is_good_weather then if is_weather_changed or not is_good_weather then
stop() stop()
minetest.after(20, play)
return return
end end
local time = minetest.get_timeofday() local time = minetest.get_timeofday()
if time < 0.2 or time >= 0.8 then if time < 0.25 or time >= 0.75 then
stop() stop()
minetest.after(10, play)
return return
end end
for _, player in pairs(minetest.get_connected_players()) do for _, player in pairs(minetest.get_connected_players()) do
local player_name = player:get_player_name() local player_name = player:get_player_name()
local listener = listeners[player_name] local hp = player:get_hp()
local old_hp = listener and listener.hp local pos = player:get_pos()
local hp = player:get_hp() local listener = listeners[player_name]
local old_hp = listener and listener.hp
local dimension = mcl_worlds.pos_to_dimension(pos)
local is_hp_changed = old_hp and math.abs(old_hp - hp) > 0.00001 local is_hp_changed = old_hp and math.abs(old_hp - hp) > 0.00001
local handle = listener and listener.handle local handle = listener and listener.handle
if is_hp_changed and handle then if is_hp_changed then
stop_music_for_listener_name(player_name) stop_music_for_listener_name(player_name)
return listeners[player_name].hp = hp
elseif dimension ~= "overworld" then
stop_music_for_listener_name(player_name)
elseif not handle then
local parameters = {
to_player = player_name,
gain = 1.0,
fade = 0.0,
pitch = 1.0,
}
handle = minetest.sound_play(spec, parameters, false)
listeners[player_name] = {
spec = spec,
parameters = parameters,
handle = handle,
hp = hp,
}
end end
if handle then
return
end
local spec = {
name = pianowtune,
gain = 0.3,
pitch = 1.0,
}
local parameters = {
to_player = player_name,
gain = 1.0,
fade = 0.0,
pitch = 1.0,
}
handle = minetest.sound_play(spec, parameters, false)
listeners[player_name] = {
spec = spec,
parameters = parameters,
handle = handle,
hp = hp,
}
end end
minetest.after(7, play) minetest.after(7, play)

View File

@ -1,4 +1,4 @@
name = mcl_music name = mcl_music
author = diminixed, kay27 author = diminixed, kay27
description = Mod check some conditions and plays music description = Mod check some conditions and plays music
depends = mcl_player, mcl_weather depends = mcl_player, mcl_weather, mcl_worlds