Don't send per-player rotation packets as often

This commit is contained in:
fullwall 2022-12-18 15:39:48 +08:00
parent 6ced30fa20
commit f9def3fe6a
3 changed files with 15 additions and 11 deletions

View File

@ -71,10 +71,6 @@ public class ProtocolLibListener {
}); });
} }
private static byte degToByte(float in) {
return (byte) (in * 256.0F / 360.0F);
}
private StructureModifier<Set<PlayerTeleportFlag>> getFlagsModifier(PacketContainer handle) { private StructureModifier<Set<PlayerTeleportFlag>> getFlagsModifier(PacketContainer handle) {
return handle.getSets(EnumWrappers.getGenericConverter(flagsClass, PlayerTeleportFlag.class)); return handle.getSets(EnumWrappers.getGenericConverter(flagsClass, PlayerTeleportFlag.class));
} }
@ -86,4 +82,8 @@ public class ProtocolLibListener {
ZPITCH, ZPITCH,
ZYAW, ZYAW,
} }
private static byte degToByte(float in) {
return (byte) (in * 256.0F / 360.0F);
}
} }

View File

@ -181,13 +181,20 @@ public class CitizensNavigator implements Navigator, Runnable {
if (!finished) { if (!finished) {
localParams.run(); 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 (localParams.lookAtFunction() != null) {
if (session == null) { if (session == null) {
RotationTrait trait = npc.getOrAddTrait(RotationTrait.class); 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)); session.getSession().rotateToFace(localParams.lookAtFunction().apply(this));
} }
if (localParams.destinationTeleportMargin() > 0 if (localParams.destinationTeleportMargin() > 0
&& npcLoc.distance(targetLoc) <= localParams.destinationTeleportMargin()) { && npcLoc.distance(targetLoc) <= localParams.destinationTeleportMargin()) {
// TODO: easing? // TODO: easing?

View File

@ -74,10 +74,10 @@ public class RotationTrait extends Trait {
public PacketRotationSession getPacketSession(Player player) { public PacketRotationSession getPacketSession(Player player) {
PacketRotationSession lrs = packetSessionsByUUID.get(player.getUniqueId()); PacketRotationSession lrs = packetSessionsByUUID.get(player.getUniqueId());
if (lrs != null) if (lrs != null && lrs.triple != null)
return lrs; return lrs;
for (PacketRotationSession session : packetSessions) { for (PacketRotationSession session : packetSessions) {
if (session.accepts(player)) { if (session.accepts(player) && session.triple != null) {
return session; return session;
} }
} }
@ -198,10 +198,7 @@ public class RotationTrait extends Trait {
@Override @Override
public void apply() { public void apply() {
Location loc = entity.getLocation(); // NMS.sendRotationNearby(entity, bodyYaw, headYaw, pitch);
loc.setPitch(pitch);
loc.setYaw(headYaw);
NMS.sendRotationNearby(entity, bodyYaw, headYaw, pitch);
} }
} }