Search in sources :

Example 1 with CCSinkResponder

use of logisticspipes.proxy.computers.objects.CCSinkResponder in project LogisticsPipes by RS485.

the class ModuleCCBasedQuickSort method handleSinkResponses.

private void handleSinkResponses(IInventoryUtil invUtil) {
    boolean changed = false;
    Iterator<Entry<Integer, Pair<Integer, List<CCSinkResponder>>>> iter = sinkResponses.entrySet().iterator();
    while (iter.hasNext()) {
        Entry<Integer, Pair<Integer, List<CCSinkResponder>>> pair = iter.next();
        pair.getValue().setValue1(pair.getValue().getValue1() + 1);
        boolean canBeHandled = true;
        for (CCSinkResponder response : pair.getValue().getValue2()) {
            if (!response.isDone()) {
                canBeHandled = false;
                break;
            }
        }
        if (canBeHandled || pair.getValue().getValue1() > timeout) {
            // skip entry, if slot is not in the inventory (too high).
            boolean slotInInventory = pair.getKey() < invUtil.getSizeInventory();
            if (slotInInventory && handle(invUtil, pair.getKey(), pair.getValue().getValue2())) {
                stalled = false;
                lastSuceededStack = pair.getKey();
            }
            iter.remove();
            changed = true;
        }
    }
    if (changed) {
        checkSize();
    }
}
Also used : Entry(java.util.Map.Entry) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) List(java.util.List) ArrayList(java.util.ArrayList) CCSinkResponder(logisticspipes.proxy.computers.objects.CCSinkResponder) Pair(logisticspipes.utils.tuples.Pair)

Example 2 with CCSinkResponder

use of logisticspipes.proxy.computers.objects.CCSinkResponder in project LogisticsPipes by RS485.

the class ModuleCCBasedQuickSort method createSinkMessage.

private void createSinkMessage(int slot, ItemIdentifierStack stack) {
    List<CCSinkResponder> respones = new ArrayList<>();
    IRouter sourceRouter = _service.getRouter();
    if (sourceRouter == null) {
        return;
    }
    // get only pipes with generic interest
    BitSet routersIndex = ServerRouter.getRoutersInterestedIn((ItemIdentifier) null);
    // get the routing table
    List<ExitRoute> validDestinations = new ArrayList<>();
    for (int i = routersIndex.nextSetBit(0); i >= 0; i = routersIndex.nextSetBit(i + 1)) {
        IRouter r = SimpleServiceLocator.routerManager.getRouterUnsafe(i, false);
        List<ExitRoute> exits = sourceRouter.getDistanceTo(r);
        if (exits != null) {
            validDestinations.addAll(exits.stream().filter(e -> e.containsFlag(PipeRoutingConnectionType.canRouteTo)).collect(Collectors.toList()));
        }
    }
    Collections.sort(validDestinations);
    outer: for (ExitRoute candidateRouter : validDestinations) {
        if (candidateRouter.destination.getId().equals(sourceRouter.getId())) {
            continue;
        }
        for (IFilter filter : candidateRouter.filters) {
            if (filter.blockRouting() || (filter.isBlocked() == filter.isFilteredItem(stack.getItem()))) {
                continue outer;
            }
        }
        if (candidateRouter.destination != null && candidateRouter.destination.getLogisticsModule() != null) {
            respones.addAll(candidateRouter.destination.getLogisticsModule().queueCCSinkEvent(stack));
        }
    }
    sinkResponses.put(slot, new Pair<>(0, respones));
}
Also used : IRouter(logisticspipes.routing.IRouter) IFilter(logisticspipes.interfaces.routing.IFilter) ArrayList(java.util.ArrayList) BitSet(java.util.BitSet) CCSinkResponder(logisticspipes.proxy.computers.objects.CCSinkResponder) ExitRoute(logisticspipes.routing.ExitRoute)

Example 3 with CCSinkResponder

use of logisticspipes.proxy.computers.objects.CCSinkResponder in project LogisticsPipes by RS485.

the class ModuleCCBasedItemSink method queueCCSinkEvent.

@Override
public List<CCSinkResponder> queueCCSinkEvent(ItemIdentifierStack item) {
    CCSinkResponder resonse = new CCSinkResponder(item, _service.getSourceID(), eventQueuer);
    eventQueuer.queueEvent("ItemSink", new Object[] { SimpleServiceLocator.ccProxy.getAnswer(resonse) });
    return new OneList<>(resonse);
}
Also used : OneList(logisticspipes.utils.OneList) CCSinkResponder(logisticspipes.proxy.computers.objects.CCSinkResponder)

Example 4 with CCSinkResponder

use of logisticspipes.proxy.computers.objects.CCSinkResponder in project LogisticsPipes by RS485.

the class ModuleCCBasedQuickSort method handle.

private boolean handle(IInventoryUtil invUtil, int slot, List<CCSinkResponder> list) {
    if (list.isEmpty()) {
        return false;
    }
    ItemIdentifier ident = list.get(0).getStack().getItem();
    ItemStack stack = invUtil.getStackInSlot(slot);
    if (stack == null || !ItemIdentifier.get(stack).equals(ident)) {
        return false;
    }
    final IRouter source = _service.getRouter();
    List<Triplet<Integer, Double, CCSinkResponder>> posibilities = new ArrayList<>();
    for (CCSinkResponder sink : list) {
        if (!sink.isDone()) {
            continue;
        }
        if (sink.getCanSink() < 1) {
            continue;
        }
        IRouter r = SimpleServiceLocator.routerManager.getRouter(sink.getRouterId());
        if (r == null) {
            continue;
        }
        List<ExitRoute> ways = source.getDistanceTo(r);
        double minDistance = Double.MAX_VALUE;
        outer: for (ExitRoute route : ways) {
            for (IFilter filter : route.filters) {
                if (filter.blockRouting() || filter.isFilteredItem(ident) == filter.isBlocked()) {
                    continue outer;
                }
            }
            minDistance = Math.min(route.distanceToDestination, minDistance);
        }
        if (minDistance != Integer.MAX_VALUE) {
            posibilities.add(new Triplet<>(sink.getPriority(), minDistance, sink));
        }
    }
    if (posibilities.isEmpty()) {
        return false;
    }
    Collections.sort(posibilities, (o1, o2) -> {
        int c = o2.getValue1() - o1.getValue1();
        if (c != 0) {
            return c;
        }
        double e = o1.getValue2() - o2.getValue2();
        return e < 0 ? -1 : 1;
    });
    boolean sended = false;
    for (Triplet<Integer, Double, CCSinkResponder> triple : posibilities) {
        CCSinkResponder sink = triple.getValue3();
        if (sink.getCanSink() < 0) {
            continue;
        }
        stack = invUtil.getStackInSlot(slot);
        if (stack == null || stack.stackSize <= 0) {
            continue;
        }
        int amount = Math.min(stack.stackSize, sink.getCanSink());
        ItemStack extracted = invUtil.decrStackSize(slot, amount);
        _service.sendStack(extracted, sink.getRouterId(), ItemSendMode.Fast, null);
        sended = true;
    }
    return sended;
}
Also used : Triplet(logisticspipes.utils.tuples.Triplet) ArrayList(java.util.ArrayList) CCSinkResponder(logisticspipes.proxy.computers.objects.CCSinkResponder) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IRouter(logisticspipes.routing.IRouter) IFilter(logisticspipes.interfaces.routing.IFilter) ItemStack(net.minecraft.item.ItemStack) ExitRoute(logisticspipes.routing.ExitRoute)

Aggregations

CCSinkResponder (logisticspipes.proxy.computers.objects.CCSinkResponder)4 ArrayList (java.util.ArrayList)3 IFilter (logisticspipes.interfaces.routing.IFilter)2 ExitRoute (logisticspipes.routing.ExitRoute)2 IRouter (logisticspipes.routing.IRouter)2 BitSet (java.util.BitSet)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 OneList (logisticspipes.utils.OneList)1 PlayerCollectionList (logisticspipes.utils.PlayerCollectionList)1 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)1 Pair (logisticspipes.utils.tuples.Pair)1 Triplet (logisticspipes.utils.tuples.Triplet)1 ItemStack (net.minecraft.item.ItemStack)1