Search in sources :

Example 16 with IRouter

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

the class RequestRoutingLasersPacket method processPacket.

@Override
public void processPacket(EntityPlayer player) {
    LogisticsTileGenericPipe tile = this.getPipe(player.world);
    if (tile == null) {
        return;
    }
    if (tile.pipe instanceof CoreRoutedPipe) {
        IRouter router = ((CoreRoutedPipe) tile.pipe).getRouter();
        // this is here to allow players to manually trigger a network-wide LSA update
        router.forceLsaUpdate();
        List<List<ExitRoute>> exits = router.getRouteTable();
        HashMap<EnumFacing, ArrayList<ExitRoute>> routers = new HashMap<>();
        for (List<ExitRoute> exit : exits) {
            if (exit == null) {
                continue;
            }
            for (ExitRoute e : exit) {
                if (!routers.containsKey(e.exitOrientation)) {
                    routers.put(e.exitOrientation, new ArrayList<>());
                }
                if (!routers.get(e.exitOrientation).contains(e)) {
                    routers.get(e.exitOrientation).add(e);
                }
            }
        }
        ArrayList<LaserData> lasers = new ArrayList<>();
        firstPipe = true;
        for (final EnumFacing dir : routers.keySet()) {
            if (dir == null) {
                continue;
            }
            handleRouteInDirection(tile, dir, routers.get(dir), lasers, EnumSet.allOf(PipeRoutingConnectionType.class), new Log() {

                @Override
                void log(String log) {
                    if (LogisticsPipes.isDEBUG()) {
                        System.out.println(dir.name() + ": " + log);
                    }
                }
            });
        }
        lasers = compressLasers(lasers);
        MainProxy.sendPacketToPlayer(PacketHandler.getPacket(RoutingLaserPacket.class).setLasers(lasers), player);
    }
}
Also used : PipeRoutingConnectionType(logisticspipes.routing.PipeRoutingConnectionType) HashMap(java.util.HashMap) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) IRouter(logisticspipes.routing.IRouter) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) LaserData(logisticspipes.routing.LaserData) ExitRoute(logisticspipes.routing.ExitRoute)

Example 17 with IRouter

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

the class RequestRoutingLasersPacket method handleRouteInDirection.

