Add initial environmental sounds mod with flowing water sounds

default:river_water_source can also create sound if desired as
rivers are considered to be flowing water.
A simple mod for now, with the intention to later use new engine
environmental sound features if/when they appear.
This commit is contained in:
paramat 2018-02-27 23:15:18 +00:00
parent e8097c9e87
commit 95fb14aa8e
9 changed files with 196 additions and 0 deletions

View file

@ -64,3 +64,7 @@ default:torch 99,default:cobble 99
# starting biome, is used.
# Default value is false.
#engine_spawn = false
# Whether river water source nodes create flowing sounds.
# Helps rivers create more sound, especially on level sections.
#river_source_sounds = false

View file

@ -0,0 +1,13 @@
Minetest Game mod: env_sounds
=============================
See license.txt for license information.
Authors of source code
----------------------
paramat (MIT)
Authors of media (sounds)
-------------------------
Yuval (CC0 1.0)
https://freesound.org/people/Yuval/sounds/197023/
env_sounds_water.*.ogg

View file

@ -0,0 +1 @@
default

121
mods/env_sounds/init.lua Normal file
View file

@ -0,0 +1,121 @@
-- Parameters
local radius = 8 -- Water node search radius around player
-- End of parameters
local handles = {}
local river_source_sounds = minetest.settings:get_bool("river_source_sounds")
-- Update sound for player
local function update_sound(player)
local player_name = player:get_player_name()
-- Search for water nodes in radius around player
local ppos = player:getpos()
local areamin = vector.subtract(ppos, radius)
local areamax = vector.add(ppos, radius)
local wpos, num
if river_source_sounds then
wpos, num = minetest.find_nodes_in_area(
areamin,
areamax,
{
"default:water_flowing",
"default:river_water_source",
"default:river_water_flowing"
}
)
else
wpos, num = minetest.find_nodes_in_area(
areamin,
areamax,
{
"default:water_flowing",
"default:river_water_flowing"
}
)
end
-- Total number of waters in radius
local waters = (num["default:water_flowing"] or 0) +
(num["default:river_water_source"] or 0) +
(num["default:river_water_flowing"] or 0)
-- If waters
if waters > 0 then
-- Find centre of water positions
local wposmid = wpos[1]
-- If more than 1 water
if #wpos > 1 then
local wposmin = areamax
local wposmax = areamin
for i = 1, #wpos do
local wposi = wpos[i]
if wposi.x > wposmax.x then
wposmax.x = wposi.x
end
if wposi.y > wposmax.y then
wposmax.y = wposi.y
end
if wposi.z > wposmax.z then
wposmax.z = wposi.z
end
if wposi.x < wposmin.x then
wposmin.x = wposi.x
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
-- Update sound 'on joinplayer'
minetest.register_on_joinplayer(function(player)
update_sound(player)
end)
-- Cyclic sound update
local function cyclic_update()
for _, player in pairs(minetest.get_connected_players()) do
update_sound(player)
end
minetest.after(3.5, cyclic_update)
end
minetest.after(0, cyclic_update)
-- Stop sound and clear handle on player leave
minetest.register_on_leaveplayer(function(player)
local player_name = player:get_player_name()
if handles[player_name] then
minetest.sound_stop(handles[player_name])
handles[player_name] = nil
end
end)

View file

@ -0,0 +1,57 @@
License of source code
----------------------
The MIT License (MIT)
Copyright (C) 2019 paramat
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
For more details:
https://opensource.org/licenses/MIT
Licenses of media (sounds)
--------------------------
CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
Yuval
No Copyright
The person who associated a work with this deed has dedicated the work to the
public domain by waiving all of his or her rights to the work worldwide under
copyright law, including all related and neighboring rights, to the extent
allowed by law.
You can copy, modify, distribute and perform the work, even for commercial
purposes, all without asking permission. See Other Information below.
Other Information:
In no way are the patent or trademark rights of any person affected by CC0, nor
are the rights that other persons may have in the work or in how the work is
used, such as publicity or privacy rights.
Unless expressly stated otherwise, the person who associated a work with this
deed makes no warranties about the work, and disclaims liability for all uses
of the work, to the fullest extent permitted by applicable law.
When using or citing the work, you should not imply endorsement by the author
or the affirmer.
For more details:
https://creativecommons.org/publicdomain/zero/1.0/

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.