From 388b0fc0f294f1b7c47853e34cedf2b9a1b4e49d Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 1 May 2022 15:19:51 -0500 Subject: ClientboundUpdateAttributesPacket & ClientboundEntityVelocityPacket --- .../game/clientbound_update_attributes_packet.rs | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs (limited to 'azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs') 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(()) + } +} -- cgit v1.2.3