aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/packets/game
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-05-01 15:19:51 -0500
committermat <github@matdoes.dev>2022-05-01 15:19:51 -0500
commit388b0fc0f294f1b7c47853e34cedf2b9a1b4e49d (patch)
tree7463acc478252e7f96931132a9a823ae365df606 /azalea-protocol/src/packets/game
parent1a68d55eaf8cb2a108bf850776ee81c74ebaaf5a (diff)
downloadazalea-drasl-388b0fc0f294f1b7c47853e34cedf2b9a1b4e49d.tar.xz
ClientboundUpdateAttributesPacket & ClientboundEntityVelocityPacket
Diffstat (limited to 'azalea-protocol/src/packets/game')
-rw-r--r--azalea-protocol/src/packets/game/clientbound_entity_velocity_packet.rs16
-rw-r--r--azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs57
-rwxr-xr-xazalea-protocol/src/packets/game/mod.rs4
3 files changed, 77 insertions, 0 deletions
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<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(())
+ }
+}
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
}