diff --git a/main/src/main/java/net/citizensnpcs/ProtocolLibListener.java b/main/src/main/java/net/citizensnpcs/ProtocolLibListener.java index de85f97ce..d5d7dfe2c 100644 --- a/main/src/main/java/net/citizensnpcs/ProtocolLibListener.java +++ b/main/src/main/java/net/citizensnpcs/ProtocolLibListener.java @@ -108,7 +108,6 @@ public class ProtocolLibListener { PacketRotationSession session = trait.getPacketSession(event.getPlayer()); if (session == null || !session.isActive()) return; - PacketContainer packet = event.getPacket(); PacketType type = event.getPacketType(); if (type == Server.ENTITY_HEAD_ROTATION) { @@ -127,6 +126,8 @@ public class ProtocolLibListener { packet.getFloat().write(0, session.getBodyYaw()); packet.getFloat().write(1, session.getPitch()); } + + session.onPacketOverwritten(); } }); } diff --git a/main/src/main/java/net/citizensnpcs/trait/LookClose.java b/main/src/main/java/net/citizensnpcs/trait/LookClose.java index 5c7376e42..d1ac46dd4 100644 --- a/main/src/main/java/net/citizensnpcs/trait/LookClose.java +++ b/main/src/main/java/net/citizensnpcs/trait/LookClose.java @@ -106,6 +106,7 @@ public class LookClose extends Trait implements Toggleable { for (UUID uuid : Sets.newHashSet(Sets.difference(sessions.keySet(), seen))) { sessions.remove(uuid).end(); } + return; } else if (sessions.size() > 0) { for (PacketRotationSession session : sessions.values()) { session.end(); diff --git a/main/src/main/java/net/citizensnpcs/trait/RotationTrait.java b/main/src/main/java/net/citizensnpcs/trait/RotationTrait.java index 05ca9750d..57301cd8c 100644 --- a/main/src/main/java/net/citizensnpcs/trait/RotationTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/RotationTrait.java @@ -145,7 +145,7 @@ public class RotationTrait extends Trait { public static class PacketRotationSession { private boolean ended; private final RotationSession session; - private RotationTriple triple; + private PacketRotationTriple triple; public PacketRotationSession(RotationSession session) { this.session = session; @@ -180,6 +180,12 @@ public class RotationTrait extends Trait { return !ended && session.isActive(); } + public void onPacketOverwritten() { + if (triple == null) + return; + triple.record(); + } + public void run(Entity entity) { if (triple == null) { triple = new PacketRotationTriple(entity); @@ -192,13 +198,25 @@ public class RotationTrait extends Trait { } private static class PacketRotationTriple extends EntityRotation { + private float lastBodyYaw; + private float lastHeadYaw; + private float lastPitch; + public PacketRotationTriple(Entity entity) { super(entity); } @Override public void apply() { - // NMS.sendRotationNearby(entity, bodyYaw, headYaw, pitch); + if (Math.abs(lastBodyYaw - bodyYaw) + Math.abs(lastHeadYaw - headYaw) + Math.abs(pitch - lastPitch) > 1) { + NMS.sendRotationNearby(entity, bodyYaw, headYaw, pitch); + } + } + + public void record() { + lastBodyYaw = bodyYaw; + lastHeadYaw = headYaw; + lastPitch = pitch; } }