mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-13 22:25:44 +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
|
* Finds a new look-close target
|
||||||
*/
|
*/
|
||||||
public void findNewTarget() {
|
public void findNewTarget() {
|
||||||
double min = Integer.MAX_VALUE;
|
double min = range * range;
|
||||||
for (Entity entity : npc.getEntity().getNearbyEntities(range, range, range)) {
|
for (Entity entity : npc.getEntity().getNearbyEntities(range, range, range)) {
|
||||||
if (!(entity instanceof Player))
|
if (!(entity instanceof Player))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Player player = (Player) entity;
|
Player player = (Player) entity;
|
||||||
Location location = player.getLocation(CACHE_LOCATION);
|
Location location = player.getLocation(CACHE_LOCATION);
|
||||||
if (location.getWorld() != NPC_LOCATION.getWorld())
|
if (location.getWorld() != NPC_LOCATION.getWorld())
|
||||||
continue;
|
continue;
|
||||||
double dist = location.distanceSquared(NPC_LOCATION);
|
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;
|
continue;
|
||||||
if (dist < min) {
|
|
||||||
min = dist;
|
min = dist;
|
||||||
lookingAt = player;
|
lookingAt = player;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public int getRandomLookDelay() {
|
public int getRandomLookDelay() {
|
||||||
return randomLookDelay;
|
return randomLookDelay;
|
||||||
|
Loading…
Reference in New Issue
Block a user