ghast_protocol/generated/v1_12_1/handshaking/
serverbound.rs1#![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
28pub mod id {
30 pub const SET_PROTOCOL: i32 = 0x00;
32 pub const LEGACY_SERVER_LIST_PING: i32 = 0xfe;
34}
35
36pub type SetProtocol = crate::defs::p47::handshaking::serverbound::SetProtocol<338>;
38impl crate::packet::Packet for SetProtocol {
39 const ID: i32 = id::SET_PROTOCOL;
40 const NAME: &'static str = "set_protocol";
41 const STATE: State = State::Handshaking;
42 const DIRECTION: Direction = Direction::Serverbound;
43}
44impl From<SetProtocol> for ServerboundHandshakingPacket {
45 fn from(p: SetProtocol) -> Self {
46 Self::SetProtocol(p)
47 }
48}
49
50pub type LegacyServerListPing =
52 crate::defs::p47::handshaking::serverbound::LegacyServerListPing<338>;
53impl crate::packet::Packet for LegacyServerListPing {
54 const ID: i32 = id::LEGACY_SERVER_LIST_PING;
55 const NAME: &'static str = "legacy_server_list_ping";
56 const STATE: State = State::Handshaking;
57 const DIRECTION: Direction = Direction::Serverbound;
58}
59impl From<LegacyServerListPing> for ServerboundHandshakingPacket {
60 fn from(p: LegacyServerListPing) -> Self {
61 Self::LegacyServerListPing(p)
62 }
63}
64
65#[derive(Debug, Clone, PartialEq)]
67pub enum ServerboundHandshakingPacket {
68 SetProtocol(SetProtocol),
70 LegacyServerListPing(LegacyServerListPing),
72}
73
74impl PacketSet for ServerboundHandshakingPacket {
75 const STATE: State = State::Handshaking;
76 const DIRECTION: Direction = Direction::Serverbound;
77 fn decode_raw(raw: &RawPacket) -> DecodeResult<Self> {
78 match raw.id {
79 id::SET_PROTOCOL => decode_exact(&raw.body).map(Self::SetProtocol),
80 id::LEGACY_SERVER_LIST_PING => decode_exact(&raw.body).map(Self::LegacyServerListPing),
81 other => Err(DecodeError::UnknownPacketId(other)),
82 }
83 }
84 fn id(&self) -> i32 {
85 match *self {
86 Self::SetProtocol(_) => id::SET_PROTOCOL,
87 Self::LegacyServerListPing(_) => id::LEGACY_SERVER_LIST_PING,
88 }
89 }
90 fn name(&self) -> &'static str {
91 match *self {
92 Self::SetProtocol(_) => "set_protocol",
93 Self::LegacyServerListPing(_) => "legacy_server_list_ping",
94 }
95 }
96 fn encode_body(&self, w: &mut BytesMut) -> EncodeResult {
97 match *self {
98 Self::SetProtocol(ref p) => p.encode(w),
99 Self::LegacyServerListPing(ref p) => p.encode(w),
100 }
101 }
102 fn name_of(id: i32) -> Option<&'static str> {
103 match id {
104 id::SET_PROTOCOL => Some("set_protocol"),
105 id::LEGACY_SERVER_LIST_PING => Some("legacy_server_list_ping"),
106 _ => None,
107 }
108 }
109}
110
111impl ServerboundHandshakingPacket {
112 pub const IDS: &'static [i32] = &[id::SET_PROTOCOL, id::LEGACY_SERVER_LIST_PING];
114 #[cfg(feature = "testgen")]
116 pub fn generate_by_id(id: i32, g: &mut Gen) -> Option<Self> {
117 match id {
118 id::SET_PROTOCOL => Some(Self::SetProtocol(<SetProtocol as Generate>::generate(g))),
119 id::LEGACY_SERVER_LIST_PING => Some(Self::LegacyServerListPing(
120 <LegacyServerListPing as Generate>::generate(g),
121 )),
122 _ => None,
123 }
124 }
125}