From ede3123b1a0641d47cca419153da649388532e29 Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Fri, 10 Mar 2023 03:04:34 +0000 Subject: [PATCH 1/2] Remove music interruptions --- mods/PLAYER/mcl_music/init.lua | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/mods/PLAYER/mcl_music/init.lua b/mods/PLAYER/mcl_music/init.lua index 7bd0cfbbfd..b532b0be54 100644 --- a/mods/PLAYER/mcl_music/init.lua +++ b/mods/PLAYER/mcl_music/init.lua @@ -22,8 +22,6 @@ local dimension_to_base_track = { local listeners = {} -local weather_state - local function pick_track(dimension, underground) local track_key @@ -72,7 +70,7 @@ local function stop_music_for_all() end end -local function play_song(track, player_name, hp, dimension, day_count, underground) +local function play_song(track, player_name, hp, dimension, day_count) local spec = { name = track, gain = 0.3, @@ -90,17 +88,10 @@ local function play_song(track, player_name, hp, dimension, day_count, undergrou hp = hp, dimension = dimension, day_count = day_count, - underground = underground, } end local function play() - local new_weather_state = mcl_weather.get_weather() - local was_good_weather = weather_state == "none" or weather_state == "clear" - weather_state = new_weather_state - local is_good_weather = weather_state == "none" or weather_state == "clear" - local is_weather_changed = weather_state ~= new_weather_state - local time = minetest.get_timeofday() if time < 0.25 or time >= 0.75 then stop_music_for_all() @@ -116,34 +107,28 @@ local function play() local dimension = mcl_worlds.pos_to_dimension(pos) - local underground = dimension == "overworld" and pos and pos.y < 0 - local listener = listeners[player_name] local handle = listener and listener.handle local old_hp = listener and listener.hp local old_dimension = listener and listener.dimension - local old_underground = listener and listener.underground local is_dimension_changed = old_dimension and (old_dimension ~= dimension) or false local is_hp_changed = old_hp and (math.abs(old_hp - hp) > 0.00001) or false - local underground_changed = old_underground and underground ~= old_underground - --minetest.log("handle: " .. dump (handle)) - if is_hp_changed or is_dimension_changed or underground_changed - or (dimension == "overworld" and (is_weather_changed or not is_good_weather)) then + if is_hp_changed or is_dimension_changed then stop_music_for_listener_name(player_name) if not listeners[player_name] then listeners[player_name] = {} end listeners[player_name].hp = hp listeners[player_name].dimension = dimension - listeners[player_name].underground = underground elseif not handle and (not listener or (listener.day_count ~= day_count)) then + local underground = dimension == "overworld" and pos and pos.y < 0 local track = pick_track(dimension, underground) if track then - play_song(track, player_name, hp, dimension, day_count, underground) + play_song(track, player_name, hp, dimension, day_count) else --minetest.log("no track found. weird") end From 03d8363ed1bc1cfffb295b8765a73c622987a9aa Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Sat, 11 Mar 2023 22:16:55 +0000 Subject: [PATCH 2/2] Ensure HP change doesn't stop music --- mods/PLAYER/mcl_music/init.lua | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/mods/PLAYER/mcl_music/init.lua b/mods/PLAYER/mcl_music/init.lua index b532b0be54..5987d2140c 100644 --- a/mods/PLAYER/mcl_music/init.lua +++ b/mods/PLAYER/mcl_music/init.lua @@ -70,7 +70,7 @@ local function stop_music_for_all() end end -local function play_song(track, player_name, hp, dimension, day_count) +local function play_song(track, player_name, dimension, day_count) local spec = { name = track, gain = 0.3, @@ -85,7 +85,6 @@ local function play_song(track, player_name, hp, dimension, day_count) local handle = minetest.sound_play(spec, parameters, false) listeners[player_name] = { handle = handle, - hp = hp, dimension = dimension, day_count = day_count, } @@ -104,20 +103,19 @@ local function play() local player_name = player:get_player_name() local hp = player:get_hp() local pos = player:get_pos() - local dimension = mcl_worlds.pos_to_dimension(pos) local listener = listeners[player_name] local handle = listener and listener.handle - local old_hp = listener and listener.hp - local old_dimension = listener and listener.dimension + --local old_hp = listener and listener.hp + --local is_hp_changed = old_hp and (math.abs(old_hp - hp) > 0.00001) or false + local old_dimension = listener and listener.dimension local is_dimension_changed = old_dimension and (old_dimension ~= dimension) or false - local is_hp_changed = old_hp and (math.abs(old_hp - hp) > 0.00001) or false --minetest.log("handle: " .. dump (handle)) - if is_hp_changed or is_dimension_changed then + if is_dimension_changed then stop_music_for_listener_name(player_name) if not listeners[player_name] then listeners[player_name] = {} @@ -128,7 +126,7 @@ local function play() local underground = dimension == "overworld" and pos and pos.y < 0 local track = pick_track(dimension, underground) if track then - play_song(track, player_name, hp, dimension, day_count) + play_song(track, player_name, dimension, day_count) else --minetest.log("no track found. weird") end