chunkedge_protocol/packets/play/
forget_level_chunk_s2c.rs

1use chunkedge_binary::{Decode, Encode};
2
3use crate::{ChunkPos, Packet};
4
5#[derive(Copy, Clone, Debug, Packet)]
6pub struct ForgetLevelChunkS2c {
7    pub pos: ChunkPos,
8}
9
10// Note: The order of X and Z is inverted, because the client reads them
11// as one big-endian Long, with Z being the upper 32 bits.
12// https://minecraft.wiki/w/Java_Edition_protocol/Packets#Chunk_Biomes
13impl Decode<'_> for ForgetLevelChunkS2c {
14    fn decode(r: &mut &'_ [u8]) -> anyhow::Result<Self> {
15        Ok(ForgetLevelChunkS2c {
16            pos: ChunkPos {
17                z: Decode::decode(r)?,
18                x: Decode::decode(r)?,
19            },
20        })
21    }
22}
23
24// Note: The order is inverted, because the client reads this packet as
25// one big-endian Long, with Z being the upper 32 bits.
26// https://minecraft.wiki/w/Java_Edition_protocol/Packets#Unload_Chunk
27impl Encode for ForgetLevelChunkS2c {
28    fn encode(&self, mut w: impl std::io::Write) -> anyhow::Result<()> {
29        self.pos.z.encode(&mut w)?;
30        self.pos.x.encode(&mut w)
31    }
32}