#![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};
pub mod id {
pub const DISCONNECT: i32 = 0x00;
pub const ENCRYPTION_BEGIN: i32 = 0x01;
pub const SUCCESS: i32 = 0x02;
pub const COMPRESS: i32 = 0x03;
pub const LOGIN_PLUGIN_REQUEST: i32 = 0x04;
}
pub type Disconnect = crate::defs::p47::login::clientbound::Disconnect<754>;
impl crate::packet::Packet for Disconnect {
const ID: i32 = id::DISCONNECT;
const NAME: &'static str = "disconnect";
const STATE: State = State::Login;
const DIRECTION: Direction = Direction::Clientbound;
}
impl From<Disconnect> for ClientboundLoginPacket {
fn from(p: Disconnect) -> Self {
Self::Disconnect(p)
}
}
pub type EncryptionBegin = crate::defs::p47::login::clientbound::EncryptionBegin<754>;
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::Clientbound;
}
impl From<EncryptionBegin> for ClientboundLoginPacket {
fn from(p: EncryptionBegin) -> Self {
Self::EncryptionBegin(p)
}
}
pub type Success = crate::defs::p754::login::clientbound::Success<754>;
impl crate::packet::Packet for Success {
const ID: i32 = id::SUCCESS;
const NAME: &'static str = "success";
const STATE: State = State::Login;
const DIRECTION: Direction = Direction::Clientbound;
}
impl From<Success> for ClientboundLoginPacket {
fn from(p: Success) -> Self {
Self::Success(p)
}
}
pub type Compress = crate::defs::p47::login::clientbound::Compress<754>;
impl crate::packet::Packet for Compress {
const ID: i32 = id::COMPRESS;
const NAME: &'static str = "compress";
const STATE: State = State::Login;
const DIRECTION: Direction = Direction::Clientbound;
}
impl From<Compress> for ClientboundLoginPacket {
fn from(p: Compress) -> Self {
Self::Compress(p)
}
}
pub type LoginPluginRequest = crate::defs::p754::login::clientbound::LoginPluginRequest<754>;
impl crate::packet::Packet for LoginPluginRequest {
const ID: i32 = id::LOGIN_PLUGIN_REQUEST;
const NAME: &'static str = "login_plugin_request";
const STATE: State = State::Login;
const DIRECTION: Direction = Direction::Clientbound;
}
impl From<LoginPluginRequest> for ClientboundLoginPacket {
fn from(p: LoginPluginRequest) -> Self {
Self::LoginPluginRequest(p)
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum ClientboundLoginPacket {
Disconnect(Disconnect),
EncryptionBegin(EncryptionBegin),
Success(Success),
Compress(Compress),
LoginPluginRequest(LoginPluginRequest),
}
impl PacketSet for ClientboundLoginPacket {
const STATE: State = State::Login;
const DIRECTION: Direction = Direction::Clientbound;
fn decode_raw(raw: &RawPacket) -> DecodeResult<Self> {
match raw.id {
id::DISCONNECT => decode_exact(&raw.body).map(Self::Disconnect),
id::ENCRYPTION_BEGIN => decode_exact(&raw.body).map(Self::EncryptionBegin),
id::SUCCESS => decode_exact(&raw.body).map(Self::Success),
id::COMPRESS => decode_exact(&raw.body).map(Self::Compress),
id::LOGIN_PLUGIN_REQUEST => decode_exact(&raw.body).map(Self::LoginPluginRequest),
other => Err(DecodeError::UnknownPacketId(other)),
}
}
fn id(&self) -> i32 {
match *self {
Self::Disconnect(_) => id::DISCONNECT,
Self::EncryptionBegin(_) => id::ENCRYPTION_BEGIN,
Self::Success(_) => id::SUCCESS,
Self::Compress(_) => id::COMPRESS,
Self::LoginPluginRequest(_) => id::LOGIN_PLUGIN_REQUEST,
}
}
fn name(&self) -> &'static str {
match *self {
Self::Disconnect(_) => "disconnect",
Self::EncryptionBegin(_) => "encryption_begin",
Self::Success(_) => "success",
Self::Compress(_) => "compress",
Self::LoginPluginRequest(_) => "login_plugin_request",
}
}
fn encode_body(&self, w: &mut BytesMut) -> EncodeResult {
match *self {
Self::Disconnect(ref p) => p.encode(w),
Self::EncryptionBegin(ref p) => p.encode(w),
Self::Success(ref p) => p.encode(w),
Self::Compress(ref p) => p.encode(w),
Self::LoginPluginRequest(ref p) => p.encode(w),
}
}
fn name_of(id: i32) -> Option<&'static str> {
match id {
id::DISCONNECT => Some("disconnect"),
id::ENCRYPTION_BEGIN => Some("encryption_begin"),
id::SUCCESS => Some("success"),
id::COMPRESS => Some("compress"),
id::LOGIN_PLUGIN_REQUEST => Some("login_plugin_request"),
_ => None,
}
}
}
impl ClientboundLoginPacket {
pub const IDS: &'static [i32] = &[
id::DISCONNECT,
id::ENCRYPTION_BEGIN,
id::SUCCESS,
id::COMPRESS,
id::LOGIN_PLUGIN_REQUEST,
];
#[cfg(feature = "testgen")]
pub fn generate_by_id(id: i32, g: &mut Gen) -> Option<Self> {
match id {
id::DISCONNECT => Some(Self::Disconnect(<Disconnect as Generate>::generate(g))),
id::ENCRYPTION_BEGIN => Some(Self::EncryptionBegin(
<EncryptionBegin as Generate>::generate(g),
)),
id::SUCCESS => Some(Self::Success(<Success as Generate>::generate(g))),
id::COMPRESS => Some(Self::Compress(<Compress as Generate>::generate(g))),
id::LOGIN_PLUGIN_REQUEST => Some(Self::LoginPluginRequest(
<LoginPluginRequest as Generate>::generate(g),
)),
_ => None,
}
}
}