Skip to main content

basalt_mc_protocol/packets/
handshake.rs

1//! Handshake 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 = 0xfe)]
15pub struct ServerboundHandshakeLegacyServerListPing {
16    pub payload: u8,
17}
18
19#[derive(Debug, Clone, Default, PartialEq)]
20#[packet(id = 0x00)]
21pub struct ServerboundHandshakeSetProtocol {
22    #[field(varint)]
23    pub protocol_version: i32,
24    pub server_host: String,
25    pub server_port: u16,
26    #[field(varint)]
27    pub next_state: i32,
28}
29
30/// serverbound packets in the Handshake state.
31#[derive(Debug, Clone, PartialEq)]
32pub enum ServerboundHandshakePacket {
33    LegacyServerListPing(ServerboundHandshakeLegacyServerListPing),
34    SetProtocol(ServerboundHandshakeSetProtocol),
35}
36
37impl ServerboundHandshakePacket {
38    /// Decodes a packet from its ID and payload.
39    pub fn decode_by_id(id: i32, buf: &mut &[u8]) -> Result<Self> {
40        match id {
41            ServerboundHandshakeLegacyServerListPing::PACKET_ID => Ok(Self::LegacyServerListPing(
42                ServerboundHandshakeLegacyServerListPing::decode(buf)?,
43            )),
44            ServerboundHandshakeSetProtocol::PACKET_ID => Ok(Self::SetProtocol(
45                ServerboundHandshakeSetProtocol::decode(buf)?,
46            )),
47            _ => Err(Error::UnknownPacket {
48                id,
49                state: "handshake",
50            }),
51        }
52    }
53}