diff --git a/.luacheckrc b/.luacheckrc index c71b14a..3588de0 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -16,5 +16,5 @@ read_globals = { -- deps "epic", "epic_skybox", - "screwdriver", "areas" + "screwdriver", "areas", "soundblock" } diff --git a/init.lua b/init.lua index 998234b..241b49b 100644 --- a/init.lua +++ b/init.lua @@ -26,5 +26,9 @@ if minetest.get_modpath("epic_weather") then dofile(MP.."/integrations/epic_weather.lua") end +if minetest.get_modpath("soundblock") then + dofile(MP.."/integrations/soundblock.lua") +end + dofile(MP.."/integrations/day_night.lua") dofile(MP.."/integrations/no_clouds.lua") diff --git a/integrations/soundblock.lua b/integrations/soundblock.lua new file mode 100644 index 0000000..ad52337 --- /dev/null +++ b/integrations/soundblock.lua @@ -0,0 +1,74 @@ + +area_effects.register_effect("sound", "background-sound from /sound_list") + +-- playername -> sound-handle +local handles = {} + +area_effects.register_hook({ + enter = function(player, id) + local data = area_effects.get(id) + if data and data.sound then + for _, sounddef in pairs(soundblock.sounds) do + if sounddef.key == data.sound then + local playername = player:get_player_name() + minetest.log( + "action", + "[area_effects] setting sound " .. sounddef.key .. + " for player" .. playername + ) + local filename = sounddef.filename + if sounddef.filenames then + filename = sounddef.filenames[math.random(1, #sounddef.filenames)] + end + + local handle = minetest.sound_play(filename, { + to_player = playername, + gain = 1.0, + loop = true + }) + + handles[playername] = handle + + break + end + end + end + end, + + leave = function(player, id) + local data = area_effects.get(id) + if data and data.sound then + local playername = player:get_player_name() + minetest.log( + "action", + "[area_effects] clearing sound " .. + " for player" .. playername + ) + local handle = handles[playername] + if handle then + minetest.sound_stop(handle) + handles[playername] = nil + end + end + end +}) + + + +minetest.register_chatcommand("sound_list", { + description = "Lists all available sounds", + func = function() + local list = "" + for _, sounddef in pairs(soundblock.sounds) do + list = list .. sounddef.key .. "," + end + + return true, list + end +}) + +-- cleanup +minetest.register_on_leaveplayer(function(player) + local playername = player:get_player_name() + handles[playername] = nil +end) diff --git a/mod.conf b/mod.conf index 3e0d23e..29c5cb7 100644 --- a/mod.conf +++ b/mod.conf @@ -1,4 +1,4 @@ name = area_effects description = area based effects depends = areas -optional_depends = epic_skybox, epic_weather +optional_depends = epic_skybox, epic_weather, soundblock diff --git a/readme.md b/readme.md index 572af78..30edada 100644 --- a/readme.md +++ b/readme.md @@ -5,8 +5,14 @@ Area based effects * **/area_effects** lists all area effects +# Integrations + +Available integrations + ## Skybox (epic_skybox) +Mod: https://github.com/damocles-minetest/epic_skybox + * **/skybox_list** List available skyboxes * **/area_effect_set skybox Plain Black** Set * **/area_effect_get skybox** Get @@ -14,12 +20,25 @@ Area based effects ## day/night +Mod: _builtin_ + * **/area_effect_set day_night 0.4** ## Weather (epic_weather) +Mod: https://github.com/damocles-minetest/epic_weather + * **/area_effect_set weather Light rain** ## Clouds +Mod: _builtin_ + * **/area_effect_set no_clouds true** + +## Soundblock + +Mod: https://github.com/mt-mods/soundblock + +* **/area_effect_set sound damocles_soundblock_ambient_1** +* **/sound_list**