forked from VoxeLibre/VoxeLibre
Import Paramat's 'env_sounds' from Minetest Game into MCL2.
This commit is contained in:
parent
e322a9e23a
commit
2f4a923d26
|
@ -0,0 +1,17 @@
|
||||||
|
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
|
||||||
|
|
||||||
|
Halion (CC0 1.0)
|
||||||
|
https://freesound.org/people/Halion/sounds/17785/
|
||||||
|
env_sounds_lava.*.ogg
|
|
@ -0,0 +1,114 @@
|
||||||
|
-- Parameters
|
||||||
|
|
||||||
|
-- Node search radius around player
|
||||||
|
local radius = 7
|
||||||
|
|
||||||
|
local allsounds = {
|
||||||
|
["env_sounds_water"] = {
|
||||||
|
trigger = {"mcl_core:water_flowing", "mclx_core:river_water_flowing"},
|
||||||
|
base_volume = 0.04,
|
||||||
|
max_volume = 0.4,
|
||||||
|
per_node = 0.004,
|
||||||
|
},
|
||||||
|
["env_sounds_lava"] = {
|
||||||
|
trigger = {"mcl_core:lava_source", "mcl_core:lava_flowing","mcl_nether:nether_lava_source", "mcl_nether:nether_lava_flowing"},
|
||||||
|
base_volume = 0.9,
|
||||||
|
max_volume = 2,
|
||||||
|
per_node = {
|
||||||
|
["mcl_core:lava_source"] = 0.08,
|
||||||
|
["mcl_core:lava_flowing"] = 0.08,
|
||||||
|
["mcl_nether:nether_lava_source"] = 0.08,
|
||||||
|
["mcl_nether:nether_lava_flowing"] = 0.08,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if minetest.settings:get_bool("river_source_sounds") then
|
||||||
|
table.insert(allsounds["env_sounds_water"].trigger,
|
||||||
|
"mclx_core:river_water_source")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- Cache the union of all trigger nodes
|
||||||
|
|
||||||
|
local cache_triggers = {}
|
||||||
|
|
||||||
|
for sound, def in pairs(allsounds) do
|
||||||
|
for _, name in ipairs(def.trigger) do
|
||||||
|
table.insert(cache_triggers, name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- Update sound for player
|
||||||
|
|
||||||
|
local function update_sound(player)
|
||||||
|
local player_name = player:get_player_name()
|
||||||
|
local ppos = player:get_pos()
|
||||||
|
ppos = vector.add(ppos, player:get_properties().eye_height)
|
||||||
|
local areamin = vector.subtract(ppos, radius)
|
||||||
|
local areamax = vector.add(ppos, radius)
|
||||||
|
|
||||||
|
local pos = minetest.find_nodes_in_area(areamin, areamax, cache_triggers, true)
|
||||||
|
if next(pos) == nil then -- If table empty
|
||||||
|
return
|
||||||
|
end
|
||||||
|
for sound, def in pairs(allsounds) do
|
||||||
|
-- Find average position
|
||||||
|
local posav = {0, 0, 0}
|
||||||
|
local count = 0
|
||||||
|
for _, name in ipairs(def.trigger) do
|
||||||
|
if pos[name] then
|
||||||
|
for _, p in ipairs(pos[name]) do
|
||||||
|
posav[1] = posav[1] + p.x
|
||||||
|
posav[2] = posav[2] + p.y
|
||||||
|
posav[3] = posav[3] + p.z
|
||||||
|
end
|
||||||
|
count = count + #pos[name]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if count > 0 then
|
||||||
|
posav = vector.new(posav[1] / count, posav[2] / count,
|
||||||
|
posav[3] / count)
|
||||||
|
|
||||||
|
-- Calculate gain
|
||||||
|
local gain = def.base_volume
|
||||||
|
if type(def.per_node) == 'table' then
|
||||||
|
for name, multiplier in pairs(def.per_node) do
|
||||||
|
if pos[name] then
|
||||||
|
gain = gain + #pos[name] * multiplier
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
gain = gain + count * def.per_node
|
||||||
|
end
|
||||||
|
gain = math.min(gain, def.max_volume)
|
||||||
|
|
||||||
|
minetest.sound_play(sound, {
|
||||||
|
pos = posav,
|
||||||
|
to_player = player_name,
|
||||||
|
gain = gain,
|
||||||
|
}, true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- Update sound when player joins
|
||||||
|
|
||||||
|
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(2.5, cyclic_update)
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.after(0, cyclic_update)
|
|
@ -0,0 +1,64 @@
|
||||||
|
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)
|
||||||
|
--------------------------
|
||||||
|
Water 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/
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
Title: env_sounds_lava.X.ogg
|
||||||
|
Author: Audionautics
|
||||||
|
Source: https://freesound.org/people/Audionautics/sounds/133901/
|
||||||
|
License: CC-By
|
|
@ -0,0 +1,3 @@
|
||||||
|
name = env_sounds
|
||||||
|
description = Minetest Game mod converted for use with MCL2: env_sounds
|
||||||
|
depends = mcl_core
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue