File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11use crate :: net:: packets:: { ConnectionId , IncomingPacket } ;
2+ use crate :: net:: systems:: chunk_sender:: { ChunkSender , CHUNK_RADIUS } ;
23use crate :: state:: GlobalState ;
34use crate :: utils:: components:: rotation:: Rotation ;
45use crate :: utils:: encoding:: position:: Position ;
@@ -26,6 +27,20 @@ impl IncomingPacket for SetPlayerPosAndRotate {
2627 let mut position = component_storage. get_mut :: < Position > ( my_entity_id) . await ?;
2728 let mut rotation = component_storage. get_mut :: < Rotation > ( my_entity_id) . await ?;
2829
30+ let old_chunk_pos = ( position. x >> 4 , position. z >> 4 ) ;
31+ let new_chunk_pos = ( self . x as i32 >> 4 , self . z as i32 >> 4 ) ;
32+
33+ if old_chunk_pos != new_chunk_pos {
34+ let state_clone = state. clone ( ) ;
35+ tokio:: spawn (
36+ async move {
37+ ChunkSender :: send_chunks_to_player ( state_clone, my_entity_id) . await ?;
38+
39+ Ok :: < ( ) , Error > ( ( ) )
40+ }
41+ ) ;
42+ }
43+
2944 * position = Position {
3045 x : self . x as i32 ,
3146 y : self . y as i16 ,
Original file line number Diff line number Diff line change 1- use tracing:: trace;
1+ use tracing:: { debug , trace} ;
22
33use ferrumc_macros:: { packet, NetDecode } ;
44
55use crate :: net:: packets:: { ConnectionId , IncomingPacket } ;
6+ use crate :: net:: systems:: chunk_sender:: { ChunkSender , CHUNK_RADIUS } ;
67use crate :: state:: GlobalState ;
78use crate :: utils:: encoding:: position:: Position ;
89
@@ -33,6 +34,20 @@ impl IncomingPacket for SetPlayerPosition {
3334
3435 let mut position = component_storage. get_mut :: < Position > ( my_entity_id) . await ?;
3536
37+ let old_chunk_pos = ( position. x >> 4 , position. z >> 4 ) ;
38+ let new_chunk_pos = ( self . x as i32 >> 4 , self . z as i32 >> 4 ) ;
39+
40+ if old_chunk_pos != new_chunk_pos {
41+ let state_clone = state. clone ( ) ;
42+ tokio:: spawn (
43+ async move {
44+ ChunkSender :: send_chunks_to_player ( state_clone, my_entity_id) . await ?;
45+
46+ Ok :: < ( ) , Error > ( ( ) )
47+ }
48+ ) ;
49+ }
50+
3651 * position = Position {
3752 x : self . x as i32 ,
3853 y : self . y as i16 ,
Original file line number Diff line number Diff line change @@ -14,8 +14,8 @@ use crate::utils::encoding::position::Position;
1414use crate :: utils:: prelude:: * ;
1515use ferrumc_macros:: AutoGenName ;
1616
17- const CHUNK_RADIUS : i32 = 16 ;
18- const CHUNK_TX_INTERVAL_MS : u64 = 150 ;
17+ pub const CHUNK_RADIUS : i32 = 8 ;
18+ const CHUNK_TX_INTERVAL_MS : u64 = 50000 ;
1919
2020#[ derive( AutoGenName ) ]
2121pub struct ChunkSender ;
You can’t perform that action at this time.
0 commit comments