Skip to main content

ConfigHost

Trait ConfigHost 

pub trait ConfigHost {
    // Provided methods
    fn on(&self, mod_id: &str) -> bool { ... }
    fn setting(&self, mod_id: &str, key: &str) -> Option<String> { ... }
    fn set_setting(&self, mod_id: &str, key: &str, value: &str) { ... }
    fn config_files(&self) -> &'static dyn ConfigFiles { ... }
    fn dimension(&self) -> &'static str { ... }
    fn instance_dir(&self) -> PathBuf { ... }
}
Expand description

The host’s methods both sides share of the config area, implemented by the game and reached through Host.

Provided Methods§

fn on(&self, mod_id: &str) -> bool

Side: both. Whether the player left mod mod_id on in Options > Mods. A mod turned off does nothing (check this first in each hook) until the launcher’s next build leaves it out.

fn setting(&self, mod_id: &str, key: &str) -> Option<String>

Side: both. A mod’s setting key (one file per key in native_data_dir). A mod reads only its own: another mod’s id or a key not registered by that owner gives None.

fn set_setting(&self, mod_id: &str, key: &str, value: &str)

Side: both. Keeps a mod’s registered setting key. Another mod’s id or an unregistered key keeps nothing. A successful write invalidates the typed read cache for this data folder and key; a failed write leaves it unchanged. This raw write does not fire setting_changed.

fn config_files(&self) -> &'static dyn ConfigFiles

Side: both. The calling mod’s own files in the game’s config/ folder, beside options.txt (beside server.properties on a dedicated server): its folder config/<mod id>/ and the files beside it named <mod id>.<ext> or <mod id>-<rest>, as Fabric and NeoForge mods keep theirs. The service is bound to the mod whose hook or part is running, so a mod never names its id and can’t reach another mod’s files; a world’s serverconfig/ is read only through config_loading.

fn dimension(&self) -> &'static str

Side: both. The level in place (minecraft:overworld), for a hook that isn’t told which it runs in.

fn instance_dir(&self) -> PathBuf

Side: both. The instance (game) folder, which its players share: saves/, resourcepacks/, shaderpacks/ and horizon-mods/ are in it, and the title’s screens create worlds and read packs there. A world’s own datapacks/ is in that world’s folder (saves/<world>/datapacks). The folder the game runs in (--player-dir moves a player’s options and servers only, not the instance). Nothing is created.

Not on wasm: a path in the game’s file system, which a wasm mod has none of; a wasm mod reads its own data and assets through reload listeners.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§