forked from valence-rs/valence
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.rs
103 lines (82 loc) · 2.49 KB
/
client.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use crate::abilities::PlayerAbilitiesFlags;
use crate::layer::chunk::UnloadedChunk;
use crate::layer::ChunkLayer;
use crate::math::DVec3;
use crate::protocol::packets::play::{
FullC2s, MoveRelativeS2c, PlayerPositionLookS2c, TeleportConfirmC2s,
};
use crate::testing::{create_mock_client, ScenarioSingleClient};
use crate::{ChunkPos, GameMode};
#[test]
fn client_teleport_and_move() {
let ScenarioSingleClient {
mut app,
client: _,
helper: mut helper_1,
layer: layer_ent,
} = ScenarioSingleClient::new();
let mut layer = app.world.get_mut::<ChunkLayer>(layer_ent).unwrap();
for z in -10..10 {
for x in -10..10 {
layer.insert_chunk(ChunkPos::new(x, z), UnloadedChunk::new());
}
}
let (mut bundle, mut helper_2) = create_mock_client("other");
bundle.player.layer.0 = layer_ent;
bundle.visible_chunk_layer.0 = layer_ent;
bundle.visible_entity_layers.0.insert(layer_ent);
app.world.spawn(bundle);
app.update();
// Client received an initial teleport.
helper_1
.collect_received()
.assert_count::<PlayerPositionLookS2c>(1);
// Confirm the initial teleport from the server.
helper_1.send(&TeleportConfirmC2s {
teleport_id: 0.into(),
});
// Move a little.
helper_1.send(&FullC2s {
position: DVec3::new(1.0, 0.0, 0.0),
yaw: 0.0,
pitch: 0.0,
on_ground: true,
});
app.update();
// Check that the other client saw the client moving.
helper_2
.collect_received()
.assert_count::<MoveRelativeS2c>(1);
}
#[test]
fn client_gamemode_changed_ability() {
let mut scenario = ScenarioSingleClient::new();
*scenario
.app
.world
.get_mut::<GameMode>(scenario.client)
.unwrap() = GameMode::Creative;
scenario.app.update();
let abilities = scenario
.app
.world
.get::<PlayerAbilitiesFlags>(scenario.client)
.unwrap();
assert!(abilities.allow_flying());
assert!(abilities.instant_break());
assert!(abilities.invulnerable());
*scenario
.app
.world
.get_mut::<GameMode>(scenario.client)
.unwrap() = GameMode::Adventure;
scenario.app.update();
let abilities = scenario
.app
.world
.get::<PlayerAbilitiesFlags>(scenario.client)
.unwrap();
assert!(!abilities.allow_flying());
assert!(!abilities.instant_break());
assert!(!abilities.invulnerable());
}