Skip to main content

ghast_protocol/generated/v1_16_5/login/
clientbound.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//! Clientbound 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    /// `disconnect`
31    pub const DISCONNECT: i32 = 0x00;
32    /// `encryption_begin`
33    pub const ENCRYPTION_BEGIN: i32 = 0x01;
34    /// `success`
35    pub const SUCCESS: i32 = 0x02;
36    /// `compress`
37    pub const COMPRESS: i32 = 0x03;
38    /// `login_plugin_request`
39    pub const LOGIN_PLUGIN_REQUEST: i32 = 0x04;
40}
41
42/// `disconnect` (clientbound login, id 0x00).
43pub type Disconnect = crate::defs::p47::login::clientbound::Disconnect<754>;
44impl crate::packet::Packet for Disconnect {
45    const ID: i32 = id::DISCONNECT;
46    const NAME: &'static str = "disconnect";
47    const STATE: State = State::Login;
48    const DIRECTION: Direction = Direction::Clientbound;
49}
50impl From<Disconnect> for ClientboundLoginPacket {
51    fn from(p: Disconnect) -> Self {
52        Self::Disconnect(p)
53    }
54}
55
56/// `encryption_begin` (clientbound login, id 0x01).
57pub type EncryptionBegin = crate::defs::p47::login::clientbound::EncryptionBegin<754>;
58impl crate::packet::Packet for EncryptionBegin {
59    const ID: i32 = id::ENCRYPTION_BEGIN;
60    const NAME: &'static str = "encryption_begin";
61    const STATE: State = State::Login;
62    const DIRECTION: Direction = Direction::Clientbound;
63}
64impl From<EncryptionBegin> for ClientboundLoginPacket {
65    fn from(p: EncryptionBegin) -> Self {
66        Self::EncryptionBegin(p)
67    }
68}
69
70/// `success` (clientbound login, id 0x02).
71pub type Success = crate::defs::p754::login::clientbound::Success<754>;
72impl crate::packet::Packet for Success {
73    const ID: i32 = id::SUCCESS;
74    const NAME: &'static str = "success";
75    const STATE: State = State::Login;
76    const DIRECTION: Direction = Direction::Clientbound;
77}
78impl From<Success> for ClientboundLoginPacket {
79    fn from(p: Success) -> Self {
80        Self::Success(p)
81    }
82}
83
84/// `compress` (clientbound login, id 0x03).
85pub type Compress = crate::defs::p47::login::clientbound::Compress<754>;
86impl crate::packet::Packet for Compress {
87    const ID: i32 = id::COMPRESS;
88    const NAME: &'static str = "compress";
89    const STATE: State = State::Login;
90    const DIRECTION: Direction = Direction::Clientbound;
91}
92impl From<Compress> for ClientboundLoginPacket {
93    fn from(p: Compress) -> Self {
94        Self::Compress(p)
95    }
96}
97
98/// `login_plugin_request` (clientbound login, id 0x04).
99pub type LoginPluginRequest = crate::defs::p754::login::clientbound::LoginPluginRequest<754>;
100impl crate::packet::Packet for LoginPluginRequest {
101    const ID: i32 = id::LOGIN_PLUGIN_REQUEST;
102    const NAME: &'static str = "login_plugin_request";
103    const STATE: State = State::Login;
104    const DIRECTION: Direction = Direction::Clientbound;
105}
106impl From<LoginPluginRequest> for ClientboundLoginPacket {
107    fn from(p: LoginPluginRequest) -> Self {
108        Self::LoginPluginRequest(p)
109    }
110}
111
112/// Every Clientbound packet of the Login state.
113#[derive(Debug, Clone, PartialEq)]
114pub enum ClientboundLoginPacket {
115    /// `disconnect`
116    Disconnect(Disconnect),
117    /// `encryption_begin`
118    EncryptionBegin(EncryptionBegin),
119    /// `success`
120    Success(Success),
121    /// `compress`
122    Compress(Compress),
123    /// `login_plugin_request`
124    LoginPluginRequest(LoginPluginRequest),
125}
126
127impl PacketSet for ClientboundLoginPacket {
128    const STATE: State = State::Login;
129    const DIRECTION: Direction = Direction::Clientbound;
130    fn decode_raw(raw: &RawPacket) -> DecodeResult<Self> {
131        match raw.id {
132            id::DISCONNECT => decode_exact(&raw.body).map(Self::Disconnect),
133            id::ENCRYPTION_BEGIN => decode_exact(&raw.body).map(Self::EncryptionBegin),
134            id::SUCCESS => decode_exact(&raw.body).map(Self::Success),
135            id::COMPRESS => decode_exact(&raw.body).map(Self::Compress),
136            id::LOGIN_PLUGIN_REQUEST => decode_exact(&raw.body).map(Self::LoginPluginRequest),
137            other => Err(DecodeError::UnknownPacketId(other)),
138        }
139    }
140    fn id(&self) -> i32 {
141        match *self {
142            Self::Disconnect(_) => id::DISCONNECT,
143            Self::EncryptionBegin(_) => id::ENCRYPTION_BEGIN,
144            Self::Success(_) => id::SUCCESS,
145            Self::Compress(_) => id::COMPRESS,
146            Self::LoginPluginRequest(_) => id::LOGIN_PLUGIN_REQUEST,
147        }
148    }
149    fn name(&self) -> &'static str {
150        match *self {
151            Self::Disconnect(_) => "disconnect",
152            Self::EncryptionBegin(_) => "encryption_begin",
153            Self::Success(_) => "success",
154            Self::Compress(_) => "compress",
155            Self::LoginPluginRequest(_) => "login_plugin_request",
156        }
157    }
158    fn encode_body(&self, w: &mut BytesMut) -> EncodeResult {
159        match *self {
160            Self::Disconnect(ref p) => p.encode(w),
161            Self::EncryptionBegin(ref p) => p.encode(w),
162            Self::Success(ref p) => p.encode(w),
163            Self::Compress(ref p) => p.encode(w),
164            Self::LoginPluginRequest(ref p) => p.encode(w),
165        }
166    }
167    fn name_of(id: i32) -> Option<&'static str> {
168        match id {
169            id::DISCONNECT => Some("disconnect"),
170            id::ENCRYPTION_BEGIN => Some("encryption_begin"),
171            id::SUCCESS => Some("success"),
172            id::COMPRESS => Some("compress"),
173            id::LOGIN_PLUGIN_REQUEST => Some("login_plugin_request"),
174            _ => None,
175        }
176    }
177}
178
179impl ClientboundLoginPacket {
180    /// All packet ids of this set, ascending.
181    pub const IDS: &'static [i32] = &[
182        id::DISCONNECT,
183        id::ENCRYPTION_BEGIN,
184        id::SUCCESS,
185        id::COMPRESS,
186        id::LOGIN_PLUGIN_REQUEST,
187    ];
188    /// Generates a random packet with the given id (test support).
189    #[cfg(feature = "testgen")]
190    pub fn generate_by_id(id: i32, g: &mut Gen) -> Option<Self> {
191        match id {
192            id::DISCONNECT => Some(Self::Disconnect(<Disconnect as Generate>::generate(g))),
193            id::ENCRYPTION_BEGIN => Some(Self::EncryptionBegin(
194                <EncryptionBegin as Generate>::generate(g),
195            )),
196            id::SUCCESS => Some(Self::Success(<Success as Generate>::generate(g))),
197            id::COMPRESS => Some(Self::Compress(<Compress as Generate>::generate(g))),
198            id::LOGIN_PLUGIN_REQUEST => Some(Self::LoginPluginRequest(
199                <LoginPluginRequest as Generate>::generate(g),
200            )),
201            _ => None,
202        }
203    }
204}