diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2022-06-20 06:22:16 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-20 06:22:16 +0000 |
| commit | a1484f66290517b6c36f2e82c92613f23d2c4935 (patch) | |
| tree | f0a590ef6deac0c23c932773354fc4f75903953a /azalea-protocol/src | |
| parent | e2553bbaf2a550f4941b924e703a922345a1389f (diff) | |
| parent | 405a00c0d1908a4b3fbd8e6684c77dfb178ac55d (diff) | |
| download | azalea-drasl-a1484f66290517b6c36f2e82c92613f23d2c4935.tar.xz | |
Merge branch 'main' into 1.19.1
Diffstat (limited to 'azalea-protocol/src')
6 files changed, 88 insertions, 8 deletions
diff --git a/azalea-protocol/src/packets/game/clientbound_add_entity_packet.rs b/azalea-protocol/src/packets/game/clientbound_add_entity_packet.rs index 8a8a713e..9ef7e05c 100644 --- a/azalea-protocol/src/packets/game/clientbound_add_entity_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_add_entity_packet.rs @@ -3,6 +3,7 @@ use uuid::Uuid; #[derive(Clone, Debug, McBuf, GamePacket)] pub struct ClientboundAddEntityPacket { + /// The id of the entity. #[var] pub id: u32, pub uuid: Uuid, diff --git a/azalea-protocol/src/packets/game/clientbound_entity_event_packet.rs b/azalea-protocol/src/packets/game/clientbound_entity_event_packet.rs index 1b06bff7..d0cc7222 100644 --- a/azalea-protocol/src/packets/game/clientbound_entity_event_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_entity_event_packet.rs @@ -3,6 +3,6 @@ use packet_macros::{GamePacket, McBuf}; // we can't identify the status in azalea-protocol since they vary depending on the entity #[derive(Clone, Debug, McBuf, GamePacket)] pub struct ClientboundEntityEventPacket { - pub entity_id: i32, - pub entity_status: i8, + pub entity_id: u32, + pub event_id: u8, } diff --git a/azalea-protocol/src/packets/game/clientbound_level_particles_packet.rs b/azalea-protocol/src/packets/game/clientbound_level_particles_packet.rs index a3538598..9ed08d8a 100644 --- a/azalea-protocol/src/packets/game/clientbound_level_particles_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_level_particles_packet.rs @@ -1,10 +1,11 @@ -use std::io::{Read, Write}; - +use crate::mc_buf::McBufVarReadable; use crate::mc_buf::{McBufReadable, McBufWritable, ParticleData}; use packet_macros::GamePacket; +use std::io::{Read, Write}; #[derive(Clone, Debug, GamePacket)] pub struct ClientboundLevelParticlesPacket { + #[var] pub particle_id: u32, pub override_limiter: bool, pub x: f64, @@ -14,13 +15,13 @@ pub struct ClientboundLevelParticlesPacket { pub y_dist: f32, pub z_dist: f32, pub max_speed: f32, - pub count: i32, + pub count: u32, pub data: ParticleData, } impl McBufReadable for ClientboundLevelParticlesPacket { fn read_into(buf: &mut impl Read) -> Result<Self, String> { - let particle_id = u32::read_into(buf)?; + let particle_id = u32::var_read_into(buf)?; let override_limiter = bool::read_into(buf)?; let x = f64::read_into(buf)?; let y = f64::read_into(buf)?; @@ -29,7 +30,7 @@ impl McBufReadable for ClientboundLevelParticlesPacket { let y_dist = f32::read_into(buf)?; let z_dist = f32::read_into(buf)?; let max_speed = f32::read_into(buf)?; - let count = i32::read_into(buf)?; + let count = u32::read_into(buf)?; let data = ParticleData::read_from_particle_id(buf, particle_id)?; diff --git a/azalea-protocol/src/packets/game/clientbound_set_equipment_packet.rs b/azalea-protocol/src/packets/game/clientbound_set_equipment_packet.rs new file mode 100644 index 00000000..3acbd58f --- /dev/null +++ b/azalea-protocol/src/packets/game/clientbound_set_equipment_packet.rs @@ -0,0 +1,74 @@ +use azalea_core::Slot; +use packet_macros::{GamePacket, McBuf}; + +use crate::mc_buf::{McBufReadable, McBufWritable}; + +#[derive(Clone, Debug, McBuf, GamePacket)] +pub struct ClientboundSetEquipmentPacket { + #[var] + pub entity: i32, + pub slots: EquipmentSlots, +} + +#[derive(Clone, Debug)] +pub struct EquipmentSlots { + pub slots: Vec<(EquipmentSlot, Slot)>, +} + +impl McBufReadable for EquipmentSlots { + fn read_into(buf: &mut impl std::io::Read) -> Result<Self, String> { + let mut slots = vec![]; + + loop { + let equipment_byte = u8::read_into(buf)?; + let equipment_slot = EquipmentSlot::from_byte(equipment_byte & 127) + .ok_or_else(|| format!("Invalid equipment slot byte {}", equipment_byte))?; + let item = Slot::read_into(buf)?; + slots.push((equipment_slot, item)); + if equipment_byte & 128 == 0 { + break; + }; + } + + Ok(EquipmentSlots { slots }) + } +} +impl McBufWritable for EquipmentSlots { + fn write_into(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> { + for i in 0..self.slots.len() { + let (equipment_slot, item) = &self.slots[i]; + let mut equipment_byte = *equipment_slot as u8; + if i != self.slots.len() - 1 { + equipment_byte |= 128; + } + equipment_byte.write_into(buf)?; + item.write_into(buf)?; + } + + Ok(()) + } +} + +#[derive(Clone, Debug, Copy, McBuf)] +pub enum EquipmentSlot { + MainHand = 0, + OffHand = 1, + Feet = 2, + Legs = 3, + Chest = 4, + Head = 5, +} + +impl EquipmentSlot { + pub fn from_byte(byte: u8) -> Option<Self> { + match byte { + 0 => Some(EquipmentSlot::MainHand), + 1 => Some(EquipmentSlot::OffHand), + 2 => Some(EquipmentSlot::Feet), + 3 => Some(EquipmentSlot::Legs), + 4 => Some(EquipmentSlot::Chest), + 5 => Some(EquipmentSlot::Head), + _ => None, + } + } +} diff --git a/azalea-protocol/src/packets/game/clientbound_sound_packet.rs b/azalea-protocol/src/packets/game/clientbound_sound_packet.rs index 797f03de..fbc5830b 100644 --- a/azalea-protocol/src/packets/game/clientbound_sound_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_sound_packet.rs @@ -3,7 +3,7 @@ use packet_macros::{GamePacket, McBuf}; #[derive(Clone, Debug, McBuf, GamePacket)] pub struct ClientboundSoundPacket { #[var] - /// TODO: use the sound registry instead of just being a u32 + // TODO: use the sound registry instead of just being a u32 pub sound: u32, pub source: SoundSource, pub x: i32, @@ -11,6 +11,8 @@ pub struct ClientboundSoundPacket { pub z: i32, pub volume: f32, pub pitch: f32, + /// Seed used to pick sound varient. + pub seed: u64, } #[derive(Clone, Debug, Copy, McBuf)] diff --git a/azalea-protocol/src/packets/game/mod.rs b/azalea-protocol/src/packets/game/mod.rs index eee36788..c4435636 100755 --- a/azalea-protocol/src/packets/game/mod.rs +++ b/azalea-protocol/src/packets/game/mod.rs @@ -37,6 +37,7 @@ pub mod clientbound_set_default_spawn_position_packet; pub mod clientbound_set_display_chat_preview_packet; pub mod clientbound_set_entity_data_packet; pub mod clientbound_set_entity_link_packet; +pub mod clientbound_set_equipment_packet; pub mod clientbound_set_experience_packet; pub mod clientbound_set_health_packet; pub mod clientbound_set_time_packet; @@ -104,6 +105,7 @@ declare_state_packets!( 0x4b: clientbound_set_display_chat_preview_packet::ClientboundSetDisplayChatPreviewPacket, 0x4d: clientbound_set_entity_data_packet::ClientboundSetEntityDataPacket, 0x4f: clientbound_entity_velocity_packet::ClientboundEntityVelocityPacket, + 0x50: clientbound_set_equipment_packet::ClientboundSetEquipmentPacket, 0x51: clientbound_set_experience_packet::ClientboundSetExperiencePacket, 0x52: clientbound_set_health_packet::ClientboundSetHealthPacket, 0x59: clientbound_set_time_packet::ClientboundSetTimePacket, |