private void handleRouteInDirection(final LogisticsTileGenericPipe pipeIn, ForgeDirection dirIn, ArrayList<ExitRoute> connectedRoutersIn, final List<LaserData> lasersIn, EnumSet<PipeRoutingConnectionType> connectionTypeIn, final Log logIn) {
    List<DataEntry> worklist = new LinkedList<>();
    worklist.add(new DataEntry(pipeIn, dirIn, connectedRoutersIn, lasersIn, connectionTypeIn, logIn));
    while (!worklist.isEmpty()) {
        final DataEntry entry = worklist.remove(0);
        final LogisticsTileGenericPipe pipe = entry.pipe;
        final ForgeDirection dir = entry.dir;
        final ArrayList<ExitRoute> connectedRouters = entry.connectedRouters;
        final List<LaserData> lasers = entry.lasers;
        final EnumSet<PipeRoutingConnectionType> connectionType = entry.connectionType;
        final Log log = entry.log;
        if (LPConstants.DEBUG) {
            log.log("Size: " + connectedRouters.size());
        }
        lasers.add(new LaserData(pipe.xCoord, pipe.yCoord, pipe.zCoord, dir, connectionType).setStartPipe(firstPipe));
        firstPipe = false;
        HashMap<CoreRoutedPipe, ExitRoute> map = PathFinder.paintAndgetConnectedRoutingPipes(pipe, dir, Configs.LOGISTICS_DETECTION_COUNT, Configs.LOGISTICS_DETECTION_LENGTH, (worldObj, laser) -> {
            if (pipe.getWorld() == worldObj) {
                lasers.add(laser);
            }
        }, connectionType);
        for (CoreRoutedPipe connectedPipe : map.keySet()) {
            IRouter newRouter = connectedPipe.getRouter();
            Iterator<ExitRoute> iRoutes = connectedRouters.iterator();
            while (iRoutes.hasNext()) {
                ExitRoute route = iRoutes.next();
                if (route.destination == newRouter) {
                    iRoutes.remove();
                }
            }
        }
        Map<CoreRoutedPipe, ArrayList<ExitRoute>> sort = new HashMap<>();
        for (ExitRoute routeTo : connectedRouters) {
            ExitRoute result = null;
            CoreRoutedPipe resultPipe = null;
            for (Entry<CoreRoutedPipe, ExitRoute> routeCanidate : map.entrySet()) {
                List<ExitRoute> distances = routeCanidate.getValue().destination.getDistanceTo(routeTo.destination);
                for (ExitRoute distance : distances) {
                    if (distance.isSameWay(routeTo)) {
                        if (result == null || result.distanceToDestination > distance.distanceToDestination) {
                            result = distance;
                            resultPipe = routeCanidate.getKey();
                        }
                    }
                }
            }
            if (result == null) {
                continue;
            }
            if (!sort.containsKey(resultPipe)) {
                sort.put(resultPipe, new ArrayList<>());
            }
            if (!sort.get(resultPipe).contains(result)) {
                sort.get(resultPipe).add(result);
            }
        }
        for (Entry<CoreRoutedPipe, ArrayList<ExitRoute>> connectedPipe : sort.entrySet()) {
            HashMap<ForgeDirection, ArrayList<ExitRoute>> routers = new HashMap<>();
            for (ExitRoute exit : connectedPipe.getValue()) {
                if (!routers.containsKey(exit.exitOrientation)) {
                    routers.put(exit.exitOrientation, new ArrayList<>());
                }
                if (!routers.get(exit.exitOrientation).contains(exit)) {
                    routers.get(exit.exitOrientation).add(exit);
                }
            }
            for (final ForgeDirection exitDir : routers.keySet()) {
                if (exitDir == ForgeDirection.UNKNOWN) {
                    continue;
                }
                worklist.add(new DataEntry(connectedPipe.getKey().container, exitDir, routers.get(exitDir), lasers, map.get(connectedPipe.getKey()).connectionDetails, new Log() {

                    @Override
                    void log(String logString) {
                        if (LPConstants.DEBUG) {
                            log.log(exitDir.name() + ": " + logString);
                        }
                    }
                }));
            }
        }
    }
}
Also used : PipeRoutingConnectionType(logisticspipes.routing.PipeRoutingConnectionType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) IRouter(logisticspipes.routing.IRouter) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) LinkedList(java.util.LinkedList) LaserData(logisticspipes.routing.LaserData) ExitRoute(logisticspipes.routing.ExitRoute)

Example 18 with IRouter

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

the class TrackingTask method tick.

public void tick(int tickCount, CoreRoutedPipe pipe) {
    if (tickCount % everyNthTick != 0) {
        return;
    }
    IRouter router = pipe.getRouter();
    if (router == null) {
        return;
    }
    amountRecorded[arrayPos++] = SimpleServiceLocator.logisticsManager.getAmountFor(item, router.getIRoutersByCost());
    if (arrayPos >= amountRecorded.length) {
        arrayPos = 0;
    }
}
Also used : IRouter(logisticspipes.routing.IRouter)

Example 19 with IRouter

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

the class ModuleCrafter method getNextConnectSatelliteId.

