azalea_protocol/packets/game/
s_set_structure_block.rs

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