aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/packets/game/c_move_entity_pos_rot.rs
blob: dffa16c7d6211ebcde2961451f12f8cab2c3e39a (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
use azalea_buf::AzBuf;
use azalea_core::{delta::PositionDelta8, entity_id::MinecraftEntityId};
use azalea_entity::LookDirection;
use azalea_protocol_macros::ClientboundGamePacket;

/// This packet is sent by the server when an entity moves less then 8 blocks.
#[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)]
pub struct ClientboundMoveEntityPosRot {
    #[var]
    pub entity_id: MinecraftEntityId,
    pub delta: PositionDelta8,
    pub look_direction: CompactLookDirection,
    pub on_ground: bool,
}

#[derive(AzBuf, Clone, Copy, Debug, PartialEq, Default)]
pub struct CompactLookDirection {
    pub y_rot: i8,
    pub x_rot: i8,
}

impl From<CompactLookDirection> for LookDirection {
    fn from(l: CompactLookDirection) -> Self {
        LookDirection::new(
            (l.y_rot as i32 * 360) as f32 / 256.,
            (l.x_rot as i32 * 360) as f32 / 256.,
        )
    }
}