From 388b0fc0f294f1b7c47853e34cedf2b9a1b4e49d Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 1 May 2022 15:19:51 -0500 Subject: [PATCH] ClientboundUpdateAttributesPacket & ClientboundEntityVelocityPacket --- azalea-client/src/connect.rs | 7 +++ .../clientbound_entity_velocity_packet.rs | 16 ++++++ .../clientbound_update_attributes_packet.rs | 57 +++++++++++++++++++ azalea-protocol/src/packets/game/mod.rs | 4 ++ 4 files changed, 84 insertions(+) create mode 100644 azalea-protocol/src/packets/game/clientbound_entity_velocity_packet.rs create mode 100644 azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs diff --git a/azalea-client/src/connect.rs b/azalea-client/src/connect.rs index ec3e122f..d28f2067 100755 --- a/azalea-client/src/connect.rs +++ b/azalea-client/src/connect.rs @@ -43,6 +43,7 @@ pub enum Event { Login, } +/// Whether we should ignore errors when decoding packets. const IGNORE_ERRORS: bool = false; impl Client { @@ -245,6 +246,12 @@ impl Client { GamePacket::ClientboundSetEntityDataPacket(p) => { println!("Got set entity data packet {:?}", p); } + GamePacket::ClientboundUpdateAttributesPacket(p) => { + println!("Got update attributes packet {:?}", p); + } + GamePacket::ClientboundEntityVelocityPacket(p) => { + println!("Got entity velocity packet {:?}", p); + } _ => panic!("Unexpected packet {:?}", packet), } println!(); diff --git a/azalea-protocol/src/packets/game/clientbound_entity_velocity_packet.rs b/azalea-protocol/src/packets/game/clientbound_entity_velocity_packet.rs new file mode 100644 index 00000000..83b21425 --- /dev/null +++ b/azalea-protocol/src/packets/game/clientbound_entity_velocity_packet.rs @@ -0,0 +1,16 @@ +use async_trait::async_trait; +use azalea_chat::component::Component; +use azalea_core::{resource_location::ResourceLocation, Slot}; +use packet_macros::{GamePacket, McBufReadable, McBufWritable}; +use tokio::io::AsyncRead; + +use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable}; + +#[derive(Clone, Debug, GamePacket)] +pub struct ClientboundEntityVelocityPacket { + #[varint] + pub entity_id: u32, + pub x_vel: i16, + pub y_vel: i16, + pub z_vel: i16, +} diff --git a/azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs new file mode 100644 index 00000000..d7f86931 --- /dev/null +++ b/azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs @@ -0,0 +1,57 @@ +use async_trait::async_trait; +use azalea_core::{game_type::GameType, resource_location::ResourceLocation}; +use packet_macros::{GamePacket, McBufReadable, McBufWritable}; +use tokio::io::AsyncRead; +use uuid::Uuid; + +use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable}; + +#[derive(Clone, Debug, GamePacket)] +pub struct ClientboundUpdateAttributesPacket { + #[varint] + pub entity_id: u32, + pub attributes: Vec, +} + +#[derive(Clone, Debug, McBufReadable, McBufWritable)] +pub struct AttributeSnapshot { + pub attribute: ResourceLocation, + pub base: f64, + pub modifiers: Vec, +} + +#[derive(Clone, Debug, McBufReadable, McBufWritable)] +pub struct Modifier { + pub uuid: Uuid, + pub amount: f64, + pub operation: u8, +} + +#[derive(Clone, Debug, Copy)] +enum Operation { + Addition = 0, + MultiplyBase = 1, + MultiplyTotal = 2, +} + +#[async_trait] +impl McBufReadable for Operation { + async fn read_into(buf: &mut R) -> Result + where + R: AsyncRead + std::marker::Unpin + std::marker::Send, + { + match buf.read_byte().await? { + 0 => Ok(Operation::Addition), + 1 => Ok(Operation::MultiplyBase), + 2 => Ok(Operation::MultiplyTotal), + op => Err(format!("Unknown operation: {}", op)), + } + } +} + +impl McBufWritable for Operation { + fn write_into(&self, buf: &mut Vec) -> Result<(), std::io::Error> { + buf.write_byte(*self as u8)?; + Ok(()) + } +} diff --git a/azalea-protocol/src/packets/game/mod.rs b/azalea-protocol/src/packets/game/mod.rs index e27255ac..22b65bff 100755 --- a/azalea-protocol/src/packets/game/mod.rs +++ b/azalea-protocol/src/packets/game/mod.rs @@ -5,6 +5,7 @@ pub mod clientbound_custom_payload_packet; pub mod clientbound_declare_commands_packet; pub mod clientbound_disconnect_packet; pub mod clientbound_entity_event_packet; +pub mod clientbound_entity_velocity_packet; pub mod clientbound_level_chunk_with_light_packet; pub mod clientbound_light_update_packet; pub mod clientbound_login_packet; @@ -15,6 +16,7 @@ pub mod clientbound_recipe_packet; pub mod clientbound_set_carried_item_packet; pub mod clientbound_set_chunk_cache_center; pub mod clientbound_set_entity_data_packet; +pub mod clientbound_update_attributes_packet; pub mod clientbound_update_recipes_packet; pub mod clientbound_update_tags_packet; pub mod clientbound_update_view_distance_packet; @@ -46,6 +48,8 @@ declare_state_packets!( 0x49: clientbound_set_chunk_cache_center::ClientboundSetChunkCacheCenterPacket, 0x4a: clientbound_update_view_distance_packet::ClientboundUpdateViewDistancePacket, 0x4d: clientbound_set_entity_data_packet::ClientboundSetEntityDataPacket, + 0x4f: clientbound_entity_velocity_packet::ClientboundEntityVelocityPacket, + 0x64: clientbound_update_attributes_packet::ClientboundUpdateAttributesPacket, 0x66: clientbound_update_recipes_packet::ClientboundUpdateRecipesPacket, 0x67: clientbound_update_tags_packet::ClientboundUpdateTagsPacket }