Search in sources :

Example 1 with InventoryManipulator

use of mods.railcraft.common.util.inventory.manipulators.InventoryManipulator in project Railcraft by Railcraft.

the class IcemanBackpack method manageSnow.

private void manageSnow(IInventory backpackInventory) {
    InventoryComposite inv = InventoryComposite.of(backpackInventory);
    if (!inv.isEmpty()) {
        int numSnowballs = InvTools.countItems(inv, SNOWBALL_MATCHER);
        InventoryManipulator im = InventoryManipulator.get(backpackInventory);
        while (numSnowballs > 16 && im.canRemoveItems(SNOWBALL_MATCHER, 4) && im.canAddStack(SNOW_BLOCK)) {
            im.removeItems(SNOWBALL_MATCHER, 4);
            im.addStack(new ItemStack(Blocks.SNOW));
            numSnowballs -= 4;
        }
        while (numSnowballs < 8 && im.canRemoveItem(SNOW_BLOCK_MATCHER) && im.canAddStack(new ItemStack(Items.SNOWBALL, 4))) {
            im.removeItem(SNOW_BLOCK_MATCHER);
            im.addStack(new ItemStack(Items.SNOWBALL, 4));
            numSnowballs += 4;
        }
    }
}
Also used : InventoryManipulator(mods.railcraft.common.util.inventory.manipulators.InventoryManipulator) InventoryComposite(mods.railcraft.common.util.inventory.wrappers.InventoryComposite) ItemStack(net.minecraft.item.ItemStack)

Example 2 with InventoryManipulator

use of mods.railcraft.common.util.inventory.manipulators.InventoryManipulator in project Railcraft by Railcraft.

the class InvTools method findMatchingItem.

/**
     * Returns a single item from the inventory that matches the
     * filter, but does not remove it.
     *
     * @param inv    the inventory    The inventory
     * @param filter the filter to match against
     * @return An ItemStack
     */
@Nullable
public static ItemStack findMatchingItem(IInventoryComposite inv, Predicate<ItemStack> filter) {
    for (IInventoryObject inventoryObject : inv) {
        InventoryManipulator im = InventoryManipulator.get(inventoryObject);
        ItemStack removed = im.tryRemoveItem(filter);
        if (!isEmpty(removed))
            return removed;
    }
    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)

Example 3 with InventoryManipulator

use of mods.railcraft.common.util.inventory.manipulators.InventoryManipulator in project Railcraft by Railcraft.

the class InvTools method moveItemStack.

/**
     * Places an ItemStack in a destination Inventory. Will attempt to move as
     * much of the stack as possible, returning any remainder.
     *
     * @param stack The ItemStack to put in the inventory.
     * @param dest  The destination IInventories.
     * @return Null if itemStack was completely moved, a new itemStack with
     * remaining stackSize if part or none of the stack was moved.
     */
@SuppressWarnings("unused")
@Nullable
public static ItemStack moveItemStack(ItemStack stack, IInventoryComposite dest) {
    for (IInventoryObject inv : dest) {
        InventoryManipulator im = InventoryManipulator.get(inv);
        stack = im.addStack(stack);
        if (isEmpty(stack))
            return emptyStack();
    }
    return stack;
}
Also used : IInventoryObject(mods.railcraft.common.util.inventory.wrappers.IInventoryObject) InventoryManipulator(mods.railcraft.common.util.inventory.manipulators.InventoryManipulator) Nullable(javax.annotation.Nullable)

Example 4 with InventoryManipulator

use of mods.railcraft.common.util.inventory.manipulators.InventoryManipulator in project Railcraft by Railcraft.

the class InvTools method moveOneItem.

/**
     * Attempts to move a single item from one inventory to another.
     *
     * @param source the source inventory
     * @param dest   the destination inventory
     * @param filter Predicate to match against
     * @return null if nothing was moved, the stack moved otherwise
     */
@Nullable
public static ItemStack moveOneItem(IInventoryComposite source, IInventoryComposite dest, Predicate<ItemStack> filter) {
    for (IInventoryObject src : source) {
        for (IInventoryObject dst : dest) {
            InventoryManipulator imSource = InventoryManipulator.get(src);
            ItemStack moved = imSource.moveItem(dst, filter);
            if (!isEmpty(moved))
                return moved;
        }
    }
    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)

Example 5 with InventoryManipulator

use of mods.railcraft.common.util.inventory.manipulators.InventoryManipulator 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

InventoryManipulator (mods.railcraft.common.util.inventory.manipulators.InventoryManipulator)5 Nullable (javax.annotation.Nullable)4 IInventoryObject (mods.railcraft.common.util.inventory.wrappers.IInventoryObject)4 ItemStack (net.minecraft.item.ItemStack)4 InventoryComposite (mods.railcraft.common.util.inventory.wrappers.InventoryComposite)1