aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/packets/game/serverbound_player_abilities_packet.rs
blob: 7ea43e88f1d4547ecfbf3f4c84d088dc39be0778 (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
use crate::packets::BufReadError;
use azalea_buf::{McBufReadable, McBufWritable};
use packet_macros::ServerboundGamePacket;

#[derive(Clone, Debug, ServerboundGamePacket)]
pub struct ServerboundPlayerAbilitiesPacket {
    is_flying: bool,
}

impl McBufReadable for ServerboundPlayerAbilitiesPacket {
    fn read_from(buf: &mut impl std::io::Read) -> Result<Self, BufReadError> {
        let byte = u8::read_from(buf)?;
        Ok(Self {
            is_flying: byte & 2 != 0,
        })
    }
}

impl McBufWritable for ServerboundPlayerAbilitiesPacket {
    fn write_into(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
        let mut byte = 0;
        if self.is_flying {
            byte |= 2;
        }
        byte.write_into(buf)?;
        Ok(())
    }
}