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;
}
}
}
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();
}
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;
}
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();
}
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();
}
Aggregations