#![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 SET_PROTOCOL: i32 = 0x00;
pub const LEGACY_SERVER_LIST_PING: i32 = 0xfe;
}
pub type SetProtocol = crate::defs::p47::handshaking::serverbound::SetProtocol<775>;
impl crate::packet::Packet for SetProtocol {
const ID: i32 = id::SET_PROTOCOL;
const NAME: &'static str = "set_protocol";
const STATE: State = State::Handshaking;
const DIRECTION: Direction = Direction::Serverbound;
}
impl From<SetProtocol> for ServerboundHandshakingPacket {
fn from(p: SetProtocol) -> Self {
Self::SetProtocol(p)
}
}
pub type LegacyServerListPing =
crate::defs::p47::handshaking::serverbound::LegacyServerListPing<775>;
impl crate::packet::Packet for LegacyServerListPing {
const ID: i32 = id::LEGACY_SERVER_LIST_PING;
const NAME: &'static str = "legacy_server_list_ping";
const STATE: State = State::Handshaking;
const DIRECTION: Direction = Direction::Serverbound;
}
impl From<LegacyServerListPing> for ServerboundHandshakingPacket {
fn from(p: LegacyServerListPing) -> Self {
Self::LegacyServerListPing(p)
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum ServerboundHandshakingPacket {
SetProtocol(SetProtocol),
LegacyServerListPing(LegacyServerListPing),
}
impl PacketSet for ServerboundHandshakingPacket {
const STATE: State = State::Handshaking;
const DIRECTION: Direction = Direction::Serverbound;
fn decode_raw(raw: &RawPacket) -> DecodeResult<Self> {
match raw.id {
id::SET_PROTOCOL => decode_exact(&raw.body).map(Self::SetProtocol),
id::LEGACY_SERVER_LIST_PING => decode_exact(&raw.body).map(Self::LegacyServerListPing),
other => Err(DecodeError::UnknownPacketId(other)),
}
}
fn id(&self) -> i32 {
match *self {
Self::SetProtocol(_) => id::SET_PROTOCOL,
Self::LegacyServerListPing(_) => id::LEGACY_SERVER_LIST_PING,
}
}
fn name(&self) -> &'static str {
match *self {
Self::SetProtocol(_) => "set_protocol",
Self::LegacyServerListPing(_) => "legacy_server_list_ping",
}
}
fn encode_body(&self, w: &mut BytesMut) -> EncodeResult {
match *self {
Self::SetProtocol(ref p) => p.encode(w),
Self::LegacyServerListPing(ref p) => p.encode(w),
}
}
fn name_of(id: i32) -> Option<&'static str> {
match id {
id::SET_PROTOCOL => Some("set_protocol"),
id::LEGACY_SERVER_LIST_PING => Some("legacy_server_list_ping"),
_ => None,
}
}
}
impl ServerboundHandshakingPacket {
pub const IDS: &'static [i32] = &[id::SET_PROTOCOL, id::LEGACY_SERVER_LIST_PING];
#[cfg(feature = "testgen")]
pub fn generate_by_id(id: i32, g: &mut Gen) -> Option<Self> {
match id {
id::SET_PROTOCOL => Some(Self::SetProtocol(<SetProtocol as Generate>::generate(g))),
id::LEGACY_SERVER_LIST_PING => Some(Self::LegacyServerListPing(
<LegacyServerListPing as Generate>::generate(g),
)),
_ => None,
}
}
}