I've seen some ways on how to go about doing this for extended sword reach (checks entities in surrounding AABB, checks if the length of the vector from the player's eye to an entity is within said range, checks the angle, then hits the entity). I found an example of this being applied in the Aether mod's source code (here) which with just a few changes works well in 1.15.2.
The thing is, I was trying to think of another ways to make this work. For instance, I'd like to use the player's eyesight vector and ray trace from there to a certain length (say, 8 blocks' distance) and check if the ray hits an entity's bounding box. This way, I wouldn't need to check all the surrounding entities.
Endermen use the canEntityBeSeen method, and that one draws a vector and checks that it doesn't collide with any blocks. The problem is, this method already knows the position of both the enderman in question and the player.
One option was to use a method found in the Minecraft class, but of course, that would only work client-side.
Also, by the way, is there any replacement for onEntitySwing on 1.15.2? I've been using onItemRightClick for now to test, but I want to check for entities using it (so a skeleton, for instance, can use it as a sword). Which method would I have to override?