Attend to reviews, calculate average water position

This commit is contained in:
paramat 2019-09-10 00:34:25 +01:00
parent 95fb14aa8e
commit fe544f4ab5
3 changed files with 28 additions and 50 deletions

View file

@ -1 +0,0 @@
default

View file

@ -14,7 +14,7 @@ local river_source_sounds = minetest.settings:get_bool("river_source_sounds")
local function update_sound(player) local function update_sound(player)
local player_name = player:get_player_name() local player_name = player:get_player_name()
-- Search for water nodes in radius around player -- Search for water nodes in radius around player
local ppos = player:getpos() local ppos = player:get_pos()
local areamin = vector.subtract(ppos, radius) local areamin = vector.subtract(ppos, radius)
local areamax = vector.add(ppos, radius) local areamax = vector.add(ppos, radius)
local wpos, num local wpos, num
@ -39,54 +39,30 @@ local function update_sound(player)
) )
end end
-- Total number of waters in radius -- Total number of waters in radius
local waters = (num["default:water_flowing"] or 0) + local waters = #wpos
(num["default:river_water_source"] or 0) + if waters == 0 then
(num["default:river_water_flowing"] or 0) return
-- If waters end
if waters > 0 then
-- Find centre of water positions -- Find average position of water positions
local wposmid = wpos[1] local wposav = vector.new()
-- If more than 1 water for i, pos in ipairs(wpos) do
if #wpos > 1 then wposav = vector.add(wposav, pos)
local wposmin = areamax end
local wposmax = areamin wposav = vector.divide(wposav, waters)
for i = 1, #wpos do -- Play sound
local wposi = wpos[i] local handle = minetest.sound_play(
if wposi.x > wposmax.x then "env_sounds_water",
wposmax.x = wposi.x {
end pos = wposav,
if wposi.y > wposmax.y then to_player = player_name,
wposmax.y = wposi.y gain = math.min(0.04 + waters * 0.004, 0.4),
end max_hear_distance = 32,
if wposi.z > wposmax.z then }
wposmax.z = wposi.z )
end -- Store sound handle for this player
if wposi.x < wposmin.x then if handle then
wposmin.x = wposi.x handles[player_name] = handle
end
if wposi.y < wposmin.y then
wposmin.y = wposi.y
end
if wposi.z < wposmin.z then
wposmin.z = wposi.z
end
end
wposmid = vector.divide(vector.add(wposmin, wposmax), 2)
end
-- Play sound
local handle = minetest.sound_play(
"env_sounds_water",
{
pos = wposmid,
to_player = player_name,
gain = math.min(0.04 + waters * 0.004, 0.4),
max_hear_distance = 32,
}
)
-- Store sound handle for this player
if handle then
handles[player_name] = handle
end
end end
end end

3
mods/env_sounds/mod.conf Normal file
View file

@ -0,0 +1,3 @@
name = env_sounds
description = Minetest Game mod: env_sounds
depends = default