Search in sources :

Example 21 with ItemRoutingInformation

use of logisticspipes.routing.ItemRoutingInformation in project LogisticsPipes by RS485.

the class PipeItemsInvSysConnector method getExpectedItems.

public Set<ItemIdentifierStack> getExpectedItems() {
    // got to be a TreeMap, because a TreeSet doesn't have the ability to retrieve the key.
    Set<ItemIdentifierStack> list = new TreeSet<>();
    for (Entry<ItemIdentifier, List<ItemRoutingInformation>> entry : itemsOnRoute.entrySet()) {
        if (entry.getValue().isEmpty()) {
            continue;
        }
        ItemIdentifierStack currentStack = new ItemIdentifierStack(entry.getKey(), 0);
        for (ItemRoutingInformation e : entry.getValue()) {
            currentStack.setStackSize(currentStack.getStackSize() + e.getItem().getStackSize());
        }
        list.add(currentStack);
    }
    return list;
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) TreeSet(java.util.TreeSet) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack)

Example 22 with ItemRoutingInformation

use of logisticspipes.routing.ItemRoutingInformation in project LogisticsPipes by RS485.

the class PipeItemsInvSysConnector method checkOneConnectedInv.

private boolean checkOneConnectedInv(@Nonnull IInventoryUtil inv, EnumFacing dir) {
    boolean contentchanged = false;
    if (!itemsOnRoute.isEmpty()) {
        // don't check the inventory if you don't want anything
        List<ItemIdentifier> items = new ArrayList<>(itemsOnRoute.keySet());
        items.retainAll(inv.getItems());
        Map<ItemIdentifier, Integer> amounts = null;
        if (!items.isEmpty()) {
            amounts = inv.getItemsAndCount();
        }
        for (ItemIdentifier ident : items) {
            if (!amounts.containsKey(ident)) {
                continue;
            }
            int itemAmount = amounts.get(ident);
            List<ItemRoutingInformation> needs = itemsOnRoute.get(ident);
            for (Iterator<ItemRoutingInformation> iterator = needs.iterator(); iterator.hasNext(); ) {
                ItemRoutingInformation need = iterator.next();
                if (need.getItem().getStackSize() <= itemAmount) {
                    if (!useEnergy(6)) {
                        return contentchanged;
                    }
                    ItemStack toSend = inv.getMultipleItems(ident, need.getItem().getStackSize());
                    if (toSend.isEmpty()) {
                        return contentchanged;
                    }
                    if (toSend.getCount() != need.getItem().getStackSize()) {
                        if (inv instanceof ITransactor) {
                            ((ITransactor) inv).add(toSend, dir.getOpposite(), true);
                        } else {
                            container.getWorld().spawnEntity(ItemIdentifierStack.getFromStack(toSend).makeEntityItem(getWorld(), container.getX(), container.getY(), container.getZ()));
                        }
                        new UnsupportedOperationException("The extracted amount didn't match the requested one. (" + inv + ")").printStackTrace();
                        return contentchanged;
                    }
                    sendStack(need, dir);
                    // finished with this need, we sent part of a stack, lets see if anyone where needs the current item type.
                    iterator.remove();
                    contentchanged = true;
                    if (needs.isEmpty()) {
                        itemsOnRoute.remove(ident);
                    }
                    // Refresh Available Items
                    amounts = inv.getItemsAndCount();
                    if (amounts.containsKey(ident)) {
                        itemAmount = amounts.get(ident);
                    } else {
                        break;
                    }
                }
            }
        }
    }
    return contentchanged;
}
Also used : ArrayList(java.util.ArrayList) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) ItemStack(net.minecraft.item.ItemStack) ITransactor(logisticspipes.utils.transactor.ITransactor)

Aggregations

ItemRoutingInformation (logisticspipes.routing.ItemRoutingInformation)22 ItemStack (net.minecraft.item.ItemStack)7 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 ArrayList (java.util.ArrayList)4 IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)4 LPTravelingItemServer (logisticspipes.transport.LPTravelingItem.LPTravelingItemServer)4 Triplet (logisticspipes.utils.tuples.Triplet)4 EnumFacing (net.minecraft.util.EnumFacing)4 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)3 ITransactor (logisticspipes.utils.transactor.ITransactor)3 LinkedList (java.util.LinkedList)2 List (java.util.List)2 TreeSet (java.util.TreeSet)2 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)2 Pair (logisticspipes.utils.tuples.Pair)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 IFlowItems (buildcraft.api.transport.pipe.IFlowItems)1 Collection (java.util.Collection)1