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);
}
}
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);
}
}
}));
}
}
}
}
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;
}
}
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;
}
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;
}
Aggregations