I looked at how Advanced Fluid Handling works and correctly detecting orphans of its pipes is just too difficult, which is why I added the Underground pipe mode setting . If you set that to Strict it should at least only check the base game's pipes.
Technical details: certain entities have a neighbours property
- For underground belts this returns a reference to the other end of the underground belt, making it very easy to check
- For underground pipes this returns a list of all connected entities, both underground and via the surface pipe. The way I check for an orphan is to loop over these connected entities, check if it is also an underground pipe, which direction it is facing, and which direction it is relative to the pipe I am checking, to detect if it is connected via underground or the surface.