@@ -18,22 +18,26 @@ use common::{
18
18
Window ,
19
19
} ;
20
20
use packets:: server:: { Particle , SetSlot , SpawnLivingEntity , UpdateLight , WindowConfirmation } ;
21
- use protocol:: packets:: server:: { HeldItemChange , PlayerAbilities } ;
21
+ use protocol:: packets:: server:: {
22
+ EntityPosition , EntityPositionAndRotation , HeldItemChange , PlayerAbilities ,
23
+ } ;
22
24
use protocol:: {
23
25
packets:: {
24
26
self ,
25
27
server:: {
26
28
AddPlayer , Animation , BlockChange , ChatPosition , ChunkData , ChunkDataKind ,
27
- DestroyEntities , Disconnect , EntityAnimation , EntityHeadLook , EntityTeleport , JoinGame ,
28
- KeepAlive , PlayerInfo , PlayerPositionAndLook , PluginMessage , SendEntityMetadata ,
29
- SpawnPlayer , Title , UnloadChunk , UpdateViewPosition , WindowItems ,
29
+ DestroyEntities , Disconnect , EntityAnimation , EntityHeadLook , JoinGame , KeepAlive ,
30
+ PlayerInfo , PlayerPositionAndLook , PluginMessage , SendEntityMetadata , SpawnPlayer ,
31
+ Title , UnloadChunk , UpdateViewPosition , WindowItems ,
30
32
} ,
31
33
} ,
32
34
ClientPlayPacket , Nbt , ProtocolVersion , ServerPlayPacket , Writeable ,
33
35
} ;
34
36
use quill_common:: components:: { OnGround , PreviousGamemode } ;
35
37
36
- use crate :: { initial_handler:: NewPlayer , network_id_registry:: NetworkId , Options } ;
38
+ use crate :: {
39
+ entities:: PreviousPosition , initial_handler:: NewPlayer , network_id_registry:: NetworkId , Options ,
40
+ } ;
37
41
use slab:: Slab ;
38
42
39
43
/// Max number of chunks to send to a client per tick.
@@ -379,6 +383,7 @@ impl Client {
379
383
& self ,
380
384
network_id : NetworkId ,
381
385
position : Position ,
386
+ prev_position : PreviousPosition ,
382
387
on_ground : OnGround ,
383
388
) {
384
389
if self . network_id == Some ( network_id) {
@@ -390,23 +395,35 @@ impl Client {
390
395
}
391
396
return ;
392
397
}
393
- // Consider using the relative movement packets in the future.
394
- // (Entity Teleport works fine, but the relative movement packets
395
- // save bandwidth.)
396
- self . send_packet ( EntityTeleport {
397
- entity_id : network_id. 0 ,
398
- x : position. x ,
399
- y : position. y ,
400
- z : position. z ,
401
- yaw : position. yaw ,
402
- pitch : position. pitch ,
403
- on_ground : on_ground. 0 ,
404
- } ) ;
405
- // Needed for head orientation
406
- self . send_packet ( EntityHeadLook {
407
- entity_id : network_id. 0 ,
408
- head_yaw : position. yaw ,
409
- } ) ;
398
+
399
+ let no_change_yaw = ( position. yaw - prev_position. 0 . yaw ) . abs ( ) < 0.001 ;
400
+ let no_change_pitch = ( position. pitch - prev_position. 0 . pitch ) . abs ( ) < 0.001 ;
401
+
402
+ if no_change_yaw && no_change_pitch {
403
+ self . send_packet ( EntityPosition {
404
+ entity_id : network_id. 0 ,
405
+ delta_x : ( ( position. x * 32.0 - prev_position. 0 . x * 32.0 ) * 128.0 ) as i16 ,
406
+ delta_y : ( ( position. y * 32.0 - prev_position. 0 . y * 32.0 ) * 128.0 ) as i16 ,
407
+ delta_z : ( ( position. z * 32.0 - prev_position. 0 . z * 32.0 ) * 128.0 ) as i16 ,
408
+ on_ground : on_ground. 0 ,
409
+ } ) ;
410
+ } else {
411
+ self . send_packet ( EntityPositionAndRotation {
412
+ entity_id : network_id. 0 ,
413
+ delta_x : ( ( position. x * 32.0 - prev_position. 0 . x * 32.0 ) * 128.0 ) as i16 ,
414
+ delta_y : ( ( position. y * 32.0 - prev_position. 0 . y * 32.0 ) * 128.0 ) as i16 ,
415
+ delta_z : ( ( position. z * 32.0 - prev_position. 0 . z * 32.0 ) * 128.0 ) as i16 ,
416
+ yaw : position. yaw ,
417
+ pitch : position. pitch ,
418
+ on_ground : on_ground. 0 ,
419
+ } ) ;
420
+
421
+ // Needed for head orientation
422
+ self . send_packet ( EntityHeadLook {
423
+ entity_id : network_id. 0 ,
424
+ head_yaw : position. yaw ,
425
+ } ) ;
426
+ }
410
427
}
411
428
412
429
pub fn send_keepalive ( & self ) {
0 commit comments