Search in sources :

Example 11 with IInvSlot

use of mods.railcraft.common.util.inventory.iterators.IInvSlot in project Railcraft by Railcraft.

the class InventoryManipulator method tryRemoveItem.

/**
     * Returns the item that would be returned if an item matching the filter
     * was removed. Does not modify the inventory.
     */
@Nullable
public ItemStack tryRemoveItem(Predicate<ItemStack> filter) {
    for (IInvSlot slot : this) {
        ItemStack stack = slot.getStack();
        if (!isEmpty(stack) && slot.canTakeStackFromSlot(stack) && filter.test(stack)) {
            ItemStack output = stack.copy();
            output.stackSize = 1;
            return output;
        }
    }
    return emptyStack();
}
Also used : IInvSlot(mods.railcraft.common.util.inventory.iterators.IInvSlot) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Aggregations

IInvSlot (mods.railcraft.common.util.inventory.iterators.IInvSlot)11 ItemStack (net.minecraft.item.ItemStack)9 IInventoryObject (mods.railcraft.common.util.inventory.wrappers.IInventoryObject)3 ArrayList (java.util.ArrayList)2 Nonnull (javax.annotation.Nonnull)2 Nullable (javax.annotation.Nullable)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 ICrusherCraftingManager (mods.railcraft.api.crafting.ICrusherCraftingManager)1 StackKey (mods.railcraft.common.util.collections.StackKey)1 InventoryCopy (mods.railcraft.common.util.inventory.wrappers.InventoryCopy)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 IInventory (net.minecraft.inventory.IInventory)1 BlockPos (net.minecraft.util.math.BlockPos)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 Contract (org.jetbrains.annotations.Contract)1