protected int getNextConnectSatelliteId(boolean prev, int x) {
    int closestIdFound = prev ? 0 : Integer.MAX_VALUE;
    if (_service == null) {
        return prev ? Math.max(0, satelliteId - 1) : satelliteId + 1;
    }
    for (final PipeItemsSatelliteLogistics satellite : PipeItemsSatelliteLogistics.AllSatellites) {
        CoreRoutedPipe satPipe = satellite;
        if (satPipe == null || satPipe.stillNeedReplace() || satPipe.getRouter() == null || satPipe.isFluidPipe()) {
            continue;
        }
        IRouter satRouter = satPipe.getRouter();
        List<ExitRoute> routes = getRouter().getDistanceTo(satRouter);
        if (routes != null && !routes.isEmpty()) {
            boolean filterFree = false;
            for (ExitRoute route : routes) {
                if (route.filters.isEmpty()) {
                    filterFree = true;
                    break;
                }
            }
            if (!filterFree) {
                continue;
            }
            if (x == -1) {
                if (!prev && satellite.satelliteId > satelliteId && satellite.satelliteId < closestIdFound) {
                    closestIdFound = satellite.satelliteId;
                } else if (prev && satellite.satelliteId < satelliteId && satellite.satelliteId > closestIdFound) {
                    closestIdFound = satellite.satelliteId;
                }
            } else {
                if (!prev && satellite.satelliteId > advancedSatelliteIdArray[x] && satellite.satelliteId < closestIdFound) {
                    closestIdFound = satellite.satelliteId;
                } else if (prev && satellite.satelliteId < advancedSatelliteIdArray[x] && satellite.satelliteId > closestIdFound) {
                    closestIdFound = satellite.satelliteId;
                }
            }
        }
    }
    if (closestIdFound == Integer.MAX_VALUE) {
        if (x == -1) {
            return satelliteId;
        } else {
            return advancedSatelliteIdArray[x];
        }
    }
    return closestIdFound;
}
Also used : PipeItemsSatelliteLogistics(logisticspipes.pipes.PipeItemsSatelliteLogistics) IRouter(logisticspipes.routing.IRouter) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) ExitRoute(logisticspipes.routing.ExitRoute)

Example 20 with IRouter

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

the class ModuleCrafter method getNextConnectFluidSatelliteId.

protected int getNextConnectFluidSatelliteId(boolean prev, int x) {
    int closestIdFound = prev ? 0 : Integer.MAX_VALUE;
    for (final PipeFluidSatellite satellite : PipeFluidSatellite.AllSatellites) {
        CoreRoutedPipe satPipe = satellite;
        if (satPipe == null || satPipe.stillNeedReplace() || satPipe.getRouter() == null || !satPipe.isFluidPipe()) {
            continue;
        }
        IRouter satRouter = satPipe.getRouter();
        List<ExitRoute> routes = getRouter().getDistanceTo(satRouter);
        if (routes != null && !routes.isEmpty()) {
            boolean filterFree = false;
            for (ExitRoute route : routes) {
                if (route.filters.isEmpty()) {
                    filterFree = true;
                    break;
                }
            }
            if (!filterFree) {
                continue;
            }
            if (x == -1) {
                if (!prev && satellite.satelliteId > liquidSatelliteId && satellite.satelliteId < closestIdFound) {
                    closestIdFound = satellite.satelliteId;
                } else if (prev && satellite.satelliteId < liquidSatelliteId && satellite.satelliteId > closestIdFound) {
                    closestIdFound = satellite.satelliteId;
                }
            } else {
                if (!prev && satellite.satelliteId > liquidSatelliteIdArray[x] && satellite.satelliteId < closestIdFound) {
                    closestIdFound = satellite.satelliteId;
                } else if (prev && satellite.satelliteId < liquidSatelliteIdArray[x] && satellite.satelliteId > closestIdFound) {
                    closestIdFound = satellite.satelliteId;
                }
            }
        }
    }
    if (closestIdFound == Integer.MAX_VALUE) {
        if (x == -1) {
            return liquidSatelliteId;
        } else {
            return liquidSatelliteIdArray[x];
        }
    }
    return closestIdFound;
}
Also used : IRouter(logisticspipes.routing.IRouter) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) ExitRoute(logisticspipes.routing.ExitRoute) PipeFluidSatellite(logisticspipes.pipes.PipeFluidSatellite)

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