Added square method to remove ugly code.
This commit is contained in:
@@ -129,7 +129,7 @@ public class PlayerListener implements Listener {
|
|||||||
double distanceSquared = location.distanceSquared(npc.getLocation());
|
double distanceSquared = location.distanceSquared(npc.getLocation());
|
||||||
|
|
||||||
int tempRange = Bukkit.getViewDistance() << 4;
|
int tempRange = Bukkit.getViewDistance() << 4;
|
||||||
boolean inRange = distanceSquared <= (hideDistance * hideDistance) && distanceSquared <= (tempRange * tempRange); // Avoids Math.pow due to how intensive it is. Could make a static utility function for it.
|
boolean inRange = distanceSquared <= square(hideDistance) && distanceSquared <= square(tempRange);
|
||||||
if (npc.getAutoHidden().contains(player.getUniqueId())) {
|
if (npc.getAutoHidden().contains(player.getUniqueId())) {
|
||||||
// Check if the player and NPC are within the range to sendShowPackets it again.
|
// Check if the player and NPC are within the range to sendShowPackets it again.
|
||||||
if (inRange) {
|
if (inRange) {
|
||||||
@@ -145,4 +145,9 @@ public class PlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Avoiding Math.pow due to how resource intensive it is.
|
||||||
|
private double square(double val) {
|
||||||
|
return val * val;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user