forked from valence-rs/valence
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer_list.rs
66 lines (53 loc) · 1.97 KB
/
player_list.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use crate::layer::chunk::UnloadedChunk;
use crate::protocol::packets::play::{PlayerListS2c, PlayerSpawnS2c};
use crate::testing::{create_mock_client, ScenarioSingleClient};
use crate::ChunkLayer;
#[test]
fn player_list_arrives_before_player_spawn() {
let ScenarioSingleClient {
mut app,
client: _,
helper: mut client_helper_1,
layer: layer_ent,
} = ScenarioSingleClient::new();
let mut layer = app.world.get_mut::<ChunkLayer>(layer_ent).unwrap();
for z in -5..5 {
for x in -5..5 {
layer.insert_chunk([x, z], UnloadedChunk::new());
}
}
app.update();
{
let recvd = client_helper_1.collect_received();
recvd.assert_count::<PlayerListS2c>(1);
recvd.assert_count::<PlayerSpawnS2c>(0);
recvd.assert_order::<(PlayerListS2c, PlayerSpawnS2c)>();
let pkt = recvd.first::<PlayerListS2c>();
assert!(pkt.actions.add_player());
assert_eq!(pkt.entries.len(), 1);
}
let (mut client_2, mut client_helper_2) = create_mock_client("test_2");
client_2.player.layer.0 = layer_ent;
client_2.visible_chunk_layer.0 = layer_ent;
client_2.visible_entity_layers.0.insert(layer_ent);
app.world.spawn(client_2);
app.update();
{
let recvd = client_helper_1.collect_received();
recvd.assert_count::<PlayerListS2c>(1);
recvd.assert_count::<PlayerSpawnS2c>(1);
recvd.assert_order::<(PlayerListS2c, PlayerSpawnS2c)>();
let pkt = recvd.first::<PlayerListS2c>();
assert!(pkt.actions.add_player());
assert_eq!(pkt.entries.len(), 1);
}
{
let recvd = client_helper_2.collect_received();
recvd.assert_count::<PlayerListS2c>(1);
recvd.assert_count::<PlayerSpawnS2c>(1);
recvd.assert_order::<(PlayerListS2c, PlayerSpawnS2c)>();
let pkt = recvd.first::<PlayerListS2c>();
assert!(pkt.actions.add_player());
assert_eq!(pkt.entries.len(), 2);
}
}