azalea_protocol/packets/game/
s_set_jigsaw_block.rs

1use std::{
2    io,
3    io::{Cursor, Write},
4};
5
6use azalea_buf::{AzBuf, AzaleaRead};
7use azalea_core::{position::BlockPos, resource_location::ResourceLocation};
8use azalea_protocol_macros::ServerboundGamePacket;
9
10use crate::packets::{AzaleaWrite, BufReadError};
11
12#[derive(Clone, Debug, AzBuf, PartialEq, ServerboundGamePacket)]
13pub struct ServerboundSetJigsawBlock {
14    pub pos: BlockPos,
15    pub name: ResourceLocation,
16    pub target: ResourceLocation,
17    pub pool: ResourceLocation,
18    pub final_state: String,
19    pub joint: String,
20    #[var]
21    pub selection_priority: i32,
22    #[var]
23    pub placement_priority: i32,
24}
25
26pub enum JointType {
27    Rollable,
28    Aligned,
29}
30
31impl AzaleaRead for JointType {
32    fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
33        let name = String::azalea_read(buf)?;
34        match name.as_str() {
35            "rollable" => Ok(JointType::Rollable),
36            "aligned" => Ok(JointType::Aligned),
37            _ => Err(BufReadError::UnexpectedStringEnumVariant { id: name }),
38        }
39    }
40}
41
42impl AzaleaWrite for JointType {
43    fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
44        match self {
45            JointType::Rollable => "rollable".to_string().azalea_write(buf)?,
46            JointType::Aligned => "aligned".to_string().azalea_write(buf)?,
47        };
48        Ok(())
49    }
50}