Skip to main content

ghast_protocol/generated/v1_12_2/status/
clientbound.rs

1// @generated by ghast-codegen-protocol from PrismarineJS minecraft-data 3.119.0
2// (data/pc/1.12.2/protocol.json, Minecraft 1.12.2). 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//! Clientbound packets of the status 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/// Packet ids.
29pub mod id {
30    /// `server_info`
31    pub const SERVER_INFO: i32 = 0x00;
32    /// `ping`
33    pub const PING: i32 = 0x01;
34}
35
36/// `server_info` (clientbound status, id 0x00).
37pub type ServerInfo = crate::defs::p47::status::clientbound::ServerInfo<340>;
38impl crate::packet::Packet for ServerInfo {
39    const ID: i32 = id::SERVER_INFO;
40    const NAME: &'static str = "server_info";
41    const STATE: State = State::Status;
42    const DIRECTION: Direction = Direction::Clientbound;
43}
44impl From<ServerInfo> for ClientboundStatusPacket {
45    fn from(p: ServerInfo) -> Self {
46        Self::ServerInfo(p)
47    }
48}
49
50/// `ping` (clientbound status, id 0x01).
51pub type Ping = crate::defs::p47::status::clientbound::Ping<340>;
52impl crate::packet::Packet for Ping {
53    const ID: i32 = id::PING;
54    const NAME: &'static str = "ping";
55    const STATE: State = State::Status;
56    const DIRECTION: Direction = Direction::Clientbound;
57}
58impl From<Ping> for ClientboundStatusPacket {
59    fn from(p: Ping) -> Self {
60        Self::Ping(p)
61    }
62}
63
64/// Every Clientbound packet of the Status state.
65#[derive(Debug, Clone, PartialEq)]
66pub enum ClientboundStatusPacket {
67    /// `server_info`
68    ServerInfo(ServerInfo),
69    /// `ping`
70    Ping(Ping),
71}
72
73impl PacketSet for ClientboundStatusPacket {
74    const STATE: State = State::Status;
75    const DIRECTION: Direction = Direction::Clientbound;
76    fn decode_raw(raw: &RawPacket) -> DecodeResult<Self> {
77        match raw.id {
78            id::SERVER_INFO => decode_exact(&raw.body).map(Self::ServerInfo),
79            id::PING => decode_exact(&raw.body).map(Self::Ping),
80            other => Err(DecodeError::UnknownPacketId(other)),
81        }
82    }
83    fn id(&self) -> i32 {
84        match *self {
85            Self::ServerInfo(_) => id::SERVER_INFO,
86            Self::Ping(_) => id::PING,
87        }
88    }
89    fn name(&self) -> &'static str {
90        match *self {
91            Self::ServerInfo(_) => "server_info",
92            Self::Ping(_) => "ping",
93        }
94    }
95    fn encode_body(&self, w: &mut BytesMut) -> EncodeResult {
96        match *self {
97            Self::ServerInfo(ref p) => p.encode(w),
98            Self::Ping(ref p) => p.encode(w),
99        }
100    }
101    fn name_of(id: i32) -> Option<&'static str> {
102        match id {
103            id::SERVER_INFO => Some("server_info"),
104            id::PING => Some("ping"),
105            _ => None,
106        }
107    }
108}
109
110impl ClientboundStatusPacket {
111    /// All packet ids of this set, ascending.
112    pub const IDS: &'static [i32] = &[id::SERVER_INFO, id::PING];
113    /// Generates a random packet with the given id (test support).
114    #[cfg(feature = "testgen")]
115    pub fn generate_by_id(id: i32, g: &mut Gen) -> Option<Self> {
116        match id {
117            id::SERVER_INFO => Some(Self::ServerInfo(<ServerInfo as Generate>::generate(g))),
118            id::PING => Some(Self::Ping(<Ping as Generate>::generate(g))),
119            _ => None,
120        }
121    }
122}