Mod
ll/api/mod/ Β· Common
Overview
The Mod module manages mod lifecycle, metadata (manifest), directory structure, and provides access to mod-specific resources like loggers, config directories, and data directories.
| Header |
Description |
ll/api/mod/Mod.h |
Mod instance and lifecycle |
ll/api/mod/Manifest.h |
Mod metadata structure |
ll/api/mod/ModManager.h |
Base mod manager |
ll/api/mod/ModManagerRegistry.h |
Registry of all mod managers |
ll/api/mod/NativeMod.h |
Native (DLL) mod implementation |
Key Classes
Mod
Represents a loaded mod with lifecycle callbacks and resource access.
| C++ |
|---|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 | namespace ll::mod {
class Mod {
public:
enum class State { Enabled, Disabled };
State getState() const;
Manifest const& getManifest() const;
std::string const& getName() const;
std::string const& getType() const;
std::filesystem::path const& getModDir() const;
std::filesystem::path const& getDataDir() const;
std::filesystem::path const& getConfigDir() const;
std::optional<std::filesystem::path> getWorldDataDir() const;
std::optional<std::filesystem::path> getWorldConfigDir() const;
std::filesystem::path const& getLangDir() const;
std::filesystem::path const& getResourceDir() const;
std::filesystem::path const& getBehaviorDir() const;
io::Logger& getLogger() const;
bool isEnabled() const;
bool isDisabled() const;
void onLoad(CallbackFn func) noexcept;
void onUnload(CallbackFn func) noexcept;
void onEnable(CallbackFn func) noexcept;
void onDisable(CallbackFn func) noexcept;
};
std::filesystem::path const& getModsRoot();
}
|
Manifest
Mod metadata loaded from manifest.json.
| C++ |
|---|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 | namespace ll::mod {
struct Dependency {
std::string name;
std::optional<data::Version> version;
};
struct Manifest {
std::string entry;
std::string name;
std::string type;
std::optional<std::string> platform;
std::optional<bool> passive;
std::optional<data::Version> version;
std::optional<std::string> author;
std::optional<std::string> description;
std::optional<SmallStringMap<std::string>> extraInfo;
std::optional<SmallDenseSet<Dependency>> dependencies;
std::optional<SmallDenseSet<Dependency>> optionalDependencies;
std::optional<SmallDenseSet<Dependency>> conflicts;
std::optional<SmallDenseSet<Dependency>> loadBefore;
};
}
|
Usage
Accessing Mod Instance
| C++ |
|---|
| #include "ll/api/mod/NativeMod.h"
ll::mod::NativeMod& getSelfMod() {
return ll::mod::NativeMod::current();
}
|
Using Mod Resources
| C++ |
|---|
| #include "ll/api/mod/Mod.h"
void setupMod(ll::mod::Mod& mod) {
auto& logger = mod.getLogger();
logger.info("Mod name: {}", mod.getName());
auto configPath = mod.getConfigDir() / "config.json";
auto dataPath = mod.getDataDir() / "database.db";
auto langPath = mod.getLangDir() / "en_US.json";
}
|
Lifecycle Callbacks
| C++ |
|---|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 | #include "ll/api/mod/Mod.h"
void registerCallbacks(ll::mod::Mod& mod) {
mod.onLoad([](ll::mod::Mod& self) -> bool {
self.getLogger().info("Mod loading");
return true; // Return false to abort load
});
mod.onEnable([](ll::mod::Mod& self) -> bool {
self.getLogger().info("Mod enabled");
return true;
});
mod.onDisable([](ll::mod::Mod& self) -> bool {
self.getLogger().info("Mod disabled");
return true;
});
mod.onUnload([](ll::mod::Mod& self) -> bool {
self.getLogger().info("Mod unloading");
return true;
});
}
|
Directory Structure
Each mod has the following directory structure:
| Text Only |
|---|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 | mods/
βββ MyMod/
βββ manifest.json # Mod metadata
βββ MyMod.dll # Mod binary
βββ config/ # Config files (getConfigDir())
βββ data/ # Persistent data (getDataDir())
βββ lang/ # Translations (getLangDir())
βββ resources/ # Resource packs (getResourceDir())
βββ behavior/ # Behavior packs (getBehaviorDir())
worlds/
βββ Bedrock level/
βββ plugins/
βββ MyMod/
βββ config/ # World-specific config (getWorldConfigDir())
βββ data/ # World-specific data (getWorldDataDir())
|
- Config β Use
getConfigDir() for config file location
- Data β Use
getDataDir() for database storage
- I18n β Use
getLangDir() for translation files
- IO & Logger β
getLogger() returns the mod's logger