ghast-protocol 0.4.2

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 configuration 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 {
    /// `settings`
    pub const SETTINGS: i32 = 0x00;
    /// `cookie_response`
    pub const COOKIE_RESPONSE: i32 = 0x01;
    /// `custom_payload`
    pub const CUSTOM_PAYLOAD: i32 = 0x02;
    /// `finish_configuration`
    pub const FINISH_CONFIGURATION: i32 = 0x03;
    /// `keep_alive`
    pub const KEEP_ALIVE: i32 = 0x04;
    /// `pong`
    pub const PONG: i32 = 0x05;
    /// `resource_pack_receive`
    pub const RESOURCE_PACK_RECEIVE: i32 = 0x06;
    /// `select_known_packs`
    pub const SELECT_KNOWN_PACKS: i32 = 0x07;
    /// `custom_click_action`
    pub const CUSTOM_CLICK_ACTION: i32 = 0x08;
    /// `accept_code_of_conduct`
    pub const ACCEPT_CODE_OF_CONDUCT: i32 = 0x09;
}

pub use crate::defs::p775::configuration::serverbound::SelectKnownPacksPacks;
pub use crate::defs::p775::configuration::serverbound::SettingsParticleStatus;

/// `settings` (serverbound configuration, id 0x00).
pub type Settings = crate::defs::p775::configuration::serverbound::Settings<776>;
impl crate::packet::Packet for Settings {
    const ID: i32 = id::SETTINGS;
    const NAME: &'static str = "settings";
    const STATE: State = State::Configuration;
    const DIRECTION: Direction = Direction::Serverbound;
}
impl From<Settings> for ServerboundConfigurationPacket {
    fn from(p: Settings) -> Self {
        Self::Settings(p)
    }
}

/// `cookie_response` (serverbound configuration, id 0x01).
pub type CookieResponse = crate::defs::p775::configuration::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::Configuration;
    const DIRECTION: Direction = Direction::Serverbound;
}
impl From<CookieResponse> for ServerboundConfigurationPacket {
    fn from(p: CookieResponse) -> Self {
        Self::CookieResponse(p)
    }
}

/// `custom_payload` (serverbound configuration, id 0x02).
pub type CustomPayload = crate::defs::p775::configuration::serverbound::CustomPayload<776>;
impl crate::packet::Packet for CustomPayload {
    const ID: i32 = id::CUSTOM_PAYLOAD;
    const NAME: &'static str = "custom_payload";
    const STATE: State = State::Configuration;
    const DIRECTION: Direction = Direction::Serverbound;
}
impl From<CustomPayload> for ServerboundConfigurationPacket {
    fn from(p: CustomPayload) -> Self {
        Self::CustomPayload(p)
    }
}

/// `finish_configuration` (serverbound configuration, id 0x03).
pub type FinishConfiguration =
    crate::defs::p775::configuration::serverbound::FinishConfiguration<776>;
impl crate::packet::Packet for FinishConfiguration {
    const ID: i32 = id::FINISH_CONFIGURATION;
    const NAME: &'static str = "finish_configuration";
    const STATE: State = State::Configuration;
    const DIRECTION: Direction = Direction::Serverbound;
}
impl From<FinishConfiguration> for ServerboundConfigurationPacket {
    fn from(p: FinishConfiguration) -> Self {
        Self::FinishConfiguration(p)
    }
}

/// `keep_alive` (serverbound configuration, id 0x04).
pub type KeepAlive = crate::defs::p775::configuration::serverbound::KeepAlive<776>;
impl crate::packet::Packet for KeepAlive {
    const ID: i32 = id::KEEP_ALIVE;
    const NAME: &'static str = "keep_alive";
    const STATE: State = State::Configuration;
    const DIRECTION: Direction = Direction::Serverbound;
}
impl From<KeepAlive> for ServerboundConfigurationPacket {
    fn from(p: KeepAlive) -> Self {
        Self::KeepAlive(p)
    }
}

/// `pong` (serverbound configuration, id 0x05).
pub type Pong = crate::defs::p775::configuration::serverbound::Pong<776>;
impl crate::packet::Packet for Pong {
    const ID: i32 = id::PONG;
    const NAME: &'static str = "pong";
    const STATE: State = State::Configuration;
    const DIRECTION: Direction = Direction::Serverbound;
}
impl From<Pong> for ServerboundConfigurationPacket {
    fn from(p: Pong) -> Self {
        Self::Pong(p)
    }
}

/// `resource_pack_receive` (serverbound configuration, id 0x06).
pub type ResourcePackReceive =
    crate::defs::p775::configuration::serverbound::ResourcePackReceive<776>;
