From 4cd8e627d914e5036d8744023c1311c1e94062d4 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Fri, 24 Dec 2021 16:33:09 -0800 Subject: [PATCH] protocol: ChunkData_AndLight: add struct BlockEntityAtPackedLocation --- protocol/src/protocol/packet.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/protocol/src/protocol/packet.rs b/protocol/src/protocol/packet.rs index 8f26a8d..a688142 100644 --- a/protocol/src/protocol/packet.rs +++ b/protocol/src/protocol/packet.rs @@ -1142,7 +1142,7 @@ state_packets!( field chunk_z: i32 =, field heightmaps: Option =, field data: LenPrefixedBytes =, - field block_entities: LenPrefixed> =, // TODO: packed xz,y,type + field block_entities: LenPrefixed =, field trust_edges: bool =, // TODO: BitSets instead of long arrays @@ -2774,6 +2774,34 @@ impl Serializable for CriterionProgress { } } +#[derive(Debug, Default)] +pub struct BlockEntityAtPackedLocation { + /// The packed section coordinates, calculated from ((blockX & 15) << 4) | (blockZ & 15) + pub packed_xz: u8, + /// The height relative to the world + pub y: i16, + pub ty: VarInt, + pub data: Option, +} + +impl Serializable for BlockEntityAtPackedLocation { + fn read_from(buf: &mut R) -> Result { + Ok(BlockEntityAtPackedLocation { + packed_xz: Serializable::read_from(buf)?, + y: Serializable::read_from(buf)?, + ty: Serializable::read_from(buf)?, + data: Serializable::read_from(buf)?, + }) + } + + fn write_to(&self, buf: &mut W) -> Result<(), Error> { + self.packed_xz.write_to(buf)?; + self.y.write_to(buf)?; + self.ty.write_to(buf)?; + self.data.write_to(buf) + } +} + #[derive(Debug, Default)] pub struct EntityEquipment { pub slot: u8,