use of blusunrize.immersiveengineering.api.fluid.IFluidPipe in project ImmersiveEngineering by BluSunrize.
the class TileEntityFluidPipe method getConnectedFluidHandlers.
public static Set<DirectionalFluidOutput> getConnectedFluidHandlers(BlockPos node, World world) {
if (indirectConnections.containsKey(node))
return indirectConnections.get(node);
ArrayList<BlockPos> openList = new ArrayList();
ArrayList<BlockPos> closedList = new ArrayList();
Set<DirectionalFluidOutput> fluidHandlers = Collections.newSetFromMap(new ConcurrentHashMap<DirectionalFluidOutput, Boolean>());
openList.add(node);
while (!openList.isEmpty() && closedList.size() < 1024) {
BlockPos next = openList.get(0);
if (world.isBlockLoaded(next)) {
TileEntity pipeTile = world.getTileEntity(next);
if (!closedList.contains(next) && (pipeTile instanceof IFluidPipe)) {
if (pipeTile instanceof TileEntityFluidPipe)
closedList.add(next);
IFluidTankProperties[] tankInfo;
for (int i = 0; i < 6; i++) {
// boolean b = (te instanceof TileEntityFluidPipe)? (((TileEntityFluidPipe) te).sideConfig[i]==0): (((TileEntityFluidPump) te).sideConfig[i]==1);
EnumFacing fd = EnumFacing.getFront(i);
if (((IFluidPipe) pipeTile).hasOutputConnection(fd)) {
BlockPos nextPos = next.offset(fd);
if (world.isBlockLoaded(nextPos)) {
TileEntity adjacentTile = world.getTileEntity(nextPos);
if (adjacentTile != null)
if (adjacentTile instanceof TileEntityFluidPipe)
openList.add(nextPos);
else if (adjacentTile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, fd.getOpposite())) {
IFluidHandler handler = adjacentTile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, fd.getOpposite());
tankInfo = handler.getTankProperties();
if (tankInfo != null && tankInfo.length > 0)
fluidHandlers.add(new DirectionalFluidOutput(handler, adjacentTile, fd));
}
}
}
}
}
}
openList.remove(0);
}
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
if (!indirectConnections.containsKey(node)) {
indirectConnections.put(node, newSetFromMap(new ConcurrentHashMap<DirectionalFluidOutput, Boolean>()));
indirectConnections.get(node).addAll(fluidHandlers);
}
}
return fluidHandlers;
}
Aggregations