azalea_protocol/packets/game/
s_set_structure_block.rs

1use std::io::{self, Cursor, Write};
2
3use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite};
4use azalea_core::{bitset::FixedBitSet, position::BlockPos};
5use azalea_protocol_macros::ServerboundGamePacket;
6
7use crate::packets::BufReadError;
8
9#[derive(Clone, Debug, AzBuf, PartialEq, ServerboundGamePacket)]
10pub struct ServerboundSetStructureBlock {
11    pub pos: BlockPos,
12    pub update_type: UpdateType,
13    pub mode: StructureMode,
14    pub name: String,
15    pub offset: BytePosition,
16    pub size: BytePosition,
17    pub mirror: Mirror,
18    pub rotation: Rotation,
19    pub data: String,
20    pub integrity: f32,
21    #[var]
22    pub seed: u64,
23    pub flags: Flags,
24}
25
26#[derive(Clone, Debug, AzBuf, PartialEq)]
27pub struct BytePosition {
28    pub x: u8,
29    pub y: u8,
30    pub z: u8,
31}
32
33#[derive(AzBuf, Clone, Copy, Debug, PartialEq)]
34pub enum UpdateType {
35    UpdateData = 0,
36    SaveArea = 1,
37    LoadArea = 2,
38    ScanArea = 3,
39}
40
41#[derive(AzBuf, Clone, Copy, Debug, PartialEq)]
42pub enum StructureMode {
43    Save = 0,
44    Load = 1,
45    Corner = 2,
46    Data = 3,
47}
48
49#[derive(AzBuf, Clone, Copy, Debug, Default, PartialEq)]
50pub enum Mirror {
51    #[default]
52    None = 0,
53    LeftRight = 1,
54    FrontBack = 2,
55}
56
57#[derive(AzBuf, Clone, Copy, Debug, Default, PartialEq)]
58pub enum Rotation {
59    #[default]
60    None = 0,
61    Clockwise90 = 1,
62    Clockwise180 = 2,
63    Counterclockwise90 = 3,
64}
65
66#[derive(Debug, Clone, PartialEq)]
67pub struct Flags {
68    pub ignore_entities: bool,
69    pub show_air: bool,
70    pub show_bounding_box: bool,
71}
72
73impl AzaleaRead for Flags {
74    fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
75        let set = FixedBitSet::<3>::azalea_read(buf)?;
76        Ok(Self {
77            ignore_entities: set.index(0),
78            show_air: set.index(1),
79            show_bounding_box: set.index(2),
80        })
81    }
82}
83
84impl AzaleaWrite for Flags {
85    fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
86        let mut set = FixedBitSet::<3>::new();
87        if self.ignore_entities {
88            set.set(0);
89        }
90        if self.show_air {
91            set.set(1);
92        }
93        if self.show_bounding_box {
94            set.set(2);
95        }
96        set.azalea_write(buf)?;
97        Ok(())
98    }
99}