Skip to main content

ghast_protocol/generated/v1_16_5/login/
serverbound.rs

1// @generated by ghast-codegen-protocol from PrismarineJS minecraft-data 3.119.0
2// (data/pc/1.16.2/protocol.json, Minecraft 1.16.5). 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 login 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    /// `login_start`
31    pub const LOGIN_START: i32 = 0x00;
32    /// `encryption_begin`
33    pub const ENCRYPTION_BEGIN: i32 = 0x01;
34    /// `login_plugin_response`
35    pub const LOGIN_PLUGIN_RESPONSE: i32 = 0x02;
36}
37
38/// `login_start` (serverbound login, id 0x00).
39pub type LoginStart = crate::defs::p47::login::serverbound::LoginStart<754>;
40impl crate::packet::Packet for LoginStart {
41    const ID: i32 = id::LOGIN_START;
42    const NAME: &'static str = "login_start";
43    const STATE: State = State::Login;
44    const DIRECTION: Direction = Direction::Serverbound;
45}
46impl From<LoginStart> for ServerboundLoginPacket {
47    fn from(p: LoginStart) -> Self {
48        Self::LoginStart(p)
49    }
50}
51
52/// `encryption_begin` (serverbound login, id 0x01).
53pub type EncryptionBegin = crate::defs::p47::login::serverbound::EncryptionBegin<754>;
54impl crate::packet::Packet for EncryptionBegin {
55    const ID: i32 = id::ENCRYPTION_BEGIN;
56    const NAME: &'static str = "encryption_begin";
57    const STATE: State = State::Login;
58    const DIRECTION: Direction = Direction::Serverbound;
59}
60impl From<EncryptionBegin> for ServerboundLoginPacket {
61    fn from(p: EncryptionBegin) -> Self {
62        Self::EncryptionBegin(p)
63    }
64}
65
66/// `login_plugin_response` (serverbound login, id 0x02).
67pub type LoginPluginResponse = crate::defs::p754::login::serverbound::LoginPluginResponse<754>;
68impl crate::packet::Packet for LoginPluginResponse {
69    const ID: i32 = id::LOGIN_PLUGIN_RESPONSE;
70    const NAME: &'static str = "login_plugin_response";
71    const STATE: State = State::Login;
72    const DIRECTION: Direction = Direction::Serverbound;
73}
74impl From<LoginPluginResponse> for ServerboundLoginPacket {
75    fn from(p: LoginPluginResponse) -> Self {
76        Self::LoginPluginResponse(p)
77    }
78}
79
80/// Every Serverbound packet of the Login state.
81#[derive(Debug, Clone, PartialEq)]
82pub enum ServerboundLoginPacket {
83    /// `login_start`
84    LoginStart(LoginStart),
85    /// `encryption_begin`
86    EncryptionBegin(EncryptionBegin),
87    /// `login_plugin_response`
88    LoginPluginResponse(LoginPluginResponse),
89}
90
91impl PacketSet for ServerboundLoginPacket {
92    const STATE: State = State::Login;
93    const DIRECTION: Direction = Direction::Serverbound;
94    fn decode_raw(raw: &RawPacket) -> DecodeResult<Self> {
95        match raw.id {
96            id::LOGIN_START => decode_exact(&raw.body).map(Self::LoginStart),
97            id::ENCRYPTION_BEGIN => decode_exact(&raw.body).map(Self::EncryptionBegin),
98            id::LOGIN_PLUGIN_RESPONSE => decode_exact(&raw.body).map(Self::LoginPluginResponse),
99            other => Err(DecodeError::UnknownPacketId(other)),
100        }
101    }
102    fn id(&self) -> i32 {
103        match *self {
104            Self::LoginStart(_) => id::LOGIN_START,
105            Self::EncryptionBegin(_) => id::ENCRYPTION_BEGIN,
106            Self::LoginPluginResponse(_) => id::LOGIN_PLUGIN_RESPONSE,
107        }
108    }
109    fn name(&self) -> &'static str {
110        match *self {
111            Self::LoginStart(_) => "login_start",
112            Self::EncryptionBegin(_) => "encryption_begin",
113            Self::LoginPluginResponse(_) => "login_plugin_response",
114        }
115    }
116    fn encode_body(&self, w: &mut BytesMut) -> EncodeResult {
117        match *self {
118            Self::LoginStart(ref p) => p.encode(w),
119            Self::EncryptionBegin(ref p) => p.encode(w),
120            Self::LoginPluginResponse(ref p) => p.encode(w),
121        }
122    }
123    fn name_of(id: i32) -> Option<&'static str> {
124        match id {
125            id::LOGIN_START => Some("login_start"),
126            id::ENCRYPTION_BEGIN => Some("encryption_begin"),
127            id::LOGIN_PLUGIN_RESPONSE => Some("login_plugin_response"),
128            _ => None,
129        }
130    }
131}
132
133impl ServerboundLoginPacket {
134    /// All packet ids of this set, ascending.
135    pub const IDS: &'static [i32] = &[
136        id::LOGIN_START,
137        id::ENCRYPTION_BEGIN,
138        id::LOGIN_PLUGIN_RESPONSE,
139    ];
140    /// Generates a random packet with the given id (test support).
141    #[cfg(feature = "testgen")]
142    pub fn generate_by_id(id: i32, g: &mut Gen) -> Option<Self> {
143        match id {
144            id::LOGIN_START => Some(Self::LoginStart(<LoginStart as Generate>::generate(g))),
145            id::ENCRYPTION_BEGIN => Some(Self::EncryptionBegin(
146                <EncryptionBegin as Generate>::generate(g),
147            )),
148            id::LOGIN_PLUGIN_RESPONSE => Some(Self::LoginPluginResponse(
149                <LoginPluginResponse as Generate>::generate(g),
150            )),
151            _ => None,
152        }
153    }
154}