Skip to main content

RecipeRegistrar

Struct RecipeRegistrar 

Source
pub struct RecipeRegistrar<'a> { /* private fields */ }
Expand description

Plugin-facing handle to the recipe registry with event dispatch.

Holds mutable references to a RecipeRegistryHandle trait object and the game event bus, plus a shared reference to a dispatch context. Every mutation method dispatches the appropriate lifecycle event and respects Validate-stage cancellation.

Implementations§

Source§

impl<'a> RecipeRegistrar<'a>

Source

pub fn add_shaped(&mut self, recipe: OwnedShapedRecipe) -> bool

Registers a shaped recipe.

Dispatches RecipeRegisterEvent at Validate. If a handler cancels the event, the registry is left untouched and this method returns false. Otherwise the recipe is inserted and RecipeRegisteredEvent is dispatched at Post; returns true.

Source

pub fn add_shapeless(&mut self, recipe: OwnedShapelessRecipe) -> bool

Registers a shapeless recipe.

Same dispatch semantics as add_shaped. The caller is responsible for sorting recipe.ingredients ascending — required for correct matching.

Source

pub fn remove_by_id(&mut self, id: &RecipeId) -> bool

Removes the recipe with the given id, dispatching RecipeUnregisteredEvent at Post on success.

Returns true if a recipe was removed, false if the id was not registered.

Source

pub fn remove_by_result(&mut self, result_id: i32) -> usize

Removes every recipe (shaped and shapeless) producing the given result_id. Dispatches one RecipeUnregisteredEvent per removed entry. Returns the number of recipes removed.

Source

pub fn clear(&mut self)

Removes every recipe and dispatches one RecipeUnregisteredEvent per removed entry.

Source

pub fn contains(&self, id: &RecipeId) -> bool

Returns true if the registry contains a recipe with the given id.

Source

pub fn get(&self, id: &RecipeId) -> Option<Recipe>

Returns a clone of the recipe with the given id, or None.

Source

pub fn shaped_count(&self) -> usize

Returns the number of registered shaped recipes.

Source

pub fn shapeless_count(&self) -> usize

Returns the number of registered shapeless recipes.

Auto Trait Implementations§

§

impl<'a> Freeze for RecipeRegistrar<'a>

§

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

§

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

§

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

§

impl<'a> Unpin for RecipeRegistrar<'a>

§

impl<'a> UnsafeUnpin for RecipeRegistrar<'a>

§

impl<'a> !UnwindSafe for RecipeRegistrar<'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.