ghast-protocol 0.4.3

Minecraft Java Edition network protocol for the ghast client library: generated per-version packets, framing, compression, encryption, NBT
Documentation
// @generated by ghast-codegen-protocol from PrismarineJS minecraft-data 3.119.0
// (data/pc/26.1/protocol.json + codegen/protocol/delta/776.json, Minecraft 26.2). Do not edit; run `cargo run -p ghast-codegen-protocol`.
// minecraft-data is MIT licensed, Copyright (c) 2015 PrismarineJS; see the NOTICE file
// in crates/ghast-protocol/src/generated/.

//! Serverbound packets of the login state.

#![allow(
    unused_imports,
    unused_variables,
    unused_mut,
    unused_parens,
    unused_braces,
    clippy::all,
    clippy::pedantic,
    non_camel_case_types,
    non_snake_case
)]
use crate::codec::{Decode, DecodeResult, Encode, EncodeResult, McWrite, Reader, decode_exact};
use crate::error::{DecodeError, EncodeError};
use crate::nbt::{AnonNbt, RawNbt};
use crate::packet::{Direction, PacketSet, RawPacket, State};
#[cfg(feature = "testgen")]
use crate::testgen::{Gen, Generate};
use crate::types::{BlockPos, ByteString, Holder, HolderSet, LpVec3, PositionLayout, Uuid};
use bytes::{BufMut, Bytes, BytesMut};

/// Packet ids.
pub mod id {
    /// `login_start`
    pub const LOGIN_START: i32 = 0x00;
    /// `encryption_begin`
    pub const ENCRYPTION_BEGIN: i32 = 0x01;
    /// `login_plugin_response`
    pub const LOGIN_PLUGIN_RESPONSE: i32 = 0x02;
    /// `login_acknowledged`
    pub const LOGIN_ACKNOWLEDGED: i32 = 0x03;
    /// `cookie_response`
    pub const COOKIE_RESPONSE: i32 = 0x04;
}

/// `login_start` (serverbound login, id 0x00).
pub type LoginStart = crate::defs::p775::login::serverbound::LoginStart<776>;
impl crate::packet::Packet for LoginStart {
    const ID: i32 = id::LOGIN_START;
    const NAME: &'static str = "login_start";
    const STATE: State = State::Login;
    const DIRECTION: Direction = Direction::Serverbound;
}
impl From<LoginStart> for ServerboundLoginPacket {
    fn from(p: LoginStart) -> Self {
        Self::LoginStart(p)
    }
}

/// `encryption_begin` (serverbound login, id 0x01).
pub type EncryptionBegin = crate::defs::p47::login::serverbound::EncryptionBegin<776>;
impl crate::packet::Packet for EncryptionBegin {
    const ID: i32 = id::ENCRYPTION_BEGIN;
    const NAME: &'static str = "encryption_begin";
    const STATE: State = State::Login;
    const DIRECTION: Direction = Direction::Serverbound;
}
impl From<EncryptionBegin> for ServerboundLoginPacket {
    fn from(p: EncryptionBegin) -> Self {
        Self::EncryptionBegin(p)
    }
}

/// `login_plugin_response` (serverbound login, id 0x02).
pub type LoginPluginResponse = crate::defs::p754::login::serverbound::LoginPluginResponse<776>;
impl crate::packet::Packet for LoginPluginResponse {
    const ID: i32 = id::LOGIN_PLUGIN_RESPONSE;
    const NAME: &'static str = "login_plugin_response";
    const STATE: State = State::Login;
    const DIRECTION: Direction = Direction::Serverbound;
}
impl From<LoginPluginResponse> for ServerboundLoginPacket {
    fn from(p: LoginPluginResponse) -> Self {
        Self::LoginPluginResponse(p)
    }
}

/// `login_acknowledged` (serverbound login, id 0x03).
pub type LoginAcknowledged = crate::defs::p775::login::serverbound::LoginAcknowledged<776>;
impl crate::packet::Packet for LoginAcknowledged {
    const ID: i32 = id::LOGIN_ACKNOWLEDGED;
    const NAME: &'static str = "login_acknowledged";
    const STATE: State = State::Login;
    const DIRECTION: Direction = Direction::Serverbound;
}
impl From<LoginAcknowledged> for ServerboundLoginPacket {
    fn from(p: LoginAcknowledged) -> Self {
        Self::LoginAcknowledged(p)
    }
}

/// `cookie_response` (serverbound login, id 0x04).
pub type CookieResponse = crate::defs::p775::login::serverbound::CookieResponse<776>;
impl crate::packet::Packet for CookieResponse {
    const ID: i32 = id::COOKIE_RESPONSE;
    const NAME: &'static str = "cookie_response";
    const STATE: State = State::Login;
    const DIRECTION: Direction = Direction::Serverbound;
}
impl From<CookieResponse> for ServerboundLoginPacket {
    fn from(p: CookieResponse) -> Self {
        Self::CookieResponse(p)
    }
}

/// Every Serverbound packet of the Login state.
#[derive(Debug, Clone, PartialEq)]
pub enum ServerboundLoginPacket {
    /// `login_start`
    LoginStart(LoginStart),
    /// `encryption_begin`
    EncryptionBegin(EncryptionBegin),
    /// `login_plugin_response`
    LoginPluginResponse(LoginPluginResponse),
    /// `login_acknowledged`
    LoginAcknowledged(LoginAcknowledged),
    /// `cookie_response`
    CookieResponse(CookieResponse),
}

impl PacketSet for ServerboundLoginPacket {
    const STATE: State = State::Login;
    const DIRECTION: Direction = Direction::Serverbound;
    fn decode_raw(raw: &RawPacket) -> DecodeResult<Self> {
        match raw.id {
            id::LOGIN_START => decode_exact(&raw.body).map(Self::LoginStart),
            id::ENCRYPTION_BEGIN => decode_exact(&raw.body).map(Self::EncryptionBegin),
            id::LOGIN_PLUGIN_RESPONSE => decode_exact(&raw.body).map(Self::LoginPluginResponse),
            id::LOGIN_ACKNOWLEDGED => decode_exact(&raw.body).map(Self::LoginAcknowledged),
            id::COOKIE_RESPONSE => decode_exact(&raw.body).map(Self::CookieResponse),
            other => Err(DecodeError::UnknownPacketId(other)),
        }
    }
    fn id(&self) -> i32 {
        match *self {
            Self::LoginStart(_) => id::LOGIN_START,
            Self::EncryptionBegin(_) => id::ENCRYPTION_BEGIN,
            Self::LoginPluginResponse(_) => id::LOGIN_PLUGIN_RESPONSE,
            Self::LoginAcknowledged(_) => id::LOGIN_ACKNOWLEDGED,
            Self::CookieResponse(_) => id::COOKIE_RESPONSE,
        }
    }
    fn name(&self) -> &'static str {
        match *self {
            Self::LoginStart(_) => "login_start",
            Self::EncryptionBegin(_) => "encryption_begin",
            Self::LoginPluginResponse(_) => "login_plugin_response",
            Self::LoginAcknowledged(_) => "login_acknowledged",
            Self::CookieResponse(_) => "cookie_response",
        }
    }
    fn encode_body(&self, w: &mut BytesMut) -> EncodeResult {
        match *self {
            Self::LoginStart(ref p) => p.encode(w),
            Self::EncryptionBegin(ref p) => p.encode(w),
            Self::LoginPluginResponse(ref p) => p.encode(w),
            Self::LoginAcknowledged(ref p) => p.encode(w),
            Self::CookieResponse(ref p) => p.encode(w),
        }
    }
    fn name_of(id: i32) -> Option<&'static str> {
        match id {
            id::LOGIN_START => Some("login_start"),
            id::ENCRYPTION_BEGIN => Some("encryption_begin"),
            id::LOGIN_PLUGIN_RESPONSE => Some("login_plugin_response"),
            id::LOGIN_ACKNOWLEDGED => Some("login_acknowledged"),
            id::COOKIE_RESPONSE => Some("cookie_response"),
            _ => None,
        }
    }
}

impl ServerboundLoginPacket {
    /// All packet ids of this set, ascending.
    pub const IDS: &'static [i32] = &[
        id::LOGIN_START,
        id::ENCRYPTION_BEGIN,
        id::LOGIN_PLUGIN_RESPONSE,
        id::LOGIN_ACKNOWLEDGED,
        id::COOKIE_RESPONSE,
    ];
    /// Generates a random packet with the given id (test support).
    #[cfg(feature = "testgen")]
    pub fn generate_by_id(id: i32, g: &mut Gen) -> Option<Self> {
        match id {
            id::LOGIN_START => Some(Self::LoginStart(<LoginStart as Generate>::generate(g))),
            id::ENCRYPTION_BEGIN => Some(Self::EncryptionBegin(
                <EncryptionBegin as Generate>::generate(g),
            )),
            id::LOGIN_PLUGIN_RESPONSE => Some(Self::LoginPluginResponse(
                <LoginPluginResponse as Generate>::generate(g),
            )),
            id::LOGIN_ACKNOWLEDGED => Some(Self::LoginAcknowledged(
                <LoginAcknowledged as Generate>::generate(g),
            )),
            id::COOKIE_RESPONSE => Some(Self::CookieResponse(
                <CookieResponse as Generate>::generate(g),
            )),
            _ => None,
        }
    }
}