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