Search in sources :

Example 6 with IInventoryObject

use of mods.railcraft.common.util.inventory.wrappers.IInventoryObject in project Railcraft by Railcraft.

the class InvTools method findMatchingItems.

/**
     * Returns all items from the inventory that match the
     * filter, but does not remove them.
     * The resulting set will be populated with a single instance of each item type.
     *
     * @param inv    the inventory    The inventory
     * @param filter EnumItemType to match against
     * @return A Set of ItemStacks
     */
@Nonnull
public static Set<StackKey> findMatchingItems(IInventoryComposite inv, Predicate<ItemStack> filter) {
    Set<StackKey> items = CollectionTools.createItemStackSet();
    for (IInventoryObject inventoryObject : inv) {
        for (IInvSlot slot : InventoryIterator.getRailcraft(inventoryObject)) {
            ItemStack stack = slot.getStack();
            if (!isEmpty(stack) && filter.test(stack)) {
                stack = stack.copy();
                stack.stackSize = 1;
                items.add(StackKey.make(stack));
            }
        }
    }
    return items;
}
Also used : IInvSlot(mods.railcraft.common.util.inventory.iterators.IInvSlot) IInventoryObject(mods.railcraft.common.util.inventory.wrappers.IInventoryObject) StackKey(mods.railcraft.common.util.collections.StackKey) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 7 with IInventoryObject

use of mods.railcraft.common.util.inventory.wrappers.IInventoryObject in project Railcraft by Railcraft.

the class AdjacentInventoryCache method getAdjacentInventories.

public InventoryComposite getAdjacentInventories() {
    Map<EnumFacing, TileEntity> tiles = cache.refreshTiles();
    if (!changedSides.isEmpty()) {
        for (EnumFacing side : changedSides) {
            invs.remove(side);
            TileEntity tile = tiles.get(side);
            if (tile != null && (filter == null || filter.test(tile))) {
                IInventoryObject inv = InventoryFactory.get(tile, side.getOpposite());
                if (inv != null)
                    invs.put(side, inv);
            }
        }
        changedSides.clear();
        sortedInvs.clear();
        sortedInvs.addAll(invs.values());
        if (sorter != null)
            sortedInvs.sort(sorter);
    }
    return sortedInvs;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventoryObject(mods.railcraft.common.util.inventory.wrappers.IInventoryObject) EnumFacing(net.minecraft.util.EnumFacing)

Example 8 with IInventoryObject

use of mods.railcraft.common.util.inventory.wrappers.IInventoryObject in project Railcraft by Railcraft.

the class InvTools method calcRedstoneFromInventory.

/**
     * @see Container#calcRedstoneFromInventory(IInventory)
     */
public static int calcRedstoneFromInventory(@Nullable InventoryComposite inv) {
    if (inv == null)
        return 0;
    int numStacks = 0;
    float average = 0.0F;
    for (IInventoryObject inventoryObject : inv) {
        int stackLimit = inventoryObject.getBackingObject() instanceof IInventory ? ((IInventory) inventoryObject.getBackingObject()).getInventoryStackLimit() : 64;
        for (ItemStack stack : InventoryIterator.getRailcraft(inventoryObject).getStacks()) {
            average += (float) stack.stackSize / (float) Math.min(stackLimit, stack.getMaxStackSize());
            numStacks++;
        }
    }
    average = average / (float) inv.slotCount();
    return MathHelper.floor_float(average * 14.0F) + (numStacks > 0 ? 1 : 0);
}
Also used : IInventory(net.minecraft.inventory.IInventory) IInventoryObject(mods.railcraft.common.util.inventory.wrappers.IInventoryObject) ItemStack(net.minecraft.item.ItemStack)

Example 9 with IInventoryObject

use of mods.railcraft.common.util.inventory.wrappers.IInventoryObject in project Railcraft by Railcraft.

the class InvTools method removeOneItem.

/**
     * Removes and returns a single item from the inventory that matches the
     * filter.
     *
     * @param invs   The inventories
     * @param filter the filter to match against
     * @return An ItemStack
     */
@Nullable
public static ItemStack removeOneItem(IInventoryComposite invs, Predicate<ItemStack> filter) {
    for (IInventoryObject inv : invs) {
        InventoryManipulator im = InventoryManipulator.get(inv);
        ItemStack stack = im.removeItem(filter);
        if (!isEmpty(stack))
            return stack;
    }
    return emptyStack();
}
Also used : IInventoryObject(mods.railcraft.common.util.inventory.wrappers.IInventoryObject) InventoryManipulator(mods.railcraft.common.util.inventory.manipulators.InventoryManipulator) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Aggregations

IInventoryObject (mods.railcraft.common.util.inventory.wrappers.IInventoryObject)9 ItemStack (net.minecraft.item.ItemStack)7 Nullable (javax.annotation.Nullable)4 InventoryManipulator (mods.railcraft.common.util.inventory.manipulators.InventoryManipulator)4 IInvSlot (mods.railcraft.common.util.inventory.iterators.IInvSlot)3 Nonnull (javax.annotation.Nonnull)1 StackKey (mods.railcraft.common.util.collections.StackKey)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 IInventory (net.minecraft.inventory.IInventory)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 Contract (org.jetbrains.annotations.Contract)1