1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00

add player abilities packet

This commit is contained in:
mat 2022-04-20 16:28:31 +00:00
parent c5f10af09d
commit 8bd97c6c96
5 changed files with 48 additions and 0 deletions

View file

@ -76,6 +76,10 @@ pub async fn join_server(address: &ServerAddress) -> Result<(), String> {
GamePacket::ClientboundDeclareCommandsPacket(p) => {
println!("Got declare commands packet {:?}", p);
}
GamePacket::ClientboundPlayerAbilitiesPacket(p) => {
println!("Got player abilities packet {:?}", p);
}
},
Err(e) => {
println!("Error: {:?}", e);

View file

@ -24,6 +24,7 @@ pub trait Readable {
async fn read_long(&mut self) -> Result<i64, String>;
async fn read_resource_location(&mut self) -> Result<ResourceLocation, String>;
async fn read_short(&mut self) -> Result<i16, String>;
async fn read_float(&mut self) -> Result<f32, String>;
}
#[async_trait]
@ -189,6 +190,13 @@ where
Err(_) => Err("Error reading short".to_string()),
}
}
async fn read_float(&mut self) -> Result<f32, String> {
match AsyncReadExt::read_f32(self).await {
Ok(r) => Ok(r),
Err(_) => Err("Error reading float".to_string()),
}
}
}
#[async_trait]
@ -362,6 +370,17 @@ impl McBufReadable for i8 {
}
}
// f32
#[async_trait]
impl McBufReadable for f32 {
async fn read_into<R>(buf: &mut R) -> Result<Self, String>
where
R: AsyncRead + std::marker::Unpin + std::marker::Send,
{
buf.read_float().await
}
}
// GameType
#[async_trait]
impl McBufReadable for GameType {

View file

@ -41,6 +41,7 @@ pub trait Writable {
&mut self,
location: &ResourceLocation,
) -> Result<(), std::io::Error>;
fn write_float(&mut self, n: f32) -> Result<(), std::io::Error>;
}
#[async_trait]
@ -147,6 +148,10 @@ impl Writable for Vec<u8> {
WriteBytesExt::write_i64::<BigEndian>(self, n)
}
fn write_float(&mut self, n: f32) -> Result<(), std::io::Error> {
WriteBytesExt::write_f32::<BigEndian>(self, n)
}
fn write_resource_location(
&mut self,
location: &ResourceLocation,
@ -264,6 +269,13 @@ impl McBufWritable for i8 {
}
}
// i8
impl McBufWritable for f32 {
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
buf.write_float(*self)
}
}
// GameType
impl McBufWritable for GameType {
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {

View file

@ -0,0 +1,11 @@
// i don't know the actual name of this packet, i couldn't find it in the source code
use packet_macros::GamePacket;
#[derive(Clone, Debug, GamePacket)]
pub struct ClientboundPlayerAbilitiesPacket {
pub flags: u8,
pub flying_speed: f32,
/// Used for the fov
pub walking_speed: f32,
}

View file

@ -2,6 +2,7 @@ pub mod clientbound_change_difficulty_packet;
pub mod clientbound_custom_payload_packet;
pub mod clientbound_declare_commands_packet;
pub mod clientbound_login_packet;
pub mod clientbound_player_abilities_packet;
pub mod clientbound_update_view_distance_packet;
use packet_macros::declare_state_packets;
@ -14,6 +15,7 @@ declare_state_packets!(
0x12: clientbound_declare_commands_packet::ClientboundDeclareCommandsPacket,
0x18: clientbound_custom_payload_packet::ClientboundCustomPayloadPacket,
0x26: clientbound_login_packet::ClientboundLoginPacket,
0x32: clientbound_player_abilities_packet::ClientboundPlayerAbilitiesPacket,
0x4a: clientbound_update_view_distance_packet::ClientboundUpdateViewDistancePacket
}
);