chunkedge_protocol/packets/play/
chunks_biomes_s2c.rs

1use std::borrow::Cow;
2
3use chunkedge_binary::{Decode, Encode};
4
5use crate::{ChunkPos, Packet};
6
7#[derive(Clone, Debug, Encode, Decode, Packet)]
8pub struct ChunksBiomesS2c<'a> {
9    pub chunks: Cow<'a, [ChunkBiome<'a>]>,
10}
11
12#[derive(Clone, Debug)]
13pub struct ChunkBiome<'a> {
14    pub pos: ChunkPos,
15    /// Chunk data structure, with sections containing only the `Biomes` field.
16    pub data: &'a [u8],
17}
18
19// Note: The order of X and Z is inverted, because the client reads them
20// as one big-endian Long, with Z being the upper 32 bits.
21// https://minecraft.wiki/w/Java_Edition_protocol/Packets#Chunk_Biomes
22impl<'a> Decode<'a> for ChunkBiome<'a> {
23    fn decode(r: &mut &'a [u8]) -> anyhow::Result<Self> {
24        Ok(ChunkBiome {
25            pos: ChunkPos {
26                z: Decode::decode(r)?,
27                x: Decode::decode(r)?,
28            },
29            data: Decode::decode(r)?,
30        })
31    }
32}
33
34// Note: The order of X and Z is inverted, because the client reads them
35// as one big-endian Long, with Z being the upper 32 bits.
36// https://minecraft.wiki/w/Java_Edition_protocol/Packets#Chunk_Biomes
37impl Encode for ChunkBiome<'_> {
38    fn encode(&self, mut w: impl std::io::Write) -> anyhow::Result<()> {
39        self.pos.z.encode(&mut w)?;
40        self.pos.x.encode(&mut w)?;
41        self.data.encode(&mut w)
42    }
43}