Skip to main content

RecipeRegistry

Struct RecipeRegistry 

Source
pub struct RecipeRegistry {
    recipes_by_id: Vec<&'static CraftingRecipe>,
    recipes_by_key: FxHashMap<Identifier, usize>,
    shaped_recipes: Vec<&'static ShapedRecipe>,
    shapeless_recipes: Vec<&'static ShapelessRecipe>,
    allows_registering: bool,
}
Expand description

Registry for all recipes.

Fields§

§recipes_by_id: Vec<&'static CraftingRecipe>

All recipes in registration order (unified storage for RegistryExt).

§recipes_by_key: FxHashMap<Identifier, usize>

Map from recipe key to index in recipes_by_id.

§shaped_recipes: Vec<&'static ShapedRecipe>

All shaped crafting recipes (for type-specific iteration).

§shapeless_recipes: Vec<&'static ShapelessRecipe>

All shapeless crafting recipes (for type-specific iteration).

§allows_registering: bool

Whether registration is still allowed.

Implementations§

Source§

impl RecipeRegistry

Source

pub fn new() -> Self

Creates a new empty recipe registry.

Source

pub fn register_shaped(&mut self, recipe: &'static ShapedRecipe)

Registers a shaped recipe.

Source

pub fn register_shapeless(&mut self, recipe: &'static ShapelessRecipe)

Registers a shapeless recipe.

Source

pub fn find_crafting_recipe( &self, input: &CraftingInput, ) -> Option<CraftingRecipe>

Finds a matching crafting recipe for the given positioned input. Returns the first matching recipe, or None if no recipe matches.

Source

pub fn find_crafting_recipe_2x2( &self, input: &CraftingInput, ) -> Option<CraftingRecipe>

Finds a matching crafting recipe for a 2x2 grid. Only checks recipes that can fit in a 2x2 grid.

Source

pub fn get_shaped(&self, id: &Identifier) -> Option<&'static ShapedRecipe>

Gets a shaped recipe by its identifier.

Source

pub fn get_shapeless(&self, id: &Identifier) -> Option<&'static ShapelessRecipe>

Gets a shapeless recipe by its identifier.

Source

pub fn shaped_count(&self) -> usize

Returns the number of shaped recipes.

Source

pub fn shapeless_count(&self) -> usize

Returns the number of shapeless recipes.

Source

pub fn iter_shaped(&self) -> impl Iterator<Item = &'static ShapedRecipe> + '_

Iterates over all shaped recipes.

Source

pub fn iter_shapeless( &self, ) -> impl Iterator<Item = &'static ShapelessRecipe> + '_

Iterates over all shapeless recipes.

Trait Implementations§

Source§

impl Default for RecipeRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl RegistryExt for RecipeRegistry

Source§

type Entry = CraftingRecipe

Source§

fn freeze(&mut self)

Source§

fn by_id(&self, id: usize) -> Option<&'static CraftingRecipe>

Source§

fn by_key(&self, key: &Identifier) -> Option<&'static CraftingRecipe>

Source§

fn id_from_key(&self, key: &Identifier) -> Option<usize>

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Auto Trait Implementations§

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more