diff --git a/protocol/src/protocol/packet.rs b/protocol/src/protocol/packet.rs index 6c5e48d..8b05429 100644 --- a/protocol/src/protocol/packet.rs +++ b/protocol/src/protocol/packet.rs @@ -1738,6 +1738,10 @@ state_packets!( /// EntityEquipment is sent to display an item on an entity, like a sword /// or armor. Slot 0 is the held item and slots 1 to 4 are boots, leggings /// chestplate and helmet respectively. + packet EntityEquipment_Array { + field entity_id: VarInt =, + field equipments: packet::EntityEquipments =, + } packet EntityEquipment_VarInt { field entity_id: VarInt =, field slot: VarInt =, @@ -2505,6 +2509,57 @@ impl Serializable for CriterionProgress { } } +#[derive(Debug, Default)] +pub struct EntityEquipment { + pub slot: u8, + pub item: Option, +} + +impl Serializable for EntityEquipment { + fn read_from(buf: &mut R) -> Result { + Ok(EntityEquipment { + slot: Serializable::read_from(buf)?, + item: Serializable::read_from(buf)?, + }) + } + + fn write_to(&self, buf: &mut W) -> Result<(), Error> { + self.slot.write_to(buf)?; + self.item.write_to(buf) + } +} + +// Top-bit terminated array of EntityEquipment +#[derive(Debug, Default)] +pub struct EntityEquipments { + pub equipments: Vec, +} + +impl Serializable for EntityEquipments { + fn read_from(buf: &mut R) -> Result { + let mut equipments: Vec = vec![]; + + loop { + let e: EntityEquipment = Serializable::read_from(buf)?; + equipments.push(EntityEquipment { + slot: e.slot & 0x7f, + item: e.item, + }); + + if e.slot & 0x80 == 0 { + break; + } + // TODO: detect infinite loop + } + + Ok(EntityEquipments { equipments }) + } + + fn write_to(&self, _buf: &mut W) -> Result<(), Error> { + unimplemented!() + } +} + #[derive(Debug, Default)] pub struct EntityProperty { pub key: String, diff --git a/protocol/src/protocol/versions/v1_16_1.rs b/protocol/src/protocol/versions/v1_16_1.rs index b24033f..380d39b 100644 --- a/protocol/src/protocol/versions/v1_16_1.rs +++ b/protocol/src/protocol/versions/v1_16_1.rs @@ -128,7 +128,7 @@ protocol_packet_ids!( 0x44 => EntityMetadata 0x45 => EntityAttach 0x46 => EntityVelocity - 0x47 => EntityEquipment_VarInt // TODO: changed to an array, but earlier than 1.16.1 + 0x47 => EntityEquipment_Array 0x48 => SetExperience 0x49 => UpdateHealth 0x4a => ScoreboardObjective diff --git a/protocol/src/protocol/versions/v1_16_4.rs b/protocol/src/protocol/versions/v1_16_4.rs index c5e5102..2c351c6 100644 --- a/protocol/src/protocol/versions/v1_16_4.rs +++ b/protocol/src/protocol/versions/v1_16_4.rs @@ -129,7 +129,7 @@ protocol_packet_ids!( 0x44 => EntityMetadata 0x45 => EntityAttach 0x46 => EntityVelocity - 0x47 => EntityEquipment_VarInt // TODO: changed to an array, but earlier than 1.16.1 + 0x47 => EntityEquipment_Array 0x48 => SetExperience 0x49 => UpdateHealth 0x4a => ScoreboardObjective