Skip to main content

basalt_mc_protocol/packets/
status.rs

1//! Status state packet definitions.
2//!
3//! Auto-generated by `cargo xt codegen` from minecraft-data.
4//! Do not edit manually — changes will be overwritten.
5
6use basalt_derive::packet;
7use basalt_types::Decode as _;
8
9use crate::error::{Error, Result};
10
11// -- Serverbound packets --
12
13#[derive(Debug, Clone, Default, PartialEq)]
14#[packet(id = 0x01)]
15pub struct ServerboundStatusPing {
16    pub time: i64,
17}
18
19#[derive(Debug, Clone, Default, PartialEq)]
20#[packet(id = 0x00)]
21pub struct ServerboundStatusPingStart;
22
23// -- Clientbound packets --
24
25#[derive(Debug, Clone, Default, PartialEq)]
26#[packet(id = 0x01)]
27pub struct ClientboundStatusPing {
28    pub time: i64,
29}
30
31#[derive(Debug, Clone, Default, PartialEq)]
32#[packet(id = 0x00)]
33pub struct ClientboundStatusServerInfo {
34    pub response: String,
35}
36
37/// serverbound packets in the Status state.
38#[derive(Debug, Clone, PartialEq)]
39pub enum ServerboundStatusPacket {
40    Ping(ServerboundStatusPing),
41    PingStart(ServerboundStatusPingStart),
42}
43
44impl ServerboundStatusPacket {
45    /// Decodes a packet from its ID and payload.
46    pub fn decode_by_id(id: i32, buf: &mut &[u8]) -> Result<Self> {
47        match id {
48            ServerboundStatusPing::PACKET_ID => Ok(Self::Ping(ServerboundStatusPing::decode(buf)?)),
49            ServerboundStatusPingStart::PACKET_ID => {
50                Ok(Self::PingStart(ServerboundStatusPingStart::decode(buf)?))
51            }
52            _ => Err(Error::UnknownPacket {
53                id,
54                state: "status",
55            }),
56        }
57    }
58}
59
60/// clientbound packets in the Status state.
61#[derive(Debug, Clone, PartialEq)]
62pub enum ClientboundStatusPacket {
63    Ping(ClientboundStatusPing),
64    ServerInfo(ClientboundStatusServerInfo),
65}
66
67impl ClientboundStatusPacket {
68    /// Decodes a packet from its ID and payload.
69    pub fn decode_by_id(id: i32, buf: &mut &[u8]) -> Result<Self> {
70        match id {
71            ClientboundStatusPing::PACKET_ID => Ok(Self::Ping(ClientboundStatusPing::decode(buf)?)),
72            ClientboundStatusServerInfo::PACKET_ID => {
73                Ok(Self::ServerInfo(ClientboundStatusServerInfo::decode(buf)?))
74            }
75            _ => Err(Error::UnknownPacket {
76                id,
77                state: "status",
78            }),
79        }
80    }
81}