mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
ClientboundUpdateAttributesPacket & ClientboundEntityVelocityPacket
This commit is contained in:
parent
1a68d55eaf
commit
388b0fc0f2
4 changed files with 84 additions and 0 deletions
|
@ -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!();
|
||||
|
|
|
@ -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,
|
||||
}
|
|
@ -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(())
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue