Skip to main content

ghast_protocol/generated/defs/p47/handshaking/
serverbound.rs

1// @generated by ghast-codegen-protocol from PrismarineJS minecraft-data 3.119.0
2// (data/pc/1.8/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 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#[cfg(any(
29    feature = "v1_8",
30    feature = "v1_12_2",
31    feature = "v1_16_5",
32    feature = "v26_1",
33    feature = "v26_2"
34))]
35/// `set_protocol` (serverbound handshaking).
36#[derive(Debug, Clone, PartialEq)]
37pub struct SetProtocol<const V: i32> {
38    /// `protocolVersion`
39    pub protocol_version: i32,
40    /// `serverHost`
41    pub server_host: ByteString,
42    /// `serverPort`
43    pub server_port: u16,
44    /// `nextState`
45    pub next_state: i32,
46}
47#[cfg(any(
48    feature = "v1_8",
49    feature = "v1_12_2",
50    feature = "v1_16_5",
51    feature = "v26_1",
52    feature = "v26_2"
53))]
54impl<const V: i32> Decode for SetProtocol<V> {
55    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
56        Ok({
57            let v1 = r.read_varint()?;
58            let v2 = r.read_string()?;
59            let v3 = r.read_u16()?;
60            let v4 = r.read_varint()?;
61            Self {
62                protocol_version: v1,
63                server_host: v2,
64                server_port: v3,
65                next_state: v4,
66            }
67        })
68    }
69}
70#[cfg(any(
71    feature = "v1_8",
72    feature = "v1_12_2",
73    feature = "v1_16_5",
74    feature = "v26_1",
75    feature = "v26_2"
76))]
77impl<const V: i32> Encode for SetProtocol<V> {
78    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
79        w.put_varint((*self).protocol_version);
80        w.put_string(&(*self).server_host)?;
81        w.put_u16((*self).server_port);
82        w.put_varint((*self).next_state);
83        Ok(())
84    }
85}
86#[cfg(any(
87    feature = "v1_8",
88    feature = "v1_12_2",
89    feature = "v1_16_5",
90    feature = "v26_1",
91    feature = "v26_2"
92))]
93#[cfg(feature = "testgen")]
94impl<const V: i32> Generate for SetProtocol<V> {
95    fn generate(g: &mut Gen) -> Self {
96        {
97            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
98            let v2 = g.string();
99            let v3 = (g.int_in(0, 65535, &[]) as u16);
100            let v4 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
101            Self {
102                protocol_version: v1,
103                server_host: v2,
104                server_port: v3,
105                next_state: v4,
106            }
107        }
108    }
109}
110
111#[cfg(any(
112    feature = "v1_8",
113    feature = "v1_12_2",
114    feature = "v1_16_5",
115    feature = "v26_1",
116    feature = "v26_2"
117))]
118/// `legacy_server_list_ping` (serverbound handshaking).
119#[derive(Debug, Clone, PartialEq)]
120pub struct LegacyServerListPing<const V: i32> {
121    /// `payload`
122    pub payload: u8,
123}
124#[cfg(any(
125    feature = "v1_8",
126    feature = "v1_12_2",
127    feature = "v1_16_5",
128    feature = "v26_1",
129    feature = "v26_2"
130))]
131impl<const V: i32> Decode for LegacyServerListPing<V> {
132    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
133        Ok({
134            let v1 = r.read_u8()?;
135            Self { payload: v1 }
136        })
137    }
138}
139#[cfg(any(
140    feature = "v1_8",
141    feature = "v1_12_2",
142    feature = "v1_16_5",
143    feature = "v26_1",
144    feature = "v26_2"
145))]
146impl<const V: i32> Encode for LegacyServerListPing<V> {
147    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
148        w.put_u8((*self).payload);
149        Ok(())
150    }
151}
152#[cfg(any(
153    feature = "v1_8",
154    feature = "v1_12_2",
155    feature = "v1_16_5",
156    feature = "v26_1",
157    feature = "v26_2"
158))]
159#[cfg(feature = "testgen")]
160impl<const V: i32> Generate for LegacyServerListPing<V> {
161    fn generate(g: &mut Gen) -> Self {
162        {
163            let v1 = (g.int_in(0, 255, &[]) as u8);
164            Self { payload: v1 }
165        }
166    }
167}