azalea_protocol/packets/game/
s_set_command_block.rs1use std::io::{self, Cursor, Write};
2
3use azalea_buf::{AzBuf, BufReadError};
4use azalea_core::{bitset::FixedBitSet, position::BlockPos};
5use azalea_protocol_macros::ServerboundGamePacket;
6
7#[derive(Clone, Debug, PartialEq, ServerboundGamePacket)]
8pub struct ServerboundSetCommandBlock {
9 pub pos: BlockPos,
10 pub command: String,
11 pub mode: Mode,
12
13 pub track_output: bool,
14 pub conditional: bool,
15 pub automatic: bool,
16}
17
18#[derive(AzBuf, Clone, Copy, Debug, PartialEq)]
19pub enum Mode {
20 Sequence = 0,
21 Auto = 1,
22 Redstone = 2,
23}
24
25impl AzBuf for ServerboundSetCommandBlock {
26 fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
27 let pos = BlockPos::azalea_read(buf)?;
28 let command = String::azalea_read(buf)?;
29 let mode = Mode::azalea_read(buf)?;
30
31 let set = FixedBitSet::<3>::azalea_read(buf)?;
32 Ok(Self {
33 pos,
34 command,
35 mode,
36 track_output: set.index(0),
37 conditional: set.index(1),
38 automatic: set.index(2),
39 })
40 }
41 fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
42 self.pos.azalea_write(buf)?;
43 self.command.azalea_write(buf)?;
44 self.mode.azalea_write(buf)?;
45
46 let mut set = FixedBitSet::<3>::new();
47 if self.track_output {
48 set.set(0);
49 }
50 if self.conditional {
51 set.set(1);
52 }
53 if self.automatic {
54 set.set(2);
55 }
56 set.azalea_write(buf)
57 }
58}