2022-02-27 17:02:10 +01:00
|
|
|
local modpath = minetest.get_modpath("sound_api")
|
2022-01-19 04:29:18 +01:00
|
|
|
|
2022-01-30 02:46:20 +01:00
|
|
|
sound_api = dofile(modpath .. "/sound_api_core/init.lua")
|
|
|
|
|
2022-08-12 06:31:57 +02:00
|
|
|
local function validate_sound(key)
|
|
|
|
if key and sound_api[key] then
|
|
|
|
return true
|
|
|
|
elseif key then
|
|
|
|
minetest.log("warning", "attempted to call invalid sound: "..key)
|
|
|
|
else
|
|
|
|
minetest.log("warning", "sound_def is missing a sound_api key")
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2022-01-30 02:46:20 +01:00
|
|
|
minetest.register_on_mods_loaded(function()
|
|
|
|
for name, def in pairs(minetest.registered_nodes) do
|
2022-08-12 06:31:57 +02:00
|
|
|
if def._sound_def and validate_sound(def._sound_def.key) then
|
2022-01-30 02:46:20 +01:00
|
|
|
minetest.override_item(name, {
|
|
|
|
sounds = sound_api[def._sound_def.key](def._sound_def.input)
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local old_reg_node = minetest.register_node
|
|
|
|
function minetest.register_node(name, def)
|
2022-08-12 06:31:57 +02:00
|
|
|
if def._sound_def and validate_sound(def._sound_def.key) then
|
2022-01-30 02:46:20 +01:00
|
|
|
def.sounds = sound_api[def._sound_def.key](def._sound_def.input)
|
|
|
|
end
|
|
|
|
|
|
|
|
old_reg_node(name, def)
|
|
|
|
end
|
2022-08-12 06:31:57 +02:00
|
|
|
end)
|