azalea_protocol/packets/game/
s_set_structure_block.rs1use 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, Default)]
51pub enum Mirror {
52 #[default]
53 None = 0,
54 LeftRight = 1,
55 FrontBack = 2,
56}
57
58#[derive(AzBuf, Clone, Copy, Debug, Default)]
59pub enum Rotation {
60 #[default]
61 None = 0,
62 Clockwise90 = 1,
63 Clockwise180 = 2,
64 Counterclockwise90 = 3,
65}
66
67#[derive(Debug, Clone)]
68pub struct Flags {
69 pub ignore_entities: bool,
70 pub show_air: bool,
71 pub show_bounding_box: bool,
72}
73
74impl AzaleaRead for Flags {
75 fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
76 let set = FixedBitSet::<{ 3_usize.div_ceil(8) }>::azalea_read(buf)?;
77 Ok(Self {
78 ignore_entities: set.index(0),
79 show_air: set.index(1),
80 show_bounding_box: set.index(2),
81 })
82 }
83}
84
85impl AzaleaWrite for Flags {
86 fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
87 let mut set = FixedBitSet::<{ 3_usize.div_ceil(8) }>::new();
88 if self.ignore_entities {
89 set.set(0);
90 }
91 if self.show_air {
92 set.set(1);
93 }
94 if self.show_bounding_box {
95 set.set(2);
96 }
97 set.azalea_write(buf)?;
98 Ok(())
99 }
100}