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