impl crate::packet::Packet for ResourcePackReceive {
    const ID: i32 = id::RESOURCE_PACK_RECEIVE;
    const NAME: &'static str = "resource_pack_receive";
    const STATE: State = State::Configuration;
    const DIRECTION: Direction = Direction::Serverbound;
}
impl From<ResourcePackReceive> for ServerboundConfigurationPacket {
    fn from(p: ResourcePackReceive) -> Self {
        Self::ResourcePackReceive(p)
    }
}

/// `select_known_packs` (serverbound configuration, id 0x07).
pub type SelectKnownPacks = crate::defs::p775::configuration::serverbound::SelectKnownPacks<776>;
impl crate::packet::Packet for SelectKnownPacks {
    const ID: i32 = id::SELECT_KNOWN_PACKS;
    const NAME: &'static str = "select_known_packs";
    const STATE: State = State::Configuration;
    const DIRECTION: Direction = Direction::Serverbound;
}
impl From<SelectKnownPacks> for ServerboundConfigurationPacket {
    fn from(p: SelectKnownPacks) -> Self {
        Self::SelectKnownPacks(p)
    }
}

/// `custom_click_action` (serverbound configuration, id 0x08).
pub type CustomClickAction = crate::defs::p775::configuration::serverbound::CustomClickAction<776>;
impl crate::packet::Packet for CustomClickAction {
    const ID: i32 = id::CUSTOM_CLICK_ACTION;
    const NAME: &'static str = "custom_click_action";
    const STATE: State = State::Configuration;
    const DIRECTION: Direction = Direction::Serverbound;
}
impl From<CustomClickAction> for ServerboundConfigurationPacket {
    fn from(p: CustomClickAction) -> Self {
        Self::CustomClickAction(p)
    }
}

/// `accept_code_of_conduct` (serverbound configuration, id 0x09).
pub type AcceptCodeOfConduct =
    crate::defs::p775::configuration::serverbound::AcceptCodeOfConduct<776>;
impl crate::packet::Packet for AcceptCodeOfConduct {
    const ID: i32 = id::ACCEPT_CODE_OF_CONDUCT;
    const NAME: &'static str = "accept_code_of_conduct";
    const STATE: State = State::Configuration;
    const DIRECTION: Direction = Direction::Serverbound;
}
impl From<AcceptCodeOfConduct> for ServerboundConfigurationPacket {
    fn from(p: AcceptCodeOfConduct) -> Self {
        Self::AcceptCodeOfConduct(p)
    }
}

/// Every Serverbound packet of the Configuration state.
#[derive(Debug, Clone, PartialEq)]
pub enum ServerboundConfigurationPacket {
    /// `settings`
    Settings(Settings),
    /// `cookie_response`
    CookieResponse(CookieResponse),
    /// `custom_payload`
    CustomPayload(CustomPayload),
    /// `finish_configuration`
    FinishConfiguration(FinishConfiguration),
    /// `keep_alive`
    KeepAlive(KeepAlive),
    /// `pong`
    Pong(Pong),
    /// `resource_pack_receive`
    ResourcePackReceive(ResourcePackReceive),
    /// `select_known_packs`
    SelectKnownPacks(SelectKnownPacks),
    /// `custom_click_action`
    CustomClickAction(CustomClickAction),
    /// `accept_code_of_conduct`
    AcceptCodeOfConduct(AcceptCodeOfConduct),
}

impl PacketSet for ServerboundConfigurationPacket {
    const STATE: State = State::Configuration;
    const DIRECTION: Direction = Direction::Serverbound;
    fn decode_raw(raw: &RawPacket) -> DecodeResult<Self> {
        match raw.id {
            id::SETTINGS => decode_exact(&raw.body).map(Self::Settings),
            id::COOKIE_RESPONSE => decode_exact(&raw.body).map(Self::CookieResponse),
            id::CUSTOM_PAYLOAD => decode_exact(&raw.body).map(Self::CustomPayload),
            id::FINISH_CONFIGURATION => decode_exact(&raw.body).map(Self::FinishConfiguration),
            id::KEEP_ALIVE => decode_exact(&raw.body).map(Self::KeepAlive),
            id::PONG => decode_exact(&raw.body).map(Self::Pong),
            id::RESOURCE_PACK_RECEIVE => decode_exact(&raw.body).map(Self::ResourcePackReceive),
            id::SELECT_KNOWN_PACKS => decode_exact(&raw.body).map(Self::SelectKnownPacks),
            id::CUSTOM_CLICK_ACTION => decode_exact(&raw.body).map(Self::CustomClickAction),
            id::ACCEPT_CODE_OF_CONDUCT => decode_exact(&raw.body).map(Self::AcceptCodeOfConduct),
            other => Err(DecodeError::UnknownPacketId(other)),
        }
    }
    fn id(&self) -> i32 {
        match *self {
            Self::Settings(_) => id::SETTINGS,
            Self::CookieResponse(_) => id::COOKIE_RESPONSE,
            Self::CustomPayload(_) => id::CUSTOM_PAYLOAD,
            Self::FinishConfiguration(_) => id::FINISH_CONFIGURATION,
            Self::KeepAlive(_) => id::KEEP_ALIVE,
            Self::Pong(_) => id::PONG,
            Self::ResourcePackReceive(_) => id::RESOURCE_PACK_RECEIVE,
            Self::SelectKnownPacks(_) => id::SELECT_KNOWN_PACKS,
            Self::CustomClickAction(_) => id::CUSTOM_CLICK_ACTION,
            Self::AcceptCodeOfConduct(_) => id::ACCEPT_CODE_OF_CONDUCT,
        }
    }
    fn name(&self) -> &'static str {
        match *self {
            Self::Settings(_) => "settings",
            Self::CookieResponse(_) => "cookie_response",
            Self::CustomPayload(_) => "custom_payload",
            Self::FinishConfiguration(_) => "finish_configuration",
            Self::KeepAlive(_) => "keep_alive",
            Self::Pong(_) => "pong",
            Self::ResourcePackReceive(_) => "resource_pack_receive",
            Self::SelectKnownPacks(_) => "select_known_packs",
            Self::CustomClickAction(_) => "custom_click_action",
            Self::AcceptCodeOfConduct(_) => "accept_code_of_conduct",
        }
    }
    fn encode_body(&self, w: &mut BytesMut) -> EncodeResult {
        match *self {
            Self::Settings(ref p) => p.encode(w),
            Self::CookieResponse(ref p) => p.encode(w),
            Self::CustomPayload(ref p) => p.encode(w),
            Self::FinishConfiguration(ref p) => p.encode(w),
            Self::KeepAlive(ref p) => p.encode(w),
            Self::Pong(ref p) => p.encode(w),
            Self::ResourcePackReceive(ref p) => p.encode(w),
            Self::SelectKnownPacks(ref p) => p.encode(w),
            Self::CustomClickAction(ref p) => p.encode(w),
            Self::AcceptCodeOfConduct(ref p) => p.encode(w),
        }
    }
    fn name_of(id: i32) -> Option<&'static str> {
        match id {
            id::SETTINGS => Some("settings"),
            id::COOKIE_RESPONSE => Some("cookie_response"),
            id::CUSTOM_PAYLOAD => Some("custom_payload"),
            id::FINISH_CONFIGURATION => Some("finish_configuration"),
            id::KEEP_ALIVE => Some("keep_alive"),
            id::PONG => Some("pong"),
            id::RESOURCE_PACK_RECEIVE => Some("resource_pack_receive"),
            id::SELECT_KNOWN_PACKS => Some("select_known_packs"),
            id::CUSTOM_CLICK_ACTION => Some("custom_click_action"),
            id::ACCEPT_CODE_OF_CONDUCT => Some("accept_code_of_conduct"),
            _ => None,
        }
    }
}

impl ServerboundConfigurationPacket {
    /// All packet ids of this set, ascending.
    pub const IDS: &'static [i32] = &[
        id::SETTINGS,
        id::COOKIE_RESPONSE,
        id::CUSTOM_PAYLOAD,
        id::FINISH_CONFIGURATION,
        id::KEEP_ALIVE,
        id::PONG,
        id::RESOURCE_PACK_RECEIVE,
        id::SELECT_KNOWN_PACKS,
        id::CUSTOM_CLICK_ACTION,
        id::ACCEPT_CODE_OF_CONDUCT,
    ];
    /// 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::SETTINGS => Some(Self::Settings(<Settings as Generate>::generate(g))),
            id::COOKIE_RESPONSE => Some(Self::CookieResponse(
                <CookieResponse as Generate>::generate(g),
            )),
            id::CUSTOM_PAYLOAD => Some(Self::CustomPayload(<CustomPayload as Generate>::generate(
                g,
            ))),
            id::FINISH_CONFIGURATION => Some(Self::FinishConfiguration(
                <FinishConfiguration as Generate>::generate(g),
            )),
            id::KEEP_ALIVE => Some(Self::KeepAlive(<KeepAlive as Generate>::generate(g))),
            id::PONG => Some(Self::Pong(<Pong as Generate>::generate(g))),
            id::RESOURCE_PACK_RECEIVE => Some(Self::ResourcePackReceive(
                <ResourcePackReceive as Generate>::generate(g),
            )),
            id::SELECT_KNOWN_PACKS => Some(Self::SelectKnownPacks(
                <SelectKnownPacks as Generate>::generate(g),
            )),
            id::CUSTOM_CLICK_ACTION => Some(Self::CustomClickAction(
                <CustomClickAction as Generate>::generate(g),
            )),
            id::ACCEPT_CODE_OF_CONDUCT => Some(Self::AcceptCodeOfConduct(
                <AcceptCodeOfConduct as Generate>::generate(g),
            )),
            _ => None,
        }
    }
}