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