Skip to main content

steel_protocol/packets/game/
s_set_beacon.rs

1//! Serverbound packet for selecting a beacon's primary and secondary effects.
2
3use std::io::Cursor;
4
5use steel_macros::ServerPacket;
6use steel_utils::codec::VarInt;
7use steel_utils::serial::ReadFrom;
8
9/// Sent when the player confirms a beacon's effect selection.
10///
11/// Each effect is encoded as `ByteBufCodecs.optional(MobEffect.STREAM_CODEC)`:
12/// a presence boolean followed by the mob effect's raw registry id as a `VarInt`.
13#[derive(ServerPacket, Clone, Debug)]
14pub struct SSetBeacon {
15    pub primary: Option<i32>,
16    pub secondary: Option<i32>,
17}
18
19impl ReadFrom for SSetBeacon {
20    fn read(data: &mut Cursor<&[u8]>) -> std::io::Result<Self> {
21        Ok(Self {
22            primary: read_optional_effect(data)?,
23            secondary: read_optional_effect(data)?,
24        })
25    }
26}
27
28fn read_optional_effect(data: &mut Cursor<&[u8]>) -> std::io::Result<Option<i32>> {
29    if !bool::read(data)? {
30        return Ok(None);
31    }
32    Ok(Some(VarInt::read(data)?.0))
33}