pub struct CraftingContainer {
width: usize,
height: usize,
items: Vec<ItemStack>,
}Expand description
A container for crafting grid items.
Holds items in a crafting grid pattern (2x2 for player inventory, 3x3 for crafting table).
Fields§
§width: usize§height: usize§items: Vec<ItemStack>Implementations§
Source§impl CraftingContainer
impl CraftingContainer
Sourcepub fn new(width: usize, height: usize) -> Self
pub fn new(width: usize, height: usize) -> Self
Creates a new crafting container with the given dimensions.
Sourcepub fn as_positioned_input(&self) -> PositionedCraftingInput
pub fn as_positioned_input(&self) -> PositionedCraftingInput
Creates a positioned CraftingInput representing the current state of the grid.
The positioned input contains a trimmed version of the grid (only the bounding box of non-empty items) along with the offset from the original grid origin. This is used for recipe matching and when consuming ingredients to correctly map recipe slots back to the original crafting grid slots.
Trait Implementations§
Source§impl Container for CraftingContainer
impl Container for CraftingContainer
Source§fn items_mut(&mut self) -> &mut [ItemStack]
fn items_mut(&mut self) -> &mut [ItemStack]
Returns mutable references to the items in this container.
Source§fn set_changed(&mut self)
fn set_changed(&mut self)
Marks this container as changed (dirty) for saving/syncing.
Source§fn get_container_size(&self) -> usize
fn get_container_size(&self) -> usize
Returns the number of slots in this container.
Source§fn get_item(&self, slot: usize) -> &ItemStack
fn get_item(&self, slot: usize) -> &ItemStack
Returns a reference to the item in the specified slot.
Source§fn contains_stack(&self, search_stack: &ItemStack) -> bool
fn contains_stack(&self, search_stack: &ItemStack) -> bool
Returns true if this container has a non-empty stack with the same item and components. Read more
Source§fn get_item_mut(&mut self, slot: usize) -> &mut ItemStack
fn get_item_mut(&mut self, slot: usize) -> &mut ItemStack
Returns a mutable reference to the item in the specified slot.
Source§fn remove_item(&mut self, slot: usize, count: i32) -> ItemStack
fn remove_item(&mut self, slot: usize, count: i32) -> ItemStack
Removes up to
count items from the specified slot and returns them.Source§fn remove_item_no_update(&mut self, slot: usize) -> ItemStack
fn remove_item_no_update(&mut self, slot: usize) -> ItemStack
Removes the item from the specified slot without triggering updates.
Source§fn get_max_stack_size(&self) -> i32
fn get_max_stack_size(&self) -> i32
Returns the maximum stack size for this container.
Source§fn get_max_stack_size_for_item(&self, item: &ItemStack) -> i32
fn get_max_stack_size_for_item(&self, item: &ItemStack) -> i32
Returns the maximum stack size for a specific item in this container. Read more
Source§fn can_place_item(&self, _slot: usize, _stack: &ItemStack) -> bool
fn can_place_item(&self, _slot: usize, _stack: &ItemStack) -> bool
Returns true if the specified item can be placed in the specified slot.
Source§fn can_take_item(&self, _slot: usize, _stack: &ItemStack) -> bool
fn can_take_item(&self, _slot: usize, _stack: &ItemStack) -> bool
Returns true if the specified item can be taken from the specified slot.
Source§fn clear_content(&mut self) -> i32
fn clear_content(&mut self) -> i32
Clears all items from this container.
Source§fn clear_content_matching(
&mut self,
predicate: &mut dyn FnMut(&mut ItemStack) -> bool,
) -> i32
fn clear_content_matching( &mut self, predicate: &mut dyn FnMut(&mut ItemStack) -> bool, ) -> i32
Clears all items from this container.
Source§fn clear_or_count_matching_items(
&mut self,
predicate: &dyn Fn(&ItemStack) -> bool,
amount_to_remove: i32,
counting_only: bool,
) -> i32
fn clear_or_count_matching_items( &mut self, predicate: &dyn Fn(&ItemStack) -> bool, amount_to_remove: i32, counting_only: bool, ) -> i32
Removes or counts matching items using vanilla
/clear semantics.Source§fn with_indices<const N: usize>(
&mut self,
indices: [usize; N],
) -> [&mut ItemStack; N]where
Self: Sized,
fn with_indices<const N: usize>(
&mut self,
indices: [usize; N],
) -> [&mut ItemStack; N]where
Self: Sized,
Returns mutable references to
N disjoint slots. Read moreSource§fn add(&mut self, stack: &mut ItemStack) -> bool
fn add(&mut self, stack: &mut ItemStack) -> bool
Tries to add an item to the container. Read more
Source§impl DowncastType for CraftingContainer
impl DowncastType for CraftingContainer
Source§const TYPE_KEY: DowncastTypeKey
const TYPE_KEY: DowncastTypeKey
The process-wide key for this concrete type.
Auto Trait Implementations§
impl !RefUnwindSafe for CraftingContainer
impl !UnwindSafe for CraftingContainer
impl Freeze for CraftingContainer
impl Send for CraftingContainer
impl Sync for CraftingContainer
impl Unpin for CraftingContainer
impl UnsafeUnpin for CraftingContainer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: ErasedType + ?Sized,
impl<T> Downcast for Twhere
T: ErasedType + ?Sized,
Source§fn is<T>(&self) -> boolwhere
T: DowncastType,
fn is<T>(&self) -> boolwhere
T: DowncastType,
Returns whether the erased value has concrete type
T.Source§fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastType,
fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastType,
Returns the erased value as
T when its key matches.Source§fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: DowncastType,
fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: DowncastType,
Returns the erased value as mutable
T when its key matches.Source§impl<T> ErasedType for Twhere
T: DowncastType,
impl<T> ErasedType for Twhere
T: DowncastType,
fn downcast_type_key(&self) -> DowncastTypeKey
fn downcast_data(&self) -> *const ()
fn downcast_data_mut(&mut self) -> *mut ()
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreWraps this value in an
Arc<SyncMutex<>>