From 4eee09c3be1f60f726e6d4209265f2883dcd2e79 Mon Sep 17 00:00:00 2001 From: kaadmy Date: Fri, 2 Oct 2015 10:07:07 -0700 Subject: [PATCH] fixed flowing water sounds overlapping when multiple players are near, @asl97 --- mods/default/player.lua | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/mods/default/player.lua b/mods/default/player.lua index ef0ee4e..32d1e09 100644 --- a/mods/default/player.lua +++ b/mods/default/player.lua @@ -3,8 +3,11 @@ local player_lastsound = {} local player_health = {} local enable_flowing_water_sound = minetest.setting_getbool("enable_flowing_water_sound") +if enable_flowing_water_sound == nil then enable_flowing_water_sound = true end local function step(dtime) + local player_positions = {} + for _, player in ipairs(minetest.get_connected_players()) do local player_pos=player:getpos() local name=player:get_player_name() @@ -53,13 +56,24 @@ local function step(dtime) end elseif flowing_water_pos then if player_lastsound[name] > 3.3 then - player_soundspec[name]=minetest.sound_play( - "default_water", - { - pos = flowing_water_pos, - max_hear_distance = 16, - }) - player_lastsound[name] = 0 + + local c = true + for _, p in pairs(player_positions) do + if (p.x * player_pos.x) + (p.y * player_pos.y) + (p.z * player_pos.z) < 256 then + -- 256 is 16*16 for distance checking + c = false + end + end + + if c then + player_soundspec[name]=minetest.sound_play( + "default_water", + { + pos = flowing_water_pos, + max_hear_distance = 16, + }) + player_lastsound[name] = 0 + end end else if player_soundspec[name] ~= nil then @@ -76,6 +90,8 @@ local function step(dtime) minetest.set_node(grass_pos, {name = "default:dirt_with_grass_footsteps"}) end end + + table.insert(player_positions, player_pos) end end