xcompat-cd2025/init.lua

40 lines
1.2 KiB
Lua
Raw Normal View History

2024-02-25 00:10:30 -05:00
local modpath = minetest.get_modpath("xcompat")
2022-01-18 22:29:18 -05:00
2024-02-25 00:10:30 -05:00
xcompat = {
sounds = dofile(modpath .. "/src/sounds.lua"),
materials = dofile(modpath .. "/src/materials.lua"),
}
--this exists for legacy compat reasons
sound_api = xcompat.sounds -- luacheck: ignore
2022-01-29 20:46:20 -05:00
local function validate_sound(key)
2024-02-25 00:10:30 -05:00
if key and xcompat.sounds[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-29 20:46:20 -05:00
minetest.register_on_mods_loaded(function()
for name, def in pairs(minetest.registered_nodes) do
if def._sound_def and validate_sound(def._sound_def.key) then
2022-01-29 20:46:20 -05:00
minetest.override_item(name, {
2024-02-25 00:10:30 -05:00
sounds = xcompat.sounds[def._sound_def.key](def._sound_def.input)
2022-01-29 20:46:20 -05:00
})
end
end
local old_reg_node = minetest.register_node
function minetest.register_node(name, def)
if def._sound_def and validate_sound(def._sound_def.key) then
2024-02-25 00:10:30 -05:00
def.sounds = xcompat.sounds[def._sound_def.key](def._sound_def.input)
2022-01-29 20:46:20 -05:00
end
old_reg_node(name, def)
end
end)