Worked on issue #7. Issue should be fixed now.
This commit is contained in:
@@ -28,6 +28,8 @@ public abstract class NPC {
|
||||
protected final String name = uuid.toString().replace("-", "").substring(0, 10);
|
||||
protected final int entityId = (int) Math.ceil(Math.random() * 100000) + 100000;
|
||||
|
||||
protected double cosFOV = Math.cos(Math.toRadians(60));
|
||||
|
||||
private final Set<UUID> shown = new HashSet<>();
|
||||
private final Set<UUID> autoHidden = new HashSet<>();
|
||||
|
||||
@@ -76,6 +78,14 @@ public abstract class NPC {
|
||||
}
|
||||
}
|
||||
|
||||
public void disableFOV() {
|
||||
this.cosFOV = 0; // Or equals Math.cos(1/2 * Math.PI).
|
||||
}
|
||||
|
||||
public void setFOV(double fov) {
|
||||
this.cosFOV = Math.cos(Math.toRadians(60));
|
||||
}
|
||||
|
||||
public Set<UUID> getShown() {
|
||||
return shown;
|
||||
}
|
||||
@@ -128,10 +138,14 @@ public abstract class NPC {
|
||||
if (auto) {
|
||||
sendShowPackets(player);
|
||||
} else {
|
||||
if (shown.contains(player.getUniqueId())) {
|
||||
if (isActuallyShown(player)) {
|
||||
throw new RuntimeException("Cannot call show method twice.");
|
||||
}
|
||||
|
||||
if (shown.contains(player.getUniqueId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
shown.add(player.getUniqueId());
|
||||
|
||||
if (player.getLocation().distance(location) <= autoHideDistance) {
|
||||
@@ -144,13 +158,10 @@ public abstract class NPC {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canSeeNPC(Player player) {
|
||||
private boolean canSeeNPC(Player player) {
|
||||
Vector dir = location.toVector().subtract(player.getEyeLocation().toVector()).normalize();
|
||||
double dot = dir.dot(player.getLocation().getDirection());
|
||||
|
||||
// 0.5 equals a FOV of 60 deg (but should be 0.55)
|
||||
// We want to spawn the NPC *just* before the player can see it.
|
||||
return dot >= 0.5;
|
||||
return dot >= cosFOV;
|
||||
}
|
||||
|
||||
// Internal method.
|
||||
|
||||
@@ -7,7 +7,6 @@ package net.jitse.npclib.listeners;
|
||||
import net.jitse.npclib.NPCManager;
|
||||
import net.jitse.npclib.api.NPC;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -55,13 +54,6 @@ public class PlayerListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
Location from = event.getFrom();
|
||||
Location to = event.getTo();
|
||||
|
||||
// if (from.getX() == to.getX() && from.getY() == to.getY() && from.getZ() == to.getZ()) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
handleMove(event.getPlayer());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user