Skip to main content

ghast_protocol/generated/defs/p754/login/
serverbound.rs

1// @generated by ghast-codegen-protocol from PrismarineJS minecraft-data 3.119.0
2// (data/pc/1.16.2/protocol.json). 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#[cfg(any(
29    feature = "v1_16_5",
30    feature = "v26_1",
31    feature = "v26_2",
32    feature = "v26_3"
33))]
34/// `login_plugin_response` (serverbound login).
35#[derive(Debug, Clone, PartialEq)]
36pub struct LoginPluginResponse<const V: i32> {
37    /// `messageId`
38    pub message_id: i32,
39    /// `data`
40    pub data: Option<Bytes>,
41}
42#[cfg(any(
43    feature = "v1_16_5",
44    feature = "v26_1",
45    feature = "v26_2",
46    feature = "v26_3"
47))]
48impl<const V: i32> Decode for LoginPluginResponse<V> {
49    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
50        Ok({
51            let v1 = r.read_varint()?;
52            let v2 = if r.read_bool()? {
53                Some(r.read_rest())
54            } else {
55                None
56            };
57            Self {
58                message_id: v1,
59                data: v2,
60            }
61        })
62    }
63}
64#[cfg(any(
65    feature = "v1_16_5",
66    feature = "v26_1",
67    feature = "v26_2",
68    feature = "v26_3"
69))]
70impl<const V: i32> Encode for LoginPluginResponse<V> {
71    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
72        w.put_varint((*self).message_id);
73        match &(*self).data {
74            Some(v1) => {
75                w.put_u8(1);
76                w.put_slice(&(*v1));
77            }
78            None => w.put_u8(0),
79        }
80        Ok(())
81    }
82}
83#[cfg(any(
84    feature = "v1_16_5",
85    feature = "v26_1",
86    feature = "v26_2",
87    feature = "v26_3"
88))]
89#[cfg(feature = "testgen")]
90impl<const V: i32> Generate for LoginPluginResponse<V> {
91    fn generate(g: &mut Gen) -> Self {
92        {
93            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
94            let v2 = if g.bool() { Some(g.bytes()) } else { None };
95            Self {
96                message_id: v1,
97                data: v2,
98            }
99        }
100    }
101}