Further refactor lookclose

This commit is contained in:
fullwall 2021-01-20 20:27:46 +08:00
parent fe3f12e424
commit eb9764aeb0

View File

@ -67,22 +67,19 @@ 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;
}
min = dist;
lookingAt = player;
}
}