Skip to main content

PluginRegistrar

Struct PluginRegistrar 

Source
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>

Source

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.

Source

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.

Source

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.

Source

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:

Source

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 */ });
Source

pub fn command(&mut self, name: &str) -> CommandBuilder<'_, 'a>

Starts building a command with typed arguments.

Auto Trait Implementations§

§

impl<'a> Freeze for PluginRegistrar<'a>

§

impl<'a> !RefUnwindSafe for PluginRegistrar<'a>

§

impl<'a> !Send for PluginRegistrar<'a>

§

impl<'a> !Sync for PluginRegistrar<'a>

§

impl<'a> Unpin for PluginRegistrar<'a>

§

impl<'a> UnsafeUnpin for PluginRegistrar<'a>

§

impl<'a> !UnwindSafe for PluginRegistrar<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.