Search in sources :

Example 1 with IRouter

use of logisticspipes.routing.IRouter 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 IRouter

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

the class LogisticsPowerProviderTileEntity method updateEntity.

@Override
public void updateEntity() {
    super.updateEntity();
    pauseRequesting = false;
    if (!init) {
        if (MainProxy.isClient(getWorld())) {
            LogisticsHUDRenderer.instance().add(this);
        }
        init = true;
    }
    double globalRequest = orders.values().stream().reduce(Double::sum).orElse(0.0);
    if (globalRequest > 0) {
        double fullfillRatio = Math.min(1, Math.min(internalStorage, getMaxProvidePerTick()) / globalRequest);
        if (fullfillRatio > 0) {
            for (Entry<Integer, Double> order : orders.entrySet()) {
                double toSend = order.getValue() * fullfillRatio;
                if (toSend > internalStorage) {
                    toSend = internalStorage;
                }
                IRouter destinationRouter = SimpleServiceLocator.routerManager.getRouter(order.getKey());
                if (destinationRouter != null && destinationRouter.getPipe() != null) {
                    WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(this);
                    outerTiles: for (AdjacentTileEntity adjacent : worldCoordinates.getAdjacentTileEntities().collect(Collectors.toList())) {
                        if (adjacent.tileEntity instanceof LogisticsTileGenericPipe) {
                            if (((LogisticsTileGenericPipe) adjacent.tileEntity).pipe instanceof CoreRoutedPipe) {
                                if (((CoreRoutedPipe) ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe).stillNeedReplace()) {
                                    continue;
                                }
                                IRouter sourceRouter = ((CoreRoutedPipe) ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe).getRouter();
                                if (sourceRouter != null) {
                                    outerRouters: for (ExitRoute exit : sourceRouter.getDistanceTo(destinationRouter)) {
                                        if (exit.containsFlag(PipeRoutingConnectionType.canPowerSubSystemFrom)) {
                                            for (IFilter filter : exit.filters) {
                                                if (filter.blockPower()) {
                                                    continue outerRouters;
                                                }
                                            }
                                            CoreRoutedPipe pipe = sourceRouter.getPipe();
                                            if (pipe != null && pipe.isInitialized()) {
                                                pipe.container.addLaser(adjacent.direction.getOpposite(), 1, getLaserColor(), true, true);
                                            }
                                            sendPowerLaserPackets(sourceRouter, destinationRouter, exit.exitOrientation, exit.exitOrientation != adjacent.direction);
                                            internalStorage -= toSend;
                                            handlePower(destinationRouter.getPipe(), toSend);
                                            break outerTiles;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    orders.clear();
    if (MainProxy.isServer(worldObj)) {
        if (internalStorage != lastUpdateStorage) {
            updateClients();
            lastUpdateStorage = internalStorage;
        }
    }
}
Also used : IRouter(logisticspipes.routing.IRouter) IFilter(logisticspipes.interfaces.routing.IFilter) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) ExitRoute(logisticspipes.routing.ExitRoute) AdjacentTileEntity(network.rs485.logisticspipes.world.WorldCoordinatesWrapper.AdjacentTileEntity)

Example 3 with IRouter

use of logisticspipes.routing.IRouter 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 4 with IRouter

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

the class ModuleCrafter method isSatelliteConnected.

public boolean isSatelliteConnected() {
    final List<ExitRoute> routes = getRouter().getIRoutersByCost();
    if (!getUpgradeManager().isAdvancedSatelliteCrafter()) {
        if (satelliteId == 0) {
            return true;
        }
        for (final PipeItemsSatelliteLogistics satellite : PipeItemsSatelliteLogistics.AllSatellites) {
            if (satellite.satelliteId == satelliteId) {
                CoreRoutedPipe satPipe = satellite;
                if (satPipe == null || satPipe.stillNeedReplace() || satPipe.getRouter() == null) {
                    continue;
                }
                IRouter satRouter = satPipe.getRouter();
                for (ExitRoute route : routes) {
                    if (route.destination == satRouter) {
                        return true;
                    }
                }
            }
        }
    } else {
        boolean foundAll = true;
        for (int i = 0; i < 9; i++) {
            boolean foundOne = false;
            if (advancedSatelliteIdArray[i] == 0) {
                continue;
            }
            for (final PipeItemsSatelliteLogistics satellite : PipeItemsSatelliteLogistics.AllSatellites) {
                if (satellite.satelliteId == advancedSatelliteIdArray[i]) {
                    CoreRoutedPipe satPipe = satellite;
                    if (satPipe == null || satPipe.stillNeedReplace() || satPipe.getRouter() == null) {
                        continue;
                    }
                    IRouter satRouter = satPipe.getRouter();
                    for (ExitRoute route : routes) {
                        if (route.destination == satRouter) {
                            foundOne = true;
                            break;
                        }
                    }
                }
            }
            foundAll &= foundOne;
        }
        return foundAll;
    }
    //TODO check for FluidCrafter
    return false;
}
Also used : PipeItemsSatelliteLogistics(logisticspipes.pipes.PipeItemsSatelliteLogistics) IRouter(logisticspipes.routing.IRouter) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) ExitRoute(logisticspipes.routing.ExitRoute)

Example 5 with IRouter

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

the class LogisticsManager method hasDestination.

/**
	 * Method used to check if a given stack has a destination.
	 * 
	 * @return Triplet of destinationSimpleID, sinkreply, relays; null if
	 *         nothing found
	 * @param stack
	 *            The stack to check if it has destination.
	 * @param allowDefault
	 *            Boolean, if true then a default route will be considered a
	 *            valid destination.
	 * @param sourceRouter
	 *            The UUID of the router pipe that wants to send the stack.
	 * @param excludeSource
	 *            Boolean, true means it will not consider the pipe itself as a
	 *            valid destination.
	 */
@Override
public Triplet<Integer, SinkReply, List<IFilter>> hasDestination(ItemIdentifier stack, boolean allowDefault, int sourceID, List<Integer> routerIDsToExclude) {
    IRouter sourceRouter = SimpleServiceLocator.routerManager.getRouter(sourceID);
    if (sourceRouter == null) {
        return null;
    }
    BitSet routersIndex = ServerRouter.getRoutersInterestedIn(stack);
    // 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);
    Triplet<Integer, SinkReply, List<IFilter>> search = getBestReply(stack, sourceRouter, validDestinations, true, routerIDsToExclude, null, allowDefault);
    if (search.getValue2() == null) {
        return null;
    }
    if (!allowDefault && search.getValue2().isDefault) {
        return null;
    }
    return search;
}
Also used : IRouter(logisticspipes.routing.IRouter) SinkReply(logisticspipes.utils.SinkReply) BitSet(java.util.BitSet) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ExitRoute(logisticspipes.routing.ExitRoute)

Aggregations

IRouter (logisticspipes.routing.IRouter)32 ExitRoute (logisticspipes.routing.ExitRoute)19 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)16 ArrayList (java.util.ArrayList)15 LinkedList (java.util.LinkedList)13 List (java.util.List)12 IFilter (logisticspipes.interfaces.routing.IFilter)10 PipeRoutingConnectionType (logisticspipes.routing.PipeRoutingConnectionType)8 Pair (logisticspipes.utils.tuples.Pair)7 ItemStack (net.minecraft.item.ItemStack)7 BitSet (java.util.BitSet)6 HashMap (java.util.HashMap)6 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)6 Map (java.util.Map)5 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)5 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)5 EnumFacing (net.minecraft.util.EnumFacing)5 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)4 IResource (logisticspipes.request.resources.IResource)4 LaserData (logisticspipes.routing.LaserData)4