/// Attempts to insert the given item into a player
/// inventory.
///
/// Returns the affected slots and the number of remaining
/// items which were not added to the inventory.
Attempts to insert the given item into a player
inventory.

Returns the affected slots and the number of remaining
items which were not added to the inventory.
Attempts to insert the given item into a player inventory . Returns the affected slots and the number of remaining items which were not added to the inventory .
pub fn collect_item(&mut self, mut item: ItemStack) -> (SmallVec<[SlotIndex; 2]>, u8) {
        let mut affected_slots = smallvec![];
        // First, look for slots already having the type.
        for slot in COLLECT_SEARCH_ORDER.iter() {
            if let Some(slot_item) = self.item_at(*slot).cloned() {
                if slot_item.ty == item.ty {
                    self.add_to_stack(&mut item, &slot_item, *slot, &mut affected_slots);
                    if item.amount == 0 {
                        return (affected_slots, 0);
                    }
                }
            }
        }
        for slot in COLLECT_SEARCH_ORDER.iter() {
            let slot_item = self.item_at(*slot).cloned();
            if slot_item.is_none() {
                let fake = ItemStack::new(item.ty, 0);
                self.add_to_stack(&mut item, &fake, *slot, &mut affected_slots);
                if item.amount == 0 {
                    return (affected_slots, 0);
                }
            }
            if let Some(slot_item) = slot_item {
                if slot_item.ty == item.ty {
                    self.add_to_stack(&mut item, &slot_item, *slot, &mut affected_slots);
                    if item.amount == 0 {
                        return (affected_slots, 0);
                    }
                }
            }
        }
        (affected_slots, item.amount)
    }
pub fn collect_item ( & mut self , mut item : ItemStack ) -> ( SmallVec < [ SlotIndex ; 2 ] > , u8 ) { let mut affected_slots = smallvec ! [ ] ; // First, look for slots already having the type. for slot in COLLECT_SEARCH_ORDER . iter ( ) { if let Some ( slot_item ) = self . item_at ( * slot ) . cloned ( ) { if slot_item . ty == item . ty { self . add_to_stack ( & mut item , & slot_item , * slot , & mut affected_slots ) ; if item . amount == 0 { return ( affected_slots , 0 ) ; } } } } for slot in COLLECT_SEARCH_ORDER . iter ( ) { let slot_item = self . item_at ( * slot ) . cloned ( ) ; if slot_item . is_none ( ) { let fake = ItemStack :: new ( item . ty , 0 ) ; self . add_to_stack ( & mut item , & fake , * slot , & mut affected_slots ) ; if item . amount == 0 { return ( affected_slots , 0 ) ; } } if let Some ( slot_item ) = slot_item { if slot_item . ty == item . ty { self . add_to_stack ( & mut item , & slot_item , * slot , & mut affected_slots ) ; if item . amount == 0 { return ( affected_slots , 0 ) ; } } } } ( affected_slots , item . amount ) }
Attempts to insert the given item into a player
inventory.
Attempts to insert the given item into a player inventory .
&mut self
item
ItemStack