Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity checking algorithm isn't 100% accurate. #1

Open
StefenSharkey opened this issue Oct 2, 2014 · 0 comments
Open

Entity checking algorithm isn't 100% accurate. #1

StefenSharkey opened this issue Oct 2, 2014 · 0 comments
Assignees

Comments

@StefenSharkey
Copy link
Owner

The entity checking algorithm occasionally grabs the wrong entity if another is too close to the player. Sometimes it will grab an entity behind the player, sometimes it'll grab an entity to the side, etc.

Another issue is that if there's a smaller entity (I.E. squid) in front of a larger entity (I.E. skeleton), the algorithm will return neither and will cause the preceding command to fail.

The algorithm is as follows.

public static Entity getEntityInCrosshairs(Player player) {
    int range = 10;
    Block[] blocks = player.getLineOfSight(null, range).toArray(new Block[0]);
    List<Entity> near = player.getNearbyEntities(range, range, range);

    for (Block block : blocks) {
      for (Entity entity : near) {
        if (entity.getLocation().distance(block.getLocation()) < 2) {
          return entity;
        }
      }
    }

    return null;
  }

It can also be found here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant