Skip to main content

steel_protocol/packets/game/
s_sign_update.rs

1use std::io::Cursor;
2
3use steel_macros::ServerPacket;
4use steel_utils::BlockPos;
5use steel_utils::serial::{PrefixedRead, ReadFrom};
6
7/// Maximum characters per sign line.
8pub const MAX_SIGN_LINE_LENGTH: usize = 384;
9
10/// Serverbound packet sent when a player finishes editing a sign.
11#[derive(ServerPacket, Clone, Debug)]
12pub struct SSignUpdate {
13    /// The position of the sign block.
14    pub pos: BlockPos,
15    /// Whether updating the front text (true) or back text (false).
16    pub is_front_text: bool,
17    /// The four lines of text. Each line is max 384 characters.
18    pub lines: [String; 4],
19}
20
21impl ReadFrom for SSignUpdate {
22    fn read(data: &mut Cursor<&[u8]>) -> std::io::Result<Self> {
23        use steel_utils::codec::VarInt;
24
25        let pos = BlockPos::read(data)?;
26        let is_front_text = bool::read(data)?;
27        let lines = [
28            String::read_prefixed_bound::<VarInt>(data, MAX_SIGN_LINE_LENGTH)?,
29            String::read_prefixed_bound::<VarInt>(data, MAX_SIGN_LINE_LENGTH)?,
30            String::read_prefixed_bound::<VarInt>(data, MAX_SIGN_LINE_LENGTH)?,
31            String::read_prefixed_bound::<VarInt>(data, MAX_SIGN_LINE_LENGTH)?,
32        ];
33
34        Ok(Self {
35            pos,
36            is_front_text,
37            lines,
38        })
39    }
40}