Mod Dependency Management

A mod has the ability to depend on other mods, either required dependencies or optional dependencies. These are specified as comma separated lists in the mod's mod.conf file, depends and optional_depends respectively.

A mod's dependencies get loaded before the mod, such that API functions get defined and are available for use. If no mods have dependencies, mod loading order goes in reverse alphabetical order (undocumented).

Required dependencies

Required dependencies need to be resolved for a mod to be allowed. You can always rely on these depending mods to exist. In recent versions of Minetest, the game will refuse to load if a player attempts to load a mod with unresolved required dependencies. If your mod gets installed from the main menu content browser, it will attempt to also download required dependencies.

Optional dependencies

Optional dependencies can be used to provide additional functionality if a mod exists. If you want to use API functions of the mod, you will need to check if the mod exists using minetest.get_modpath (it will return nil if the mod isn't loaded).

if minetest.get_modpath('optionally_dependant_mod') then
    -- Code for when optionally_dependant_mod exists
end

Game Support

In order to support several games, you would want to optionally depend on each game's specific mods. For example:

if minetest.get_modpath("default") then
    -- Code path for Minetest Game
elseif minetest.get_modpath("mcl_core") then
    -- Code path for MineClone 2
end