Struct RegistrationContext
pub struct RegistrationContext { /* private fields */ }Expand description
A registration phase’s view. Declarations go on the hook’s event; there is no world, handle constructor, transaction or game Host at this point.
Every registration hook (register, component_types, blocks, items,
standalone_models and the other Register* hooks) reads the same frozen view,
captured once before the first of them runs, so an answer never depends on
dispatch order or on which hook asks:
mods: the loaded packages.registry: the built-in registries, asregistries.jsonlists them. Entries that mods declare during registration are not in it; a mod already has its own declarations on its event or registrar.setting: the settings on disk for the loaded packages when registration began. Later writes are not seen.
use mod_api::{Host, RegistrationContext};
fn game(_: &dyn Host) {}
fn registration(context: &RegistrationContext) { game(context); }use mod_api::{prelude::EntitiesHost, RegistrationContext};
fn registration(context: &RegistrationContext) { let _ = EntitiesHost::entity(context, 1); }use mod_api::{HostTransaction, RegistrationContext};
fn registration(context: &mut RegistrationContext) {
let _: Result<(), ()> = context.transaction(|_, _| Ok(()));
}Implementations§
§impl RegistrationContext
impl RegistrationContext
pub fn instance_dir(&self) -> Result<&InstanceDirectory, RegistrationReadError>
pub fn instance_dir(&self) -> Result<&InstanceDirectory, RegistrationReadError>
The instance directory captured before registration, identically on native and wasm. This is data only, not permission to access a filesystem. The value preserves the host OS’s raw path encoding, including non-UTF-8 names.
pub fn mods(&self) -> &LoadedMods
pub fn mods(&self) -> &LoadedMods
The loaded-mod view, independent of this phase’s event or registrar.
§impl RegistrationContext
impl RegistrationContext
pub fn refuse(&self, reason: &str)
pub fn refuse(&self, reason: &str)
Refuse this mod’s registration with a diagnostic, without panicking.
The first reason wins. Reasons exceeding 4096 UTF-8 bytes are truncated
at a character boundary; shorter reasons are preserved verbatim.
All this mod’s declarations from this registration are discarded, including
later declarations, without adding their validation errors to the report.
Other mods’ declarations are unchanged. Native and wasm use the same
admission path. Returning from Hooks::register immediately is recommended.