Add initial environmental sounds mod with flowing water sounds
authorParamat <paramat@users.noreply.github.com>
Wed, 11 Sep 2019 23:46:40 +0000 (00:46 +0100)
committerGitHub <noreply@github.com>
Wed, 11 Sep 2019 23:46:40 +0000 (00:46 +0100)
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.

minetest.conf.example
mods/env_sounds/README.txt [new file with mode: 0644]
mods/env_sounds/init.lua [new file with mode: 0644]
mods/env_sounds/license.txt [new file with mode: 0644]
mods/env_sounds/mod.conf [new file with mode: 0644]
mods/env_sounds/sounds/env_sounds_water.1.ogg [new file with mode: 0644]
mods/env_sounds/sounds/env_sounds_water.2.ogg [new file with mode: 0644]
mods/env_sounds/sounds/env_sounds_water.3.ogg [new file with mode: 0644]
mods/env_sounds/sounds/env_sounds_water.4.ogg [new file with mode: 0644]
settingtypes.txt

index 452251e1c2f5467b2761429519fc983d646b185a..d1da0ff845d47b6688734d0a3bafdbd41fa486dc 100644 (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
diff --git a/mods/env_sounds/README.txt b/mods/env_sounds/README.txt
new file mode 100644 (file)
index 0000000..42835d2
--- /dev/null
@@ -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
diff --git a/mods/env_sounds/init.lua b/mods/env_sounds/init.lua
new file mode 100644 (file)
index 0000000..546e990
--- /dev/null
@@ -0,0 +1,64 @@
+-- Parameters
+
+local radius = 8 -- Water node search radius around player
+
+-- End of parameters
+
+
+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()
+       local ppos = player:get_pos()
+       local areamin = vector.subtract(ppos, radius)
+       local areamax = vector.add(ppos, radius)
+       local water_nodes = {"default:water_flowing", "default:river_water_flowing"}
+       if river_source_sounds then
+               table.insert(water_nodes, "default:river_water_source")
+       end
+       local wpos, _ = minetest.find_nodes_in_area(areamin, areamax, water_nodes)
+       local waters = #wpos
+       if waters == 0 then
+               return
+       end
+
+       -- Find average position of water positions
+       local wposav = vector.new()
+       for _, pos in ipairs(wpos) do
+               wposav.x = wposav.x + pos.x
+               wposav.y = wposav.y + pos.y
+               wposav.z = wposav.z + pos.z
+       end
+       wposav = vector.divide(wposav, waters)
+
+       minetest.sound_play(
+               "env_sounds_water",
+               {
+                       pos = wposav,
+                       to_player = player_name,
+                       gain = math.min(0.04 + waters * 0.004, 0.4),
+               }
+       )
+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)
diff --git a/mods/env_sounds/license.txt b/mods/env_sounds/license.txt
new file mode 100644 (file)
index 0000000..ff8867d
--- /dev/null
@@ -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/
diff --git a/mods/env_sounds/mod.conf b/mods/env_sounds/mod.conf
new file mode 100644 (file)
index 0000000..ad6feb3
--- /dev/null
@@ -0,0 +1,3 @@
+name = env_sounds
+description = Minetest Game mod: env_sounds
+depends = default
diff --git a/mods/env_sounds/sounds/env_sounds_water.1.ogg b/mods/env_sounds/sounds/env_sounds_water.1.ogg
new file mode 100644 (file)
index 0000000..aa80882
Binary files /dev/null and b/mods/env_sounds/sounds/env_sounds_water.1.ogg differ
diff --git a/mods/env_sounds/sounds/env_sounds_water.2.ogg b/mods/env_sounds/sounds/env_sounds_water.2.ogg
new file mode 100644 (file)
index 0000000..b3ff114
Binary files /dev/null and b/mods/env_sounds/sounds/env_sounds_water.2.ogg differ
diff --git a/mods/env_sounds/sounds/env_sounds_water.3.ogg b/mods/env_sounds/sounds/env_sounds_water.3.ogg
new file mode 100644 (file)
index 0000000..431a6ed
Binary files /dev/null and b/mods/env_sounds/sounds/env_sounds_water.3.ogg differ
diff --git a/mods/env_sounds/sounds/env_sounds_water.4.ogg b/mods/env_sounds/sounds/env_sounds_water.4.ogg
new file mode 100644 (file)
index 0000000..56c2ee2
Binary files /dev/null and b/mods/env_sounds/sounds/env_sounds_water.4.ogg differ
index 7f6a12badc4e05e0a8d81f40cc4d56c5afa272c6..6e3f4ab4d9a7623b2171d0ff236aaece46dd9a74 100644 (file)
@@ -64,3 +64,7 @@ enable_stairs_replace_abm (Replace old stairs) bool false
 #    If enabled, use the engine's spawn search which does not check for a
 #    suitable starting biome.
 engine_spawn (Use engine spawn search) bool false
+
+#    Whether river water source nodes create flowing sounds.
+#    Helps rivers create more sound, especially on level sections.
+river_source_sounds (River source node sounds) bool false