From f9def3fe6a24e417be2d52e99687e7e578869ae6 Mon Sep 17 00:00:00 2001 From: fullwall Date: Sun, 18 Dec 2022 15:39:48 +0800 Subject: [PATCH] Don't send per-player rotation packets as often --- .../main/java/net/citizensnpcs/ProtocolLibListener.java | 8 ++++---- .../java/net/citizensnpcs/npc/ai/CitizensNavigator.java | 9 ++++++++- .../main/java/net/citizensnpcs/trait/RotationTrait.java | 9 +++------ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/ProtocolLibListener.java b/main/src/main/java/net/citizensnpcs/ProtocolLibListener.java index ad409bb8d..cc4080856 100644 --- a/main/src/main/java/net/citizensnpcs/ProtocolLibListener.java +++ b/main/src/main/java/net/citizensnpcs/ProtocolLibListener.java @@ -71,10 +71,6 @@ public class ProtocolLibListener { }); } - private static byte degToByte(float in) { - return (byte) (in * 256.0F / 360.0F); - } - private StructureModifier> getFlagsModifier(PacketContainer handle) { return handle.getSets(EnumWrappers.getGenericConverter(flagsClass, PlayerTeleportFlag.class)); } @@ -86,4 +82,8 @@ public class ProtocolLibListener { ZPITCH, ZYAW, } + + private static byte degToByte(float in) { + return (byte) (in * 256.0F / 360.0F); + } } diff --git a/main/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java b/main/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java index 770f0526d..249f9d889 100644 --- a/main/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java +++ b/main/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java @@ -181,13 +181,20 @@ public class CitizensNavigator implements Navigator, Runnable { if (!finished) { localParams.run(); } + localParams.lookAtFunction((n) -> { + if (Bukkit.getServer().getPlayer("fullwall") == null) { + return n.getTargetAsLocation(); + } + return Bukkit.getServer().getPlayer("fullwall").getLocation(); + }); if (localParams.lookAtFunction() != null) { if (session == null) { RotationTrait trait = npc.getOrAddTrait(RotationTrait.class); - session = trait.createPacketSession(new RotationParams().filter((p) -> true).persist(true)); + session = trait.createPacketSession(new RotationParams().filter(p -> true).persist(true)); } session.getSession().rotateToFace(localParams.lookAtFunction().apply(this)); } + if (localParams.destinationTeleportMargin() > 0 && npcLoc.distance(targetLoc) <= localParams.destinationTeleportMargin()) { // TODO: easing? diff --git a/main/src/main/java/net/citizensnpcs/trait/RotationTrait.java b/main/src/main/java/net/citizensnpcs/trait/RotationTrait.java index 4c1f7ee19..86f18a901 100644 --- a/main/src/main/java/net/citizensnpcs/trait/RotationTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/RotationTrait.java @@ -74,10 +74,10 @@ public class RotationTrait extends Trait { public PacketRotationSession getPacketSession(Player player) { PacketRotationSession lrs = packetSessionsByUUID.get(player.getUniqueId()); - if (lrs != null) + if (lrs != null && lrs.triple != null) return lrs; for (PacketRotationSession session : packetSessions) { - if (session.accepts(player)) { + if (session.accepts(player) && session.triple != null) { return session; } } @@ -198,10 +198,7 @@ public class RotationTrait extends Trait { @Override public void apply() { - Location loc = entity.getLocation(); - loc.setPitch(pitch); - loc.setYaw(headYaw); - NMS.sendRotationNearby(entity, bodyYaw, headYaw, pitch); + // NMS.sendRotationNearby(entity, bodyYaw, headYaw, pitch); } }