aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/player.rs
blob: 6c093517becd8c14d341379d9365d554f4b39a04 (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
use azalea_entity::Entity;
use azalea_world::Dimension;
use uuid::Uuid;

/// Something that has a dimension associated to it. Usually, this is a `Client`.
pub trait DimensionHaver {
    fn dimension(&self) -> &Dimension;
}

#[derive(Default, Debug)]
pub struct Player {
    /// The player's uuid.
    pub uuid: Uuid,
    /// The player's entity id.
    pub entity_id: u32,
}

impl Player {
    /// Get the entity of the player in the world.
    pub fn entity<'a>(&self, world: &'a Dimension) -> Option<&'a Entity> {
        // world.entity_by_uuid(&self.uuid)
        world.entity_by_id(self.entity_id)
    }

    pub fn set_uuid(&mut self, uuid: Uuid) {
        self.uuid = uuid;
    }

    pub fn set_entity_id(&mut self, entity_id: u32) {
        self.entity_id = entity_id;
    }
}