diff options
| author | mat <github@matdoes.dev> | 2022-05-01 15:19:51 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-05-01 15:19:51 -0500 |
| commit | 388b0fc0f294f1b7c47853e34cedf2b9a1b4e49d (patch) | |
| tree | 7463acc478252e7f96931132a9a823ae365df606 /azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs | |
| parent | 1a68d55eaf8cb2a108bf850776ee81c74ebaaf5a (diff) | |
| download | azalea-drasl-388b0fc0f294f1b7c47853e34cedf2b9a1b4e49d.tar.xz | |
ClientboundUpdateAttributesPacket & ClientboundEntityVelocityPacket
Diffstat (limited to 'azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs')
| -rw-r--r-- | azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs | 57 |
1 files changed, 57 insertions, 0 deletions
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<AttributeSnapshot>, +} + +#[derive(Clone, Debug, McBufReadable, McBufWritable)] +pub struct AttributeSnapshot { + pub attribute: ResourceLocation, + pub base: f64, + pub modifiers: Vec<Modifier>, +} + +#[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<R>(buf: &mut R) -> Result<Self, String> + 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<u8>) -> Result<(), std::io::Error> { + buf.write_byte(*self as u8)?; + Ok(()) + } +} |
