aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/tests/simulation/move_despawned_entity.rs
blob: 30b326f628a23b1de2bebe457aa6f01df6563ea1 (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
use azalea_client::test_utils::prelude::*;
use azalea_core::{entity_id::MinecraftEntityId, position::ChunkPos};
use azalea_entity::metadata::Cow;
use azalea_protocol::packets::{
    ConnectionProtocol,
    game::{ClientboundMoveEntityRot, c_move_entity_pos_rot::CompactLookDirection},
};
use azalea_registry::builtin::EntityKind;
use bevy_ecs::query::With;
use tracing::Level;

#[test]
fn test_move_despawned_entity() {
    let _lock = init_with_level(Level::ERROR); // a warning is expected here

    let mut simulation = Simulation::new(ConnectionProtocol::Game);
    simulation.receive_packet(default_login_packet());

    simulation.receive_packet(make_basic_empty_chunk(ChunkPos::new(0, 0), (384 + 64) / 16));
    simulation.tick();
    // spawn a cow
    simulation.receive_packet(make_basic_add_entity(EntityKind::Cow, 123, (0.5, 64., 0.5)));
    simulation.tick();

    // make sure it's spawned
    let mut cow_query = simulation.app.world_mut().query_filtered::<(), With<Cow>>();
    let cow_iter = cow_query.iter(simulation.app.world());
    assert_eq!(cow_iter.count(), 1, "cow should be spawned");

    // despawn the cow by receiving a login packet
    simulation.receive_packet(default_login_packet());
    simulation.tick();

    // make sure it's despawned
    let mut cow_query = simulation.app.world_mut().query_filtered::<(), With<Cow>>();
    let cow_iter = cow_query.iter(simulation.app.world());
    assert_eq!(cow_iter.count(), 0, "cow should be despawned");

    // send a move_entity_rot
    simulation.receive_packet(ClientboundMoveEntityRot {
        entity_id: MinecraftEntityId(123),
        look_direction: CompactLookDirection::default(),
        on_ground: false,
    });
    simulation.tick();
}