/**
* Rechecks the piped connection to all adjacent routers as well as discover new ones.
*/
private boolean recheckAdjacent() {
boolean adjacentChanged = false;
CoreRoutedPipe thisPipe = getPipe();
if (thisPipe == null) return false;
HashMap<CoreRoutedPipe, ExitRoute> adjacent;
List<Pair<ILogisticsPowerProvider,List<IFilter>>> power;
List<Pair<ISubSystemPowerProvider,List<IFilter>>> subSystemPower;
PathFinder finder = new PathFinder(thisPipe.container, Configs.LOGISTICS_DETECTION_COUNT, Configs.LOGISTICS_DETECTION_LENGTH);
power = finder.powerNodes;
subSystemPower = finder.subPowerProvider;
adjacent = finder.result;
for(CoreRoutedPipe pipe : adjacent.keySet()) {
if(pipe.stillNeedReplace()) {
return false;
}
}
boolean[] oldSideDisconnected = sideDisconnected;
sideDisconnected = new boolean[6];
checkSecurity(adjacent);
boolean changed = false;
for(int i=0;i<6;i++) {
changed |= sideDisconnected[i] != oldSideDisconnected[i];
}
if(changed) {
CoreRoutedPipe pipe = getPipe();
if (pipe != null) {
pipe.getWorld().notifyBlocksOfNeighborChange(pipe.getX(), pipe.getY(), pipe.getZ(), pipe.getWorld().getBlock(pipe.getX(), pipe.getY(), pipe.getZ()));
pipe.refreshConnectionAndRender(false);
}
adjacentChanged = true;
}
if(_adjacent.size() != adjacent.size()) {
adjacentChanged = true;
}
for (CoreRoutedPipe pipe : _adjacent.keySet()) {
if(!adjacent.containsKey(pipe)) {
adjacentChanged = true;
}
}
if(_powerAdjacent!=null) {
if(power==null){
adjacentChanged = true;
} else {
for (Pair<ILogisticsPowerProvider,List<IFilter>> provider : _powerAdjacent){
if(!power.contains(provider))
adjacentChanged = true;
}
}
}
if(power!=null){
if(_powerAdjacent==null) {
adjacentChanged = true;
} else {
for (Pair<ILogisticsPowerProvider,List<IFilter>> provider : power){
if(!_powerAdjacent.contains(provider))
adjacentChanged = true;
}
}
}
if(_subSystemPowerAdjacent!=null) {
if(subSystemPower==null){
adjacentChanged = true;
} else {
for (Pair<ISubSystemPowerProvider, List<IFilter>> provider : _subSystemPowerAdjacent){
if(!subSystemPower.contains(provider))
adjacentChanged = true;
}
}
}
if(subSystemPower!=null){
if(_subSystemPowerAdjacent==null) {
adjacentChanged = true;
} else {
for (Pair<ISubSystemPowerProvider, List<IFilter>> provider : subSystemPower){
if(!_subSystemPowerAdjacent.contains(provider))
adjacentChanged = true;
}
}
}
for (Entry<CoreRoutedPipe, ExitRoute> pipe : adjacent.entrySet()) {
ExitRoute oldExit = _adjacent.get(pipe.getKey());
if (oldExit==null){
adjacentChanged = true;
break;
}
ExitRoute newExit = pipe.getValue();
if (!newExit.equals(oldExit)) {
adjacentChanged = true;
break;
}
}
if (adjacentChanged) {
HashMap<IRouter, ExitRoute> adjacentRouter = new HashMap<IRouter, ExitRoute>();
EnumSet<ForgeDirection> routedexits = EnumSet.noneOf(ForgeDirection.class);
EnumMap<ForgeDirection, Integer> subpowerexits = new EnumMap<ForgeDirection, Integer>(ForgeDirection.class);
for(Entry<CoreRoutedPipe,ExitRoute> pipe:adjacent.entrySet()) {
adjacentRouter.put(pipe.getKey().getRouter(), pipe.getValue());
if((pipe.getValue().connectionDetails.contains(PipeRoutingConnectionType.canRouteTo) || pipe.getValue().connectionDetails.contains(PipeRoutingConnectionType.canRequestFrom) && !routedexits.contains(pipe.getValue().exitOrientation))) {
routedexits.add(pipe.getValue().exitOrientation);
}
if(!subpowerexits.containsKey(pipe.getValue().exitOrientation) && pipe.getValue().connectionDetails.contains(PipeRoutingConnectionType.canPowerSubSystemFrom)) {
subpowerexits.put(pipe.getValue().exitOrientation, PathFinder.messureDistanceToNextRoutedPipe(this.getLPPosition(), pipe.getValue().exitOrientation, pipe.getKey().getWorld()));
}
}
_adjacent = Collections.unmodifiableMap(adjacent);
_adjacentRouter = Collections.unmodifiableMap(adjacentRouter);
if(power != null){