Skip to main content

ghast_protocol/generated/v26_1/handshaking/
serverbound.rs

1// @generated by ghast-codegen-protocol from PrismarineJS minecraft-data 3.119.0
2// (data/pc/26.1/protocol.json, Minecraft 26.1.2). Do not edit; run `cargo run -p ghast-codegen-protocol`.
3// minecraft-data is MIT licensed, Copyright (c) 2015 PrismarineJS; see the NOTICE file
4// in crates/ghast-protocol/src/generated/.
5
6//! Serverbound packets of the handshaking state.
7
8#![allow(
9    unused_imports,
10    unused_variables,
11    unused_mut,
12    unused_parens,
13    unused_braces,
14    clippy::all,
15    clippy::pedantic,
16    non_camel_case_types,
17    non_snake_case
18)]
19use crate::codec::{Decode, DecodeResult, Encode, EncodeResult, McWrite, Reader, decode_exact};
20use crate::error::{DecodeError, EncodeError};
21use crate::nbt::{AnonNbt, RawNbt};
22use crate::packet::{Direction, PacketSet, RawPacket, State};
23#[cfg(feature = "testgen")]
24use crate::testgen::{Gen, Generate};
25use crate::types::{BlockPos, ByteString, Holder, HolderSet, LpVec3, PositionLayout, Uuid};
26use bytes::{BufMut, Bytes, BytesMut};
27
28/// Packet ids.
29pub mod id {
30    /// `set_protocol`
31    pub const SET_PROTOCOL: i32 = 0x00;
32    /// `legacy_server_list_ping`
33    pub const LEGACY_SERVER_LIST_PING: i32 = 0xfe;
34}
35
36/// `set_protocol` (serverbound handshaking, id 0x00).
37pub type SetProtocol = crate::defs::p47::handshaking::serverbound::SetProtocol<775>;
38impl crate::packet::Packet for SetProtocol {
39    const ID: i32 = id::SET_PROTOCOL;
40    const NAME: &'static str = "set_protocol";
41    const STATE: State = State::Handshaking;
42    const DIRECTION: Direction = Direction::Serverbound;
43}
44impl From<SetProtocol> for ServerboundHandshakingPacket {
45    fn from(p: SetProtocol) -> Self {
46        Self::SetProtocol(p)
47    }
48}
49
50/// `legacy_server_list_ping` (serverbound handshaking, id 0xfe).
51pub type LegacyServerListPing =
52    crate::defs::p47::handshaking::serverbound::LegacyServerListPing<775>;
53impl crate::packet::Packet for LegacyServerListPing {
54    const ID: i32 = id::LEGACY_SERVER_LIST_PING;
55    const NAME: &'static str = "legacy_server_list_ping";
56    const STATE: State = State::Handshaking;
57    const DIRECTION: Direction = Direction::Serverbound;
58}
59impl From<LegacyServerListPing> for ServerboundHandshakingPacket {
60    fn from(p: LegacyServerListPing) -> Self {
61        Self::LegacyServerListPing(p)
62    }
63}
64
65/// Every Serverbound packet of the Handshaking state.
66#[derive(Debug, Clone, PartialEq)]
67pub enum ServerboundHandshakingPacket {
68    /// `set_protocol`
69    SetProtocol(SetProtocol),
70    /// `legacy_server_list_ping`
71    LegacyServerListPing(LegacyServerListPing),
72}
73
74impl PacketSet for ServerboundHandshakingPacket {
75    const STATE: State = State::Handshaking;
76    const DIRECTION: Direction = Direction::Serverbound;
77    fn decode_raw(raw: &RawPacket) -> DecodeResult<Self> {
78        match raw.id {
79            id::SET_PROTOCOL => decode_exact(&raw.body).map(Self::SetProtocol),
80            id::LEGACY_SERVER_LIST_PING => decode_exact(&raw.body).map(Self::LegacyServerListPing),
81            other => Err(DecodeError::UnknownPacketId(other)),
82        }
83    }
84    fn id(&self) -> i32 {
85        match *self {
86            Self::SetProtocol(_) => id::SET_PROTOCOL,
87            Self::LegacyServerListPing(_) => id::LEGACY_SERVER_LIST_PING,
88        }
89    }
90    fn name(&self) -> &'static str {
91        match *self {
92            Self::SetProtocol(_) => "set_protocol",
93            Self::LegacyServerListPing(_) => "legacy_server_list_ping",
94        }
95    }
96    fn encode_body(&self, w: &mut BytesMut) -> EncodeResult {
97        match *self {
98            Self::SetProtocol(ref p) => p.encode(w),
99            Self::LegacyServerListPing(ref p) => p.encode(w),
100        }
101    }
102    fn name_of(id: i32) -> Option<&'static str> {
103        match id {
104            id::SET_PROTOCOL => Some("set_protocol"),
105            id::LEGACY_SERVER_LIST_PING => Some("legacy_server_list_ping"),
106            _ => None,
107        }
108    }
109}
110
111impl ServerboundHandshakingPacket {
112    /// All packet ids of this set, ascending.
113    pub const IDS: &'static [i32] = &[id::SET_PROTOCOL, id::LEGACY_SERVER_LIST_PING];
114    /// Generates a random packet with the given id (test support).
115    #[cfg(feature = "testgen")]
116    pub fn generate_by_id(id: i32, g: &mut Gen) -> Option<Self> {
117        match id {
118            id::SET_PROTOCOL => Some(Self::SetProtocol(<SetProtocol as Generate>::generate(g))),
119            id::LEGACY_SERVER_LIST_PING => Some(Self::LegacyServerListPing(
120                <LegacyServerListPing as Generate>::generate(g),
121            )),
122            _ => None,
123        }
124    }
125}