use of org.spongepowered.api.block.BlockTypes.GLASS in project modules-extra by CubeEngine.
the class ItemDuctManager method findNetwork.
private void findNetwork(LastDuct last, Network network, int depth) {
if (depth > maxDepth) {
network.errors.add(last.loc);
return;
}
Map<Direction, Location<World>> map = new HashMap<>();
Queue<Location<World>> next = new LinkedList<>();
next.offer(last.loc);
do {
// TODO limit direction with glass panes
Set<Direction> dirs = directions;
for (Direction dir : dirs) {
if (!dir.equals(last.from.getOpposite())) {
Location<World> rel = last.loc.getRelative(dir);
if (last.isCompatible(rel)) {
if (// No loops allowed
network.pipes.contains(rel)) {
network.errors.add(rel);
network.errors.add(last.loc);
} else {
network.pipes.add(rel);
map.put(dir, rel);
}
}
// ExitPiston?
if (rel.getBlockType().equals(PISTON) && rel.get(Keys.DIRECTION).orElse(Direction.NONE).equals(dir)) {
if (rel.getRelative(dir).get(DuctData.class).map(d -> d.get(dir.getOpposite()).isPresent()).orElse(false)) {
network.exitPoints.put(rel, rel.getRelative(dir).get(DuctData.class).get());
}
}
// Storage Chest
if (last.storage) {
rel.getTileEntity().ifPresent(te -> {
if (te instanceof Carrier) {
network.storage.add(rel);
}
});
}
}
}
if (map.size() > 1) {
for (Map.Entry<Direction, Location<World>> entry : map.entrySet()) {
findNetwork(new LastDuct(entry.getValue(), entry.getKey()), network, depth + 1);
}
} else if (map.size() == 1) {
for (Map.Entry<Direction, Location<World>> entry : map.entrySet()) {
last.update(entry.getValue(), entry.getKey());
}
next.offer(last.loc);
}
// else nothing found here
next.poll();
map.clear();
} while (!next.isEmpty());
}
Aggregations