pub struct PluginRegistrar<'a> { /* private fields */ }Expand description
Plugin registration interface for events, commands, and systems.
Holds mutable references to both the network and game event buses.
Handler registration is routed automatically based on the event
type’s EventRouting::BUS constant — plugins do not specify
which loop handles their events.
World and recipe fields are trait objects so that basalt-api does not depend on concrete runtime types at the struct level. Call sites coerce concrete types to the trait objects when constructing the registrar.
Implementations§
Source§impl<'a> PluginRegistrar<'a>
impl<'a> PluginRegistrar<'a>
Sourcepub fn new(
instant_bus: &'a mut EventBus,
game_bus: &'a mut EventBus,
commands: &'a mut Vec<CommandEntry>,
systems: &'a mut Vec<SystemDescriptor>,
world: Arc<dyn WorldHandle + Send + Sync>,
recipes: &'a mut dyn RecipeRegistryHandle,
bootstrap_ctx: &'a dyn Context,
) -> Self
pub fn new( instant_bus: &'a mut EventBus, game_bus: &'a mut EventBus, commands: &'a mut Vec<CommandEntry>, systems: &'a mut Vec<SystemDescriptor>, world: Arc<dyn WorldHandle + Send + Sync>, recipes: &'a mut dyn RecipeRegistryHandle, bootstrap_ctx: &'a dyn Context, ) -> Self
Creates a new registrar with dual event buses and recipe registry.
bootstrap_ctx is a stub context used only to dispatch
system-level events (today: the recipe registry lifecycle) that
fire before any player exists.
Sourcepub fn world(&self) -> Arc<dyn WorldHandle + Send + Sync>
pub fn world(&self) -> Arc<dyn WorldHandle + Send + Sync>
Returns a shared reference to the world.
Available to all plugins — use this to capture the world in system closures for block access, collision checks, etc.
Sourcepub fn recipes(&mut self) -> RecipeRegistrar<'_>
pub fn recipes(&mut self) -> RecipeRegistrar<'_>
Returns a RecipeRegistrar
that mutates the registry while dispatching the lifecycle
events on the game bus.
Plugins call this from on_enable to add
or remove recipes. Mutations on the returned wrapper trigger
RecipeRegisterEvent,
RecipeRegisteredEvent,
and RecipeUnregisteredEvent
so other plugins can observe or veto changes.
After every plugin’s on_enable completes, the registry is
frozen behind Arc<RecipeRegistry> and shared immutably with
the game loop.
Sourcepub fn on<E>(
&mut self,
stage: Stage,
priority: i32,
handler: impl Fn(&mut E, &dyn Context) + Send + Sync + 'static,
)where
E: Event + EventRouting + 'static,
pub fn on<E>(
&mut self,
stage: Stage,
priority: i32,
handler: impl Fn(&mut E, &dyn Context) + Send + Sync + 'static,
)where
E: Event + EventRouting + 'static,
Registers an event handler on the correct bus.
The target bus is determined at compile time by E::BUS:
BusKind::Instant→ network loop busBusKind::Game→ game loop bus
Sourcepub fn system(&mut self, name: &str) -> PluginSystemBuilder<'_, 'a>
pub fn system(&mut self, name: &str) -> PluginSystemBuilder<'_, 'a>
Starts building a system for the game loop.
Returns a PluginSystemBuilder for fluent configuration of
phase, frequency, component access, and the system runner.
§Example
registrar.system("gravity")
.phase(Phase::Simulate)
.every(1)
.writes::<Position>()
.writes::<Velocity>()
.run(|ctx| { /* apply gravity */ });Sourcepub fn command(&mut self, name: &str) -> CommandBuilder<'_, 'a>
pub fn command(&mut self, name: &str) -> CommandBuilder<'_, 'a>
Starts building a command with typed arguments.