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