I managed to do it this way. It's kinda messy but hopefully it will help you.
https://pastebin.com/Q0mVsJRi
RayTraceUtil.getTargetBlock(player, world, maxdistance)
This should give you the block you are looking at.
I'm new to modding so I'm not shure how correct this is.