File tree Expand file tree Collapse file tree 3 files changed +33
-3
lines changed Expand file tree Collapse file tree 3 files changed +33
-3
lines changed Original file line number Diff line number Diff line change 1
1
use crate :: net:: packets:: { ConnectionId , IncomingPacket } ;
2
+ use crate :: net:: systems:: chunk_sender:: { ChunkSender , CHUNK_RADIUS } ;
2
3
use crate :: state:: GlobalState ;
3
4
use crate :: utils:: components:: rotation:: Rotation ;
4
5
use crate :: utils:: encoding:: position:: Position ;
@@ -26,6 +27,20 @@ impl IncomingPacket for SetPlayerPosAndRotate {
26
27
let mut position = component_storage. get_mut :: < Position > ( my_entity_id) . await ?;
27
28
let mut rotation = component_storage. get_mut :: < Rotation > ( my_entity_id) . await ?;
28
29
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
+
29
44
* position = Position {
30
45
x : self . x as i32 ,
31
46
y : self . y as i16 ,
Original file line number Diff line number Diff line change 1
- use tracing:: trace;
1
+ use tracing:: { debug , trace} ;
2
2
3
3
use ferrumc_macros:: { packet, NetDecode } ;
4
4
5
5
use crate :: net:: packets:: { ConnectionId , IncomingPacket } ;
6
+ use crate :: net:: systems:: chunk_sender:: { ChunkSender , CHUNK_RADIUS } ;
6
7
use crate :: state:: GlobalState ;
7
8
use crate :: utils:: encoding:: position:: Position ;
8
9
@@ -33,6 +34,20 @@ impl IncomingPacket for SetPlayerPosition {
33
34
34
35
let mut position = component_storage. get_mut :: < Position > ( my_entity_id) . await ?;
35
36
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
+
36
51
* position = Position {
37
52
x : self . x as i32 ,
38
53
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;
14
14
use crate :: utils:: prelude:: * ;
15
15
use ferrumc_macros:: AutoGenName ;
16
16
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 ;
19
19
20
20
#[ derive( AutoGenName ) ]
21
21
pub struct ChunkSender ;
You can’t perform that action at this time.
0 commit comments