aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/packets/game/clientbound_add_player_packet.rs
blob: 4cbeb1b92d08284d1882f0e6777e62f436a840a1 (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
use azalea_buf::McBuf;
use azalea_core::{ResourceLocation, Vec3};
use azalea_protocol_macros::ClientboundGamePacket;
use azalea_registry::EntityKind;
use azalea_world::entity::{metadata::PlayerMetadataBundle, EntityBundle, PlayerBundle};
use uuid::Uuid;

/// This packet is sent by the server when a player comes into visible range,
/// not when a player joins.
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
pub struct ClientboundAddPlayerPacket {
    #[var]
    pub id: u32,
    pub uuid: Uuid,
    pub position: Vec3,
    pub x_rot: i8,
    pub y_rot: i8,
}

impl ClientboundAddPlayerPacket {
    pub fn as_player_bundle(&self, world_name: ResourceLocation) -> PlayerBundle {
        PlayerBundle {
            entity: EntityBundle::new(self.uuid, self.position, EntityKind::Player, world_name),
            metadata: PlayerMetadataBundle::default(),
        }
    }
}