mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
* Start getting rid of Cursor * try to make the tests pass and fail * make the tests pass * remove unused uses * fix clippy warnings * fix potential OOM exploits * fix OOM in az-nbt * fix nbt benchmark * fix a test * start replacing it with Cursor<Vec<u8>> * wip * fix all the issues * fix all tests * fix nbt benchmark * fix warnings
51 lines
1.3 KiB
Rust
Executable file
51 lines
1.3 KiB
Rust
Executable file
use azalea_buf::{BufReadError, McBuf};
|
|
use azalea_buf::{McBufReadable, McBufWritable};
|
|
use azalea_protocol_macros::ClientboundGamePacket;
|
|
use std::io::{Cursor, Write};
|
|
|
|
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
|
|
pub struct ClientboundPlayerAbilitiesPacket {
|
|
pub flags: PlayerAbilitiesFlags,
|
|
pub flying_speed: f32,
|
|
/// Used for the fov
|
|
pub walking_speed: f32,
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct PlayerAbilitiesFlags {
|
|
pub invulnerable: bool,
|
|
pub flying: bool,
|
|
pub can_fly: bool,
|
|
pub instant_break: bool,
|
|
}
|
|
|
|
impl McBufReadable for PlayerAbilitiesFlags {
|
|
fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
|
|
let byte = u8::read_from(buf)?;
|
|
Ok(PlayerAbilitiesFlags {
|
|
invulnerable: byte & 1 != 0,
|
|
flying: byte & 2 != 0,
|
|
can_fly: byte & 4 != 0,
|
|
instant_break: byte & 8 != 0,
|
|
})
|
|
}
|
|
}
|
|
|
|
impl McBufWritable for PlayerAbilitiesFlags {
|
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
|
let mut byte = 0;
|
|
if self.invulnerable {
|
|
byte |= 0b1;
|
|
}
|
|
if self.flying {
|
|
byte |= 0b10;
|
|
}
|
|
if self.can_fly {
|
|
byte |= 0b100;
|
|
}
|
|
if self.instant_break {
|
|
byte |= 0b1000;
|
|
}
|
|
u8::write_into(&byte, buf)
|
|
}
|
|
}
|