Skip to content

Commit ea992bd

Browse files
authoredSep 11, 2019
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.
1 parent bb9279c commit ea992bd

10 files changed

+145
-0
lines changed
 

‎minetest.conf.example

+4
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,7 @@ default:torch 99,default:cobble 99
6464
# starting biome, is used.
6565
# Default value is false.
6666
#engine_spawn = false
67+
68+
# Whether river water source nodes create flowing sounds.
69+
# Helps rivers create more sound, especially on level sections.
70+
#river_source_sounds = false

‎mods/env_sounds/README.txt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Minetest Game mod: env_sounds
2+
=============================
3+
See license.txt for license information.
4+
5+
Authors of source code
6+
----------------------
7+
paramat (MIT)
8+
9+
Authors of media (sounds)
10+
-------------------------
11+
Yuval (CC0 1.0)
12+
https://freesound.org/people/Yuval/sounds/197023/
13+
env_sounds_water.*.ogg

‎mods/env_sounds/init.lua

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
-- Parameters
2+
3+
local radius = 8 -- Water node search radius around player
4+
5+
-- End of parameters
6+
7+
8+
local river_source_sounds = minetest.settings:get_bool("river_source_sounds")
9+
10+
11+
-- Update sound for player
12+
13+
local function update_sound(player)
14+
local player_name = player:get_player_name()
15+
local ppos = player:get_pos()
16+
local areamin = vector.subtract(ppos, radius)
17+
local areamax = vector.add(ppos, radius)
18+
local water_nodes = {"default:water_flowing", "default:river_water_flowing"}
19+
if river_source_sounds then
20+
table.insert(water_nodes, "default:river_water_source")
21+
end
22+
local wpos, _ = minetest.find_nodes_in_area(areamin, areamax, water_nodes)
23+
local waters = #wpos
24+
if waters == 0 then
25+
return
26+
end
27+
28+
-- Find average position of water positions
29+
local wposav = vector.new()
30+
for _, pos in ipairs(wpos) do
31+
wposav.x = wposav.x + pos.x
32+
wposav.y = wposav.y + pos.y
33+
wposav.z = wposav.z + pos.z
34+
end
35+
wposav = vector.divide(wposav, waters)
36+
37+
minetest.sound_play(
38+
"env_sounds_water",
39+
{
40+
pos = wposav,
41+
to_player = player_name,
42+
gain = math.min(0.04 + waters * 0.004, 0.4),
43+
}
44+
)
45+
end
46+
47+
48+
-- Update sound 'on joinplayer'
49+
50+
minetest.register_on_joinplayer(function(player)
51+
update_sound(player)
52+
end)
53+
54+
55+
-- Cyclic sound update
56+
57+
local function cyclic_update()
58+
for _, player in pairs(minetest.get_connected_players()) do
59+
update_sound(player)
60+
end
61+
minetest.after(3.5, cyclic_update)
62+
end
63+
64+
minetest.after(0, cyclic_update)

‎mods/env_sounds/license.txt

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
License of source code
2+
----------------------
3+
4+
The MIT License (MIT)
5+
Copyright (C) 2019 paramat
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy of this
8+
software and associated documentation files (the "Software"), to deal in the Software
9+
without restriction, including without limitation the rights to use, copy, modify, merge,
10+
publish, distribute, sublicense, and/or sell copies of the Software, and to permit
11+
persons to whom the Software is furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all copies or
14+
substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
17+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
18+
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
19+
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21+
DEALINGS IN THE SOFTWARE.
22+
23+
For more details:
24+
https://opensource.org/licenses/MIT
25+
26+
27+
Licenses of media (sounds)
28+
--------------------------
29+
30+
CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
31+
Yuval
32+
33+
No Copyright
34+
35+
The person who associated a work with this deed has dedicated the work to the
36+
public domain by waiving all of his or her rights to the work worldwide under
37+
copyright law, including all related and neighboring rights, to the extent
38+
allowed by law.
39+
40+
You can copy, modify, distribute and perform the work, even for commercial
41+
purposes, all without asking permission. See Other Information below.
42+
43+
Other Information:
44+
45+
In no way are the patent or trademark rights of any person affected by CC0, nor
46+
are the rights that other persons may have in the work or in how the work is
47+
used, such as publicity or privacy rights.
48+
49+
Unless expressly stated otherwise, the person who associated a work with this
50+
deed makes no warranties about the work, and disclaims liability for all uses
51+
of the work, to the fullest extent permitted by applicable law.
52+
53+
When using or citing the work, you should not imply endorsement by the author
54+
or the affirmer.
55+
56+
For more details:
57+
https://creativecommons.org/publicdomain/zero/1.0/

‎mods/env_sounds/mod.conf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name = env_sounds
2+
description = Minetest Game mod: env_sounds
3+
depends = default
78.3 KB
Binary file not shown.
82.7 KB
Binary file not shown.
81.9 KB
Binary file not shown.
80.3 KB
Binary file not shown.

‎settingtypes.txt

+4
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,7 @@ enable_stairs_replace_abm (Replace old stairs) bool false
6464
# If enabled, use the engine's spawn search which does not check for a
6565
# suitable starting biome.
6666
engine_spawn (Use engine spawn search) bool false
67+
68+
# Whether river water source nodes create flowing sounds.
69+
# Helps rivers create more sound, especially on level sections.
70+
river_source_sounds (River source node sounds) bool false

0 commit comments

Comments
 (0)
Please sign in to comment.