mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-12 13:44:07 +01:00
Further refactor lookclose
This commit is contained in:
parent
fe3f12e424
commit
eb9764aeb0
@ -67,24 +67,21 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable
|
||||
* Finds a new look-close target
|
||||
*/
|
||||
public void findNewTarget() {
|
||||
double min = Integer.MAX_VALUE;
|
||||
double min = range * range;
|
||||
for (Entity entity : npc.getEntity().getNearbyEntities(range, range, range)) {
|
||||
if (!(entity instanceof Player))
|
||||
continue;
|
||||
|
||||
Player player = (Player) entity;
|
||||
Location location = player.getLocation(CACHE_LOCATION);
|
||||
if (location.getWorld() != NPC_LOCATION.getWorld())
|
||||
continue;
|
||||
double dist = location.distanceSquared(NPC_LOCATION);
|
||||
if (dist > range * range || CitizensAPI.getNPCRegistry().getNPC(entity) != null || isInvisible(player))
|
||||
if (dist > min || CitizensAPI.getNPCRegistry().getNPC(entity) != null || isInvisible(player))
|
||||
continue;
|
||||
if (dist < min) {
|
||||
min = dist;
|
||||
lookingAt = player;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getRandomLookDelay() {
|
||||
return randomLookDelay;
|
||||
|
Loading…
Reference in New Issue
Block a user