Search in sources :

Example 11 with IResource

use of logisticspipes.request.resources.IResource in project LogisticsPipes by RS485.

the class ModuleCrafter method canProvide.

@Override
public void canProvide(RequestTreeNode tree, RequestTree root, List<IFilter> filters) {
    final IPipeServiceProvider service = _service;
    if (service == null)
        return;
    if (!service.getItemOrderManager().hasExtras() || tree.hasBeenQueried(service.getItemOrderManager())) {
        return;
    }
    IResource requestedItem = tree.getRequestType();
    if (!canCraft(requestedItem)) {
        return;
    }
    for (IFilter filter : filters) {
        if (filter.isBlocked() == filter.isFilteredItem(requestedItem) || filter.blockProvider()) {
            return;
        }
    }
    int remaining = 0;
    for (LogisticsItemOrder extra : service.getItemOrderManager()) {
        if (extra.getType() == ResourceType.EXTRA) {
            if (extra.getResource().getItem().equals(requestedItem.getAsItem())) {
                remaining += extra.getResource().stack.getStackSize();
            }
        }
    }
    final ItemIdentifierStack craftedItem = getCraftedItem();
    if (craftedItem == null)
        return;
    remaining -= root.getAllPromissesFor(this, craftedItem.getItem());
    if (remaining < 1) {
        return;
    }
    if (getUpgradeManager().isFuzzyUpgrade() && outputFuzzy().nextSetBit(0) != -1) {
        DictResource dict = new DictResource(craftedItem, null).loadFromBitSet(outputFuzzy().copyValue());
        LogisticsExtraDictPromise promise = new LogisticsExtraDictPromise(dict, Math.min(remaining, tree.getMissingAmount()), this, true);
        tree.addPromise(promise);
    } else {
        LogisticsExtraPromise promise = new LogisticsExtraPromise(craftedItem.getItem(), Math.min(remaining, tree.getMissingAmount()), this, true);
        tree.addPromise(promise);
    }
    tree.setQueried(service.getItemOrderManager());
}
Also used : IFilter(logisticspipes.interfaces.routing.IFilter) IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) DictResource(logisticspipes.request.resources.DictResource) LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder) LogisticsExtraDictPromise(logisticspipes.routing.LogisticsExtraDictPromise) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) IResource(logisticspipes.request.resources.IResource) LogisticsExtraPromise(logisticspipes.routing.LogisticsExtraPromise)

Aggregations

IResource (logisticspipes.request.resources.IResource)11 LinkedLogisticsOrderList (logisticspipes.routing.order.LinkedLogisticsOrderList)8 ArrayList (java.util.ArrayList)7 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)6 HashMap (java.util.HashMap)5 DictResource (logisticspipes.request.resources.DictResource)5 ItemResource (logisticspipes.request.resources.ItemResource)5 BitSet (java.util.BitSet)3 List (java.util.List)3 Map (java.util.Map)3 Entry (java.util.Map.Entry)3 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)3 Collections (java.util.Collections)2 EnumSet (java.util.EnumSet)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 PriorityQueue (java.util.PriorityQueue)2 Set (java.util.Set)2 TreeSet (java.util.TreeSet)2 Collectors (java.util.stream.Collectors)2