Just take a look at the teleport class of LiquidBounce, you should be able to find the code that gets the block you are looking at and how to determine the distance to it.
By the way, if you want to teleport more than 10 blocks, you have to send several packets.
https://github.com/CCBlueX/LiquidBounce/blob/master/1.8.9-Forge/src/main/java/net/ccbluex/liquidbounce/features/module/modules/exploit/Teleport.java