Work on issue #7 (skin rendering issue).
This commit is contained in:
parent
11936e630c
commit
cc0c64a610
|
@ -15,6 +15,7 @@ import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
@ -113,6 +114,17 @@ public abstract class NPC {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!canSeeNPC(player)) {
|
||||||
|
if (!auto) {
|
||||||
|
shown.add(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!autoHidden.contains(player.getUniqueId())) {
|
||||||
|
autoHidden.add(player.getUniqueId());
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (auto) {
|
if (auto) {
|
||||||
sendShowPackets(player);
|
sendShowPackets(player);
|
||||||
} else {
|
} else {
|
||||||
|
@ -132,6 +144,15 @@ public abstract class NPC {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean canSeeNPC(Player player) {
|
||||||
|
Vector dir = location.toVector().subtract(player.getEyeLocation().toVector()).normalize();
|
||||||
|
double dot = dir.dot(player.getLocation().getDirection());
|
||||||
|
Bukkit.broadcastMessage("dot: " + dot);
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
// Internal method.
|
// Internal method.
|
||||||
protected abstract void sendShowPackets(Player player);
|
protected abstract void sendShowPackets(Player player);
|
||||||
|
|
||||||
|
|
|
@ -58,9 +58,9 @@ public class PlayerListener implements Listener {
|
||||||
Location from = event.getFrom();
|
Location from = event.getFrom();
|
||||||
Location to = event.getTo();
|
Location to = event.getTo();
|
||||||
|
|
||||||
if (from.getX() == to.getX() && from.getY() == to.getY() && from.getZ() == to.getZ()) {
|
// if (from.getX() == to.getX() && from.getY() == to.getY() && from.getZ() == to.getZ()) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
handleMove(event.getPlayer());
|
handleMove(event.getPlayer());
|
||||||
}
|
}
|
||||||
|
@ -89,14 +89,14 @@ public class PlayerListener implements Listener {
|
||||||
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) {
|
||||||
npc.show(player, true);
|
|
||||||
npc.getAutoHidden().remove(player.getUniqueId());
|
npc.getAutoHidden().remove(player.getUniqueId());
|
||||||
|
npc.show(player, true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Check if the player and NPC are out of range to sendHidePackets it.
|
// Check if the player and NPC are out of range to sendHidePackets it.
|
||||||
if (!inRange) {
|
if (!inRange) {
|
||||||
npc.hide(player, true, true);
|
|
||||||
npc.getAutoHidden().add(player.getUniqueId());
|
npc.getAutoHidden().add(player.getUniqueId());
|
||||||
|
npc.hide(player, true, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Arrays;
|
||||||
public class NPCLibPlugin extends JavaPlugin implements Listener {
|
public class NPCLibPlugin extends JavaPlugin implements Listener {
|
||||||
|
|
||||||
private NPCLib npcLib;
|
private NPCLib npcLib;
|
||||||
|
private NPC npc;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
@ -48,17 +49,25 @@ public class NPCLibPlugin extends JavaPlugin implements Listener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MineSkinFetcher.fetchSkinFromIdAsync(168841, skin -> {
|
if (npc != null) {
|
||||||
NPC npc = npcLib.createNPC(skin, Arrays.asList(
|
if (npc.isActuallyShown(event.getPlayer())) {
|
||||||
ChatColor.BOLD + "NPC Library", "",
|
npc.hide(event.getPlayer());
|
||||||
"Create your own", "non-player characters",
|
} else {
|
||||||
"with the simplistic", "API of NPCLib!"
|
npc.show(event.getPlayer());
|
||||||
));
|
|
||||||
npc.create(event.getPlayer().getLocation());
|
|
||||||
|
|
||||||
for (Player player : getServer().getOnlinePlayers()) {
|
|
||||||
npc.show(player);
|
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
|
MineSkinFetcher.fetchSkinFromIdAsync(168841, skin -> {
|
||||||
|
npc = npcLib.createNPC(skin, Arrays.asList(
|
||||||
|
ChatColor.BOLD + "NPC Library", "",
|
||||||
|
"Create your own", "non-player characters",
|
||||||
|
"with the simplistic", "API of NPCLib!"
|
||||||
|
));
|
||||||
|
npc.create(event.getPlayer().getLocation());
|
||||||
|
|
||||||
|
for (Player player : getServer().getOnlinePlayers()) {
|
||||||
|
npc.show(player);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue