Search in sources :

Example 1 with Triplet

use of logisticspipes.utils.tuples.Triplet in project LogisticsPipes by RS485.

the class LogisticsPowerProviderTileEntity method sendPowerLaserPackets.

private void sendPowerLaserPackets(IRouter sourceRouter, IRouter destinationRouter, ForgeDirection exitOrientation, boolean addBall) {
    if (sourceRouter == destinationRouter) {
        return;
    }
    LinkedList<Triplet<IRouter, ForgeDirection, Boolean>> todo = new LinkedList<>();
    todo.add(new Triplet<>(sourceRouter, exitOrientation, addBall));
    while (!todo.isEmpty()) {
        Triplet<IRouter, ForgeDirection, Boolean> part = todo.pollFirst();
        List<ExitRoute> exits = part.getValue1().getRoutersOnSide(part.getValue2());
        for (ExitRoute exit : exits) {
            if (exit.containsFlag(PipeRoutingConnectionType.canPowerSubSystemFrom)) {
                // Find only result (caused by only straight connections)
                int distance = part.getValue1().getDistanceToNextPowerPipe(exit.exitOrientation);
                CoreRoutedPipe pipe = part.getValue1().getPipe();
                if (pipe != null && pipe.isInitialized()) {
                    pipe.container.addLaser(exit.exitOrientation, distance, getLaserColor(), false, part.getValue3());
                }
                // Use new sourceRouter
                IRouter nextRouter = exit.destination;
                if (nextRouter == destinationRouter) {
                    return;
                }
                outerRouters: for (ExitRoute newExit : nextRouter.getDistanceTo(destinationRouter)) {
                    if (newExit.containsFlag(PipeRoutingConnectionType.canPowerSubSystemFrom)) {
                        for (IFilter filter : newExit.filters) {
                            if (filter.blockPower()) {
                                continue outerRouters;
                            }
                        }
                        todo.addLast(new Triplet<>(nextRouter, newExit.exitOrientation, newExit.exitOrientation != exit.exitOrientation));
                    }
                }
            }
        }
    }
}
Also used : Triplet(logisticspipes.utils.tuples.Triplet) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) LinkedList(java.util.LinkedList) IRouter(logisticspipes.routing.IRouter) IFilter(logisticspipes.interfaces.routing.IFilter) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ExitRoute(logisticspipes.routing.ExitRoute)

Example 2 with Triplet

use of logisticspipes.utils.tuples.Triplet 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)

Example 3 with Triplet

use of logisticspipes.utils.tuples.Triplet in project LogisticsPipes by RS485.

the class CoreRoutedPipe method updateEntity.

@Override
public final void updateEntity() {
    debug.tick();
    spawnParticleTick();
    if (stillNeedReplace) {
        stillNeedReplace = false;
        getWorld().notifyBlockChange(getX(), getY(), getZ(), getWorld().getBlock(getX(), getY(), getZ()));
        /* TravelingItems are just held by a pipe, they don't need to know their world
			 * for(Triplet<IRoutedItem, ForgeDirection, ItemSendMode> item : _sendQueue) {
				//assign world to any entityitem we created in readfromnbt
				item.getValue1().getTravelingItem().setWorld(getWorld());
			}*/
        //first tick just create a router and do nothing.
        firstInitialiseTick();
        return;
    }
    if (repeatFor > 0) {
        if (delayTo < System.currentTimeMillis()) {
            delayTo = System.currentTimeMillis() + 200;
            repeatFor--;
            getWorld().markBlockForUpdate(getX(), getY(), getZ());
        }
    }
    // remove old items _inTransit -- these should have arrived, but have probably been lost instead. In either case, it will allow a re-send so that another attempt to re-fill the inventory can be made.
    while (_inTransitToMe.peek() != null && _inTransitToMe.peek().getTickToTimeOut() <= 0) {
        final ItemRoutingInformation p = _inTransitToMe.poll();
        if (LPConstants.DEBUG) {
            LogisticsPipes.log.info("Timed Out: " + p.getItem().getFriendlyName() + " (" + p.hashCode() + ")");
        }
        debug.log("Timed Out: " + p.getItem().getFriendlyName() + " (" + p.hashCode() + ")");
    }
    //update router before ticking logic/transport
    getRouter().update(getWorld().getTotalWorldTime() % Configs.LOGISTICS_DETECTION_FREQUENCY == _delayOffset || _initialInit || recheckConnections, this);
    recheckConnections = false;
    getOriginalUpgradeManager().securityTick();
    super.updateEntity();
    if (isNthTick(200)) {
        getCacheHolder().trigger(null);
    }
    // from BaseRoutingLogic
    if (--throttleTimeLeft <= 0) {
        throttledUpdateEntity();
        throttleTimeLeft = throttleTime;
    }
    ignoreDisableUpdateEntity();
    _initialInit = false;
    if (!_sendQueue.isEmpty()) {
        if (getItemSendMode() == ItemSendMode.Normal) {
            Triplet<IRoutedItem, ForgeDirection, ItemSendMode> itemToSend = _sendQueue.getFirst();
            sendRoutedItem(itemToSend.getValue1(), itemToSend.getValue2());
            _sendQueue.removeFirst();
            for (int i = 0; i < 16 && !_sendQueue.isEmpty() && _sendQueue.getFirst().getValue3() == ItemSendMode.Fast; i++) {
                if (!_sendQueue.isEmpty()) {
                    itemToSend = _sendQueue.getFirst();
                    sendRoutedItem(itemToSend.getValue1(), itemToSend.getValue2());
                    _sendQueue.removeFirst();
                }
            }
            sendQueueChanged(false);
        } else if (getItemSendMode() == ItemSendMode.Fast) {
            for (int i = 0; i < 16; i++) {
                if (!_sendQueue.isEmpty()) {
                    Triplet<IRoutedItem, ForgeDirection, ItemSendMode> itemToSend = _sendQueue.getFirst();
                    sendRoutedItem(itemToSend.getValue1(), itemToSend.getValue2());
                    _sendQueue.removeFirst();
                }
            }
            sendQueueChanged(false);
        } else if (getItemSendMode() == null) {
            throw new UnsupportedOperationException("getItemSendMode() can't return null. " + this.getClass().getName());
        } else {
            throw new UnsupportedOperationException("getItemSendMode() returned unhandled value. " + getItemSendMode().name() + " in " + this.getClass().getName());
        }
    }
    if (MainProxy.isClient(getWorld())) {
        return;
    }
    checkTexturePowered();
    if (!isEnabled()) {
        return;
    }
    enabledUpdateEntity();
    if (getLogisticsModule() == null) {
        return;
    }
    getLogisticsModule().tick();
}
Also used : ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) Triplet(logisticspipes.utils.tuples.Triplet) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 4 with Triplet

use of logisticspipes.utils.tuples.Triplet in project LogisticsPipes by RS485.

the class PipeTransportLogistics method dropBuffer.

public void dropBuffer() {
    Iterator<Triplet<ItemIdentifierStack, Pair<Integer, Integer>, LPTravelingItemServer>> iterator = _itemBuffer.iterator();
    while (iterator.hasNext()) {
        ItemIdentifierStack next = iterator.next().getValue1();
        MainProxy.dropItems(getWorld(), next.makeNormalStack(), getPipe().getX(), getPipe().getY(), getPipe().getZ());
        iterator.remove();
    }
}
Also used : Triplet(logisticspipes.utils.tuples.Triplet) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack)

Example 5 with Triplet

use of logisticspipes.utils.tuples.Triplet in project LogisticsPipes by RS485.

the class LPItemDuct method transferItem.

@Override
public void transferItem(TravelingItem item) {
    ItemRoutingInformation info = (ItemRoutingInformation) item.lpRoutingInformation;
    if (info != null) {
        info.setItem(ItemIdentifierStack.getFromStack(item.stack));
        LPTravelingItemServer lpItem = new LPTravelingItemServer(info);
        lpItem.setSpeed(info._transportMode == TransportMode.Active ? 0.3F : 0.2F);
        pipe.pipe.transport.injectItem(lpItem, ForgeDirection.getOrientation(item.direction));
    } else if (item.stack != null) {
        int consumed = pipe.injectItem(item.stack, true, dir);
        item.stack.stackSize -= consumed;
        if (item.stack.stackSize > 0) {
            pipe.pipe.transport._itemBuffer.add(new Triplet<>(ItemIdentifierStack.getFromStack(item.stack), new Pair<>(20 * 2, 0), null));
        }
    }
}
Also used : ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) Triplet(logisticspipes.utils.tuples.Triplet) LPTravelingItemServer(logisticspipes.transport.LPTravelingItem.LPTravelingItemServer)

Aggregations

Triplet (logisticspipes.utils.tuples.Triplet)7 IRouter (logisticspipes.routing.IRouter)3 ArrayList (java.util.ArrayList)2 IFilter (logisticspipes.interfaces.routing.IFilter)2 ExitRoute (logisticspipes.routing.ExitRoute)2 ItemRoutingInformation (logisticspipes.routing.ItemRoutingInformation)2 LPTravelingItemServer (logisticspipes.transport.LPTravelingItem.LPTravelingItemServer)2 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)2 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)2 TravelingItem (cofh.thermaldynamics.duct.item.TravelingItem)1 Route (cofh.thermaldynamics.multiblock.Route)1 RouteCache (cofh.thermaldynamics.multiblock.RouteCache)1 Method (java.lang.reflect.Method)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ILPTEInformation (logisticspipes.asm.te.ILPTEInformation)1 IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)1 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)1 CCSinkResponder (logisticspipes.proxy.computers.objects.CCSinkResponder)1 LPTravelingItem (logisticspipes.transport.LPTravelingItem)1