diff --git a/mods/ambiance/README.txt b/mods/ambiance/README.txt new file mode 100644 index 0000000..c932d4e --- /dev/null +++ b/mods/ambiance/README.txt @@ -0,0 +1,10 @@ +Ambiance mod +============ +By Kaadmy, for Pixture + +Adds directional ambient sounds coming from the correct sources. + +Sound license: + ambiance_birds.ogg: CC0, by syncopika(http://opengameart.org/users/syncopika) + ambiance_crickets.ogg: CC0, by syncopika(http://opengameart.org/users/syncopika) +Source license: WTFPL diff --git a/mods/ambiance/depends.txt b/mods/ambiance/depends.txt new file mode 100644 index 0000000..4ad96d5 --- /dev/null +++ b/mods/ambiance/depends.txt @@ -0,0 +1 @@ +default diff --git a/mods/ambiance/init.lua b/mods/ambiance/init.lua new file mode 100644 index 0000000..e250925 --- /dev/null +++ b/mods/ambiance/init.lua @@ -0,0 +1,139 @@ +-- +-- Ambiance mod +-- By Kaadmy, for Pixture +-- + +ambiance = {} + +ambiance.sounds = {} + +ambiance.sounds["birds"] = { + length = 5.0, + chance = 4, + file = "ambiance_birds", + dist = 8, + nodename = "group:leaves", + can_play = function(pos) + local tod = (minetest.get_timeofday() or 1) * 2 + + if tod > 0.47 and tod < 1.53 then -- bit of overlap into crickets + return true + end + + return false + end, +} + +ambiance.sounds["crickets"] = { + length = 6.0, + chance = 3, + file = "ambiance_crickets", + dist = 8, + nodename = "group:grass", + can_play = function(pos) + local tod = (minetest.get_timeofday() or 1) * 2 + + if tod < 0.5 or tod > 1.5 then + return true + end + + return false + end, +} + +ambiance.sounds["flowing_water"] = { + length = 3.3, + chance = 1, + file = "default_water", + dist = 16, + nodename = "group:flowing_water", +} + +local ambiance_volume = tonumber(minetest.setting_get("ambiance_volume")) or 1.0 + +local soundspec = {} +local lastsound = {} + +local function ambient_node_near(sound, pos) local nodepos = minetest.find_node_near(pos, sound.dist, sound.nodename) + + if nodepos ~= nil and math.random(1, sound.chance) == 1 then + return nodepos + end + + return nil +end + +local function step(dtime) + local player_positions = {} + + for _, player in ipairs(minetest.get_connected_players()) do + local pos = player:getpos() + local name = player:get_player_name() + + + for soundname, sound in pairs(ambiance.sounds) do + if lastsound[name][soundname] then + lastsound[name][soundname] = lastsound[name][soundname] + dtime + else + lastsound[name][soundname] = 0 + end + + if lastsound[name][soundname] > sound.length then + local sourcepos = ambient_node_near(sound, pos) + + if sound.can_play and sourcepos ~= nil and (not sound.can_play(sourcepos)) then + sourcepos = nil + end + + if sourcepos == nil then + if soundspec[name][soundname] then + minetest.sound_stop(soundspec[name][soundname]) + + soundspec[name][soundname] = nil + lastsound[name][soundname] = 0 + end + else + local ok = true + for _, p in pairs(player_positions) do + if (p.x * pos.x) + (p.y * pos.y) + (p.z * pos.z) < sound.dist*sound.dist then + ok = false + end + end + + if ok then + soundspec[name][soundname] = minetest.sound_play( + sound.file, + { + pos = sourcepos, + max_hear_distance = sound.dist, + }) + + lastsound[name][soundname] = 0 + end + end + end + end + + table.insert(player_positions, pos) + end +end + +local function on_joinplayer(player) + local name = player:get_player_name() + + soundspec[name] = {} + lastsound[name] = {} +end + +local function on_leaveplayer(player) + local name = player:get_player_name() + + soundspec[name] = nil + lastsound[name] = nil +end + +minetest.register_on_joinplayer(on_joinplayer) +minetest.register_on_leaveplayer(on_leaveplayer) +minetest.register_globalstep(step) + +default.log("mod:ambiance", "loaded") \ No newline at end of file diff --git a/mods/ambiance/sounds/ambiance_birds.ogg b/mods/ambiance/sounds/ambiance_birds.ogg new file mode 100644 index 0000000..f131c03 Binary files /dev/null and b/mods/ambiance/sounds/ambiance_birds.ogg differ diff --git a/mods/weather/sounds/weather_night.ogg b/mods/ambiance/sounds/ambiance_crickets.ogg similarity index 100% rename from mods/weather/sounds/weather_night.ogg rename to mods/ambiance/sounds/ambiance_crickets.ogg diff --git a/mods/default/nodes.lua b/mods/default/nodes.lua index a7dd9aa..adad908 100644 --- a/mods/default/nodes.lua +++ b/mods/default/nodes.lua @@ -1258,7 +1258,7 @@ minetest.register_node( waving = 1, walkable = false, buildable_to = true, - groups = {snappy = 2, dig_immediate = 3, attached_node = 1}, + groups = {snappy = 2, dig_immediate = 3, attached_node = 1, grass = 1}, sounds = default.node_sound_leaves_defaults(), }) @@ -1299,7 +1299,7 @@ minetest.register_node( waving = 1, walkable = false, buildable_to = true, - groups = {snappy=2,dig_immediate=3,attached_node=1}, + groups = {snappy = 2, dig_immediate = 3, attached_node = 1, grass = 1}, sounds = default.node_sound_leaves_defaults(), }) @@ -1320,7 +1320,7 @@ minetest.register_node( waving = 1, walkable = false, buildable_to = true, - groups = {snappy=2,dig_immediate=3,attached_node=1}, + groups = {snappy = 2, dig_immediate = 3, attached_node = 1, grass = 1}, sounds = default.node_sound_leaves_defaults(), }) @@ -1341,7 +1341,7 @@ minetest.register_node( waving = 1, walkable = false, buildable_to = true, - groups = {snappy=2,dig_immediate=3,attached_node=1}, + groups = {snappy = 2, dig_immediate = 3, attached_node = 1, grass = 1}, sounds = default.node_sound_leaves_defaults(), }) @@ -1363,7 +1363,7 @@ minetest.register_node( waving = 1, walkable = false, buildable_to = true, - groups = {snappy=2,dig_immediate=3,attached_node=1}, + groups = {snappy = 2, dig_immediate = 3, attached_node = 1, grass = 1}, sounds = default.node_sound_leaves_defaults(), }) diff --git a/mods/default/player.lua b/mods/default/player.lua index e6fe802..d7367c7 100644 --- a/mods/default/player.lua +++ b/mods/default/player.lua @@ -5,9 +5,6 @@ local player_lastpos = {} local particlespawners = {} -local enable_flowing_water_sound = minetest.setting_getbool("enable_flowing_water_sound") -if enable_flowing_water_sound == nil then enable_flowing_water_sound = true end - local function step(dtime) local player_positions = {} @@ -44,11 +41,6 @@ local function step(dtime) player_lastsound[name] = player_lastsound[name] + dtime - local flowing_water_pos = nil - if enable_flowing_water_sound then - flowing_water_pos = minetest.find_node_near(player_pos, 16, "group:flowing_water") - end - if nodename == "default:water_source" or nodename == "default:river_water_source" then if player_lastsound[name] > 3.3 then player_soundspec[name]=minetest.sound_play( @@ -78,27 +70,6 @@ local function step(dtime) }) minetest.after(0.15, function() minetest.delete_particlespawner(particlespawners[name]) end) - elseif flowing_water_pos then - if player_lastsound[name] > 3.3 then - - local c = true - for _, p in pairs(player_positions) do - if (p.x * player_pos.x) + (p.y * player_pos.y) + (p.z * player_pos.z) < 256 then - -- 256 is 16*16 for distance checking - c = false - end - end - - if c then - player_soundspec[name]=minetest.sound_play( - "default_water", - { - pos = flowing_water_pos, - max_hear_distance = 16, - }) - player_lastsound[name] = 0 - end - end else if player_soundspec[name] ~= nil then minetest.sound_stop(player_soundspec[name]) diff --git a/mods/weather/README.txt b/mods/weather/README.txt index 78f7c26..b5e80cd 100644 --- a/mods/weather/README.txt +++ b/mods/weather/README.txt @@ -4,7 +4,6 @@ By Kaadmy, for Pixture Texture license: WTFPL Sound license: - weather_night.ogg: CC0 weather_storm.ogg: GPLv2(Replace this, I want CC0/WTFPL-only assets) weather_snowstorm.ogg: GPLv2(Replace this, I want CC0/WTFPL-only assets) Source license: WTFPL diff --git a/mods/weather/init.lua b/mods/weather/init.lua index 81a09da..3230368 100644 --- a/mods/weather/init.lua +++ b/mods/weather/init.lua @@ -21,30 +21,7 @@ local function play_sound() minetest.sound_stop(weather_soundspec) end - local timeofday=minetest.get_timeofday() - - if timeofday == nil then - timeofday=1 - end - - timeofday=timeofday*2 - - if weather.weather == "clear" then - if (timeofday > 0.4 and timeofday < 0.5) or (timeofday > 1.5 and timeofday < 1.6) then - -- dusk and dawn - weather_soundspec=minetest.sound_play({name="weather_night", gain=0.5}) - minetest.after(12, play_sound) - - return - elseif (timeofday < 0.4 or timeofday > 1.6) then - -- night - weather_soundspec=minetest.sound_play({name="weather_night", gain=0.3}) - minetest.after(12, play_sound) - - return - end - -- daytime - elseif weather.weather == "storm" then + if weather.weather == "storm" then weather_soundspec=minetest.sound_play({name="weather_storm"}) minetest.after(18, play_sound)