Skip to main content

ghast_protocol/generated/v26_2/status/
serverbound.rs

1// @generated by ghast-codegen-protocol from PrismarineJS minecraft-data 3.119.0
2// (data/pc/26.1/protocol.json + codegen/protocol/delta/776.json, Minecraft 26.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//! Serverbound 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    /// `ping_start`
31    pub const PING_START: i32 = 0x00;
32    /// `ping`
33    pub const PING: i32 = 0x01;
34}
35
36/// `ping_start` (serverbound status, id 0x00).
37pub type PingStart = crate::defs::p47::status::serverbound::PingStart<776>;
38impl crate::packet::Packet for PingStart {
39    const ID: i32 = id::PING_START;
40    const NAME: &'static str = "ping_start";
41    const STATE: State = State::Status;
42    const DIRECTION: Direction = Direction::Serverbound;
43}
44impl From<PingStart> for ServerboundStatusPacket {
45    fn from(p: PingStart) -> Self {
46        Self::PingStart(p)
47    }
48}
49
50/// `ping` (serverbound status, id 0x01).
51pub type Ping = crate::defs::p47::status::serverbound::Ping<776>;
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::Serverbound;
57}
58impl From<Ping> for ServerboundStatusPacket {
59    fn from(p: Ping) -> Self {
60        Self::Ping(p)
61    }
62}
63
64/// Every Serverbound packet of the Status state.
65#[derive(Debug, Clone, PartialEq)]
66pub enum ServerboundStatusPacket {
67    /// `ping_start`
68    PingStart(PingStart),
69    /// `ping`
70    Ping(Ping),
71}
72
73impl PacketSet for ServerboundStatusPacket {
74    const STATE: State = State::Status;
75    const DIRECTION: Direction = Direction::Serverbound;
76    fn decode_raw(raw: &RawPacket) -> DecodeResult<Self> {
77        match raw.id {
78            id::PING_START => decode_exact(&raw.body).map(Self::PingStart),
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::PingStart(_) => id::PING_START,
86            Self::Ping(_) => id::PING,
87        }
88    }
89    fn name(&self) -> &'static str {
90        match *self {
91            Self::PingStart(_) => "ping_start",
92            Self::Ping(_) => "ping",
93        }
94    }
95    fn encode_body(&self, w: &mut BytesMut) -> EncodeResult {
96        match *self {
97            Self::PingStart(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::PING_START => Some("ping_start"),
104            id::PING => Some("ping"),
105            _ => None,
106        }
107    }
108}
109
110impl ServerboundStatusPacket {
111    /// All packet ids of this set, ascending.
112    pub const IDS: &'static [i32] = &[id::PING_START, 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::PING_START => Some(Self::PingStart(<PingStart as Generate>::generate(g))),
118            id::PING => Some(Self::Ping(<Ping as Generate>::generate(g))),
119            _ => None,
120        }
121    }
122}