aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/tests/simulation/teleport_movement.rs
blob: 1b740b19799eccdc1cc2299adc69b4e53c1c212d (plain)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
use azalea_client::test_utils::prelude::*;
use azalea_core::{
    delta::{LpVec3, PositionDelta8},
    entity_id::MinecraftEntityId,
    position::{BlockPos, ChunkPos, Vec3},
};
use azalea_entity::LookDirection;
use azalea_protocol::{
    common::movements::{MoveFlags, PositionMoveRotation, RelativeMovements},
    packets::{
        ConnectionProtocol,
        game::{
            ClientboundBlockUpdate, ClientboundForgetLevelChunk, ClientboundPing,
            ClientboundPlayerPosition, ClientboundSetChunkCacheCenter, ClientboundSetEntityMotion,
            ServerboundGamePacket, ServerboundMovePlayerPos, ServerboundMovePlayerPosRot,
        },
    },
};
use azalea_registry::builtin::BlockKind;

#[test]
fn test_teleport_movement() {
    let _lock = init();

    let mut simulation = Simulation::new(ConnectionProtocol::Game);
    let sent_packets = SentPackets::new(&mut simulation);

    simulation.receive_packet(default_login_packet());
    simulation.tick();

    sent_packets.expect_tick_end();
    sent_packets.expect_empty();

    // receive a chunk so the player is "loaded" now
    simulation.receive_packet(ClientboundSetChunkCacheCenter { x: 1, z: 23 });
    simulation.receive_packet(make_basic_empty_chunk(
        ChunkPos::new(1, 23),
        (384 + 64) / 16,
    ));
    simulation.receive_packet(ClientboundBlockUpdate {
        pos: BlockPos::new(31, 63, 370),
        block_state: BlockKind::Stone.into(),
    });
    simulation.receive_packet(ClientboundPlayerPosition {
        id: 1,
        change: PositionMoveRotation {
            pos: Vec3::new(31.5, 64., 370.5),
            delta: Vec3::ZERO,
            look_direction: LookDirection::default(),
        },
        relative: RelativeMovements::all_absolute(),
    });
    simulation.tick();
    simulation.tick();
    sent_packets.clear();

    // now teleport to a far-away location
    tracing::info!("meow!");
    simulation.receive_packet(ClientboundPing { id: 1 });
    simulation.receive_packet(ClientboundPlayerPosition {
        id: 2,
        change: PositionMoveRotation {
            pos: Vec3::new(10000.5, 70.0, 0.5),
            delta: Vec3::ZERO,
            look_direction: LookDirection::default(),
        },
        relative: RelativeMovements::all_absolute(),
    });
    simulation.receive_packet(ClientboundPing { id: 2 });
    simulation.tick();
    sent_packets.expect_pong(1);
    sent_packets.expect("AcceptTeleportation", |p| {
        matches!(p, ServerboundGamePacket::AcceptTeleportation(_))
    });
    sent_packets.expect("MovePlayerPosRot", |p| {
        matches!(
            p,
            ServerboundGamePacket::MovePlayerPosRot(p)
            if p == &ServerboundMovePlayerPosRot {
                pos: Vec3::new(10000.5, 70.0, 0.5),
                flags: MoveFlags::default(),
                look_direction: LookDirection::default(),
            }
        )
    });
    sent_packets.expect_pong(2);
    sent_packets.expect("MovePlayerPos", |p| {
        matches!(
            p,
            ServerboundGamePacket::MovePlayerPos(p)
            if p == &ServerboundMovePlayerPos {
                pos: Vec3::new(10000.5, 70.0, 0.5),
                flags: MoveFlags::default()
            }
        )
    });

    sent_packets.expect_tick_end();
    sent_packets.expect_empty();

    //

    simulation.receive_packet(ClientboundForgetLevelChunk {
        pos: ChunkPos { x: 1, z: 23 },
    });
    simulation.receive_packet(ClientboundSetChunkCacheCenter { x: 625, z: 0 });
    simulation.receive_packet(ClientboundPing { id: 3 });
    simulation.receive_packet(ClientboundPlayerPosition {
        id: 3,
        change: PositionMoveRotation {
            pos: Vec3::new(10000.5, 70.0000001, 0.5),
            delta: Vec3::ZERO,
            look_direction: LookDirection::default(),
        },
        relative: RelativeMovements::all_absolute(),
    });
    simulation.receive_packet(ClientboundPing { id: 4 });
    simulation.receive_packet(ClientboundSetEntityMotion {
        id: MinecraftEntityId(0),
        delta: LpVec3::from(Vec3::from(PositionDelta8 {
            xa: 0,
            ya: -627,
            za: 0,
        })),
    });
    simulation.receive_packet(ClientboundPing { id: 5 });
    simulation.tick();

    sent_packets.expect_pong(3);
    sent_packets.expect("AcceptTeleportation", |p| {
        matches!(p, ServerboundGamePacket::AcceptTeleportation(_))
    });
    sent_packets.expect("MovePlayerPosRot", |p| {
        matches!(
        p,
        ServerboundGamePacket::MovePlayerPosRot(p)
        if p == &ServerboundMovePlayerPosRot {
            pos: Vec3::new(10000.5, 70.0000001, 0.5),
            flags: MoveFlags::default(),
            look_direction: LookDirection::default(),
        })
    });
    sent_packets.expect_pong(4);
    sent_packets.expect_pong(5);
    sent_packets.expect("MovePlayerPos", |p| {
        matches!(
            p,
            ServerboundGamePacket::MovePlayerPos(p)
            if p == &ServerboundMovePlayerPos {
                pos: Vec3::new(10000.5, 69.84691458452664, 0.5),
                flags: MoveFlags::default()
            }
        )
    });

    sent_packets.expect_tick_end();
    sent_packets.expect_empty();
}