src/main/java/com/github/klikli_dev/occultism/util/StorageUtil.java
/**
     * Extracts the given amount of items matching the given comparator from the given item handler
     *
     * @param itemHandler the handler to extract from.
     * @param comparator  the comparator to match item stacks.
     * @param amount      the amount to extract.
     * @param simulate    true to simulate.
     * @return the extracted stack.
     */
Extracts the given amount of items matching the given comparator from the given item handler
@param itemHandler the handler to extract from.
@param comparator  the comparator to match item stacks.
@param amount      the amount to extract.
@param simulate    true to simulate.
@return the extracted stack.
Extracts the given amount of items matching the given comparator from the given item handler @param itemHandler the handler to extract from . @param comparator the comparator to match item stacks . @param amount the amount to extract . @param simulate true to simulate . @return the extracted stack .
public static ItemStack extractItem(IItemHandler itemHandler, Predicate<ItemStack> comparator, int amount,
                                        boolean simulate) {
        if (itemHandler == null || comparator == null) {
            return ItemStack.EMPTY;
        }
        int amountExtracted = 0;
        for (int i = 0; i < itemHandler.getSlots(); i++) {
            ItemStack slot = itemHandler.getStackInSlot(i);
            if (comparator.test(slot)) {
                ItemStack extractedStack = itemHandler.extractItem(i, 1, simulate);
                if (!extractedStack.isEmpty()) {
                    amountExtracted++;
                    if (amountExtracted == amount)
                        return ItemHandlerHelper.copyStackWithSize(slot, amount);
                    else
                        i--;
                }
            }
        }
        return ItemStack.EMPTY;
    }
public static ItemStack extractItem ( IItemHandler itemHandler , Predicate < ItemStack > comparator , int amount , boolean simulate ) { if ( itemHandler == null || comparator == null ) { return ItemStack . EMPTY ; } int amountExtracted = 0 ; for ( int i = 0 ; i < itemHandler . getSlots ( ) ; i ++ ) { ItemStack slot = itemHandler . getStackInSlot ( i ) ; if ( comparator . test ( slot ) ) { ItemStack extractedStack = itemHandler . extractItem ( i , 1 , simulate ) ; if ( ! extractedStack . isEmpty ( ) ) { amountExtracted ++ ; if ( amountExtracted == amount ) return ItemHandlerHelper . copyStackWithSize ( slot , amount ) ; else i -- ; } } } return ItemStack . EMPTY ; }
Extracts the given amount of items matching the given comparator from the given item handler
 @param itemHandler the handler to extract from.
Extracts the given amount of items matching the given comparator from the given item handler @param itemHandler the handler to extract from .
//go through all slots in the handler //check if current slot matches //take out of handler, one by one //if not empty increase the amount we extracted //once we found enough, use the current slot to create a stack with the desired amount and return it //continue extracting from this slot until we get nothing back.