mirror of
https://github.com/italicsjenga/valence.git
synced 2024-12-23 14:31:30 +11:00
Tweak packet macros
This commit is contained in:
parent
02fe0bae3b
commit
7fac522a8e
|
@ -54,7 +54,7 @@ pub trait DecodePacket: Sized + fmt::Debug {
|
|||
macro_rules! def_struct {
|
||||
(
|
||||
$(#[$struct_attrs:meta])*
|
||||
$name:ident $($id:literal)? {
|
||||
$name:ident {
|
||||
$(
|
||||
$(#[$field_attrs:meta])*
|
||||
$field:ident: $typ:ty
|
||||
|
@ -95,36 +95,6 @@ macro_rules! def_struct {
|
|||
}
|
||||
}
|
||||
|
||||
$(
|
||||
impl EncodePacket for $name {
|
||||
fn encode_packet(&self, w: &mut impl Write) -> anyhow::Result<()> {
|
||||
VarInt($id)
|
||||
.encode(w)
|
||||
.context(concat!("failed to write packet ID for `", stringify!($name), "`"))?;
|
||||
self.encode(w)
|
||||
}
|
||||
}
|
||||
|
||||
impl DecodePacket for $name {
|
||||
fn decode_packet(r: &mut impl Read) -> anyhow::Result<Self> {
|
||||
let VarInt(packet_id) = VarInt::decode(r)
|
||||
.context(concat!("failed to read packet ID for `", stringify!($name), "`"))?;
|
||||
|
||||
ensure!(
|
||||
$id == packet_id,
|
||||
concat!("bad packet ID for `", stringify!($name), "` (expected {:#04x}, got {:#04x})"),
|
||||
$id,
|
||||
packet_id
|
||||
);
|
||||
Self::decode(r)
|
||||
}
|
||||
}
|
||||
|
||||
impl $name {
|
||||
pub const PACKET_ID: i32 = $id;
|
||||
}
|
||||
)*
|
||||
|
||||
// TODO: https://github.com/rust-lang/rust/issues/48214
|
||||
//impl Copy for $name
|
||||
//where
|
||||
|
@ -145,7 +115,7 @@ macro_rules! def_struct {
|
|||
macro_rules! def_enum {
|
||||
(
|
||||
$(#[$enum_attrs:meta])*
|
||||
$name:ident $($id:literal)?: $tag_ty:ty {
|
||||
$name:ident: $tag_ty:ty {
|
||||
$(
|
||||
$(#[$variant_attrs:meta])*
|
||||
$variant:ident$(: $typ:ty)? = $lit:literal
|
||||
|
@ -203,36 +173,6 @@ macro_rules! def_enum {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
$(
|
||||
impl EncodePacket for $name {
|
||||
fn encode_packet(&self, w: &mut impl Write) -> anyhow::Result<()> {
|
||||
VarInt($id)
|
||||
.encode(w)
|
||||
.context(concat!("failed to write packet ID for `", stringify!($name), "`"))?;
|
||||
self.encode(w)
|
||||
}
|
||||
}
|
||||
|
||||
impl DecodePacket for $name {
|
||||
fn decode_packet(r: &mut impl Read) -> anyhow::Result<Self> {
|
||||
let VarInt(packet_id) = VarInt::decode(r)
|
||||
.context(concat!("failed to read packet ID for `", stringify!($name), "`"))?;
|
||||
|
||||
ensure!(
|
||||
$id == packet_id,
|
||||
concat!("bad packet ID for `", stringify!($name), "` (expected {:#04X}, got {:#04X})"),
|
||||
$id,
|
||||
packet_id
|
||||
);
|
||||
Self::decode(r)
|
||||
}
|
||||
}
|
||||
|
||||
impl $name {
|
||||
pub const PACKET_ID: i32 = $id;
|
||||
}
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -336,7 +276,7 @@ macro_rules! def_packet_group {
|
|||
(
|
||||
$(#[$attrs:meta])*
|
||||
$group_name:ident {
|
||||
$($packet:ident),* $(,)?
|
||||
$($packet:ident = $id:literal),* $(,)?
|
||||
}
|
||||
) => {
|
||||
#[derive(Clone)]
|
||||
|
@ -351,6 +291,26 @@ macro_rules! def_packet_group {
|
|||
Self::$packet(p)
|
||||
}
|
||||
}
|
||||
|
||||
impl EncodePacket for $packet {
|
||||
fn encode_packet(&self, w: &mut impl Write) -> anyhow::Result<()> {
|
||||
VarInt($id).encode(w).context("failed to write packet ID")?;
|
||||
self.encode(w)
|
||||
}
|
||||
}
|
||||
|
||||
impl DecodePacket for $packet {
|
||||
fn decode_packet(r: &mut impl Read) -> anyhow::Result<Self> {
|
||||
let packet_id = VarInt::decode(r).context("failed to read packet ID")?.0;
|
||||
|
||||
ensure!(
|
||||
$id == packet_id,
|
||||
"bad packet ID (expected {}, got {packet_id}",
|
||||
$id
|
||||
);
|
||||
Self::decode(r)
|
||||
}
|
||||
}
|
||||
)*
|
||||
|
||||
impl DecodePacket for $group_name {
|
||||
|
@ -360,12 +320,12 @@ macro_rules! def_packet_group {
|
|||
|
||||
match packet_id {
|
||||
$(
|
||||
$packet::PACKET_ID => {
|
||||
$id => {
|
||||
let pkt = $packet::decode(r)?;
|
||||
Ok(Self::$packet(pkt))
|
||||
}
|
||||
)*
|
||||
id => bail!(concat!("unknown ", stringify!($group_name), " packet ID {:#04x}"), id),
|
||||
id => bail!(concat!("unknown ", stringify!($group_name), " packet ID {}"), id),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -375,7 +335,7 @@ macro_rules! def_packet_group {
|
|||
match self {
|
||||
$(
|
||||
Self::$packet(pkt) => {
|
||||
VarInt($packet::PACKET_ID)
|
||||
VarInt($id)
|
||||
.encode(w)
|
||||
.context(concat!(
|
||||
"failed to write ",
|
||||
|
|
|
@ -6,7 +6,7 @@ pub mod handshake {
|
|||
use super::*;
|
||||
|
||||
def_struct! {
|
||||
Handshake 0x00 {
|
||||
Handshake {
|
||||
protocol_version: VarInt,
|
||||
server_adddress: BoundedString<0, 255>,
|
||||
server_port: u16,
|
||||
|
@ -20,34 +20,47 @@ pub mod handshake {
|
|||
Login = 2,
|
||||
}
|
||||
}
|
||||
|
||||
def_packet_group! {
|
||||
C2sHandshakePacket {
|
||||
Handshake = 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod status {
|
||||
use super::*;
|
||||
|
||||
def_struct! {
|
||||
QueryRequest 0x00 {}
|
||||
QueryRequest {}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
QueryPing 0x01 {
|
||||
QueryPing {
|
||||
payload: u64
|
||||
}
|
||||
}
|
||||
|
||||
def_packet_group! {
|
||||
C2sStatusPacket {
|
||||
QueryRequest = 0,
|
||||
QueryPing = 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod login {
|
||||
use super::*;
|
||||
|
||||
def_struct! {
|
||||
LoginStart 0x00 {
|
||||
LoginStart {
|
||||
username: BoundedString<3, 16>,
|
||||
sig_data: Option<SignatureData>,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
EncryptionResponse 0x01 {
|
||||
EncryptionResponse {
|
||||
shared_secret: BoundedArray<u8, 16, 128>,
|
||||
token_or_sig: VerifyTokenOrMsgSig,
|
||||
}
|
||||
|
@ -68,7 +81,7 @@ pub mod login {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
LoginPluginResponse 0x02 {
|
||||
LoginPluginResponse {
|
||||
message_id: VarInt,
|
||||
data: Option<RawBytes>,
|
||||
}
|
||||
|
@ -76,9 +89,9 @@ pub mod login {
|
|||
|
||||
def_packet_group! {
|
||||
C2sLoginPacket {
|
||||
LoginStart,
|
||||
EncryptionResponse,
|
||||
LoginPluginResponse,
|
||||
LoginStart = 0,
|
||||
EncryptionResponse = 1,
|
||||
LoginPluginResponse = 2,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -87,20 +100,20 @@ pub mod play {
|
|||
use super::super::*;
|
||||
|
||||
def_struct! {
|
||||
TeleportConfirm 0x00 {
|
||||
TeleportConfirm {
|
||||
teleport_id: VarInt
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
QueryBlockNbt 0x01 {
|
||||
QueryBlockNbt {
|
||||
transaction_id: VarInt,
|
||||
location: BlockPos,
|
||||
}
|
||||
}
|
||||
|
||||
def_enum! {
|
||||
UpdateDifficulty 0x02: i8 {
|
||||
UpdateDifficulty: i8 {
|
||||
Peaceful = 0,
|
||||
Easy = 1,
|
||||
Normal = 2,
|
||||
|
@ -109,7 +122,7 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
CommandExecution 0x03 {
|
||||
CommandExecution {
|
||||
command: String, // TODO: bounded?
|
||||
// TODO: timestamp, arg signatures
|
||||
signed_preview: bool,
|
||||
|
@ -117,7 +130,7 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
ChatMessage 0x04 {
|
||||
ChatMessage {
|
||||
message: BoundedString<0, 256>,
|
||||
timestamp: u64,
|
||||
salt: u64,
|
||||
|
@ -127,14 +140,14 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
RequestChatPreview 0x05 {
|
||||
RequestChatPreview {
|
||||
query: i32, // TODO: is this an i32 or a varint?
|
||||
message: BoundedString<0, 256>,
|
||||
}
|
||||
}
|
||||
|
||||
def_enum! {
|
||||
ClientStatus 0x06: VarInt {
|
||||
ClientStatus: VarInt {
|
||||
/// Sent when ready to complete login and ready to respawn after death.
|
||||
PerformRespawn = 0,
|
||||
/// Sent when the statistics menu is opened.
|
||||
|
@ -143,7 +156,7 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
ClientSettings 0x07 {
|
||||
ClientSettings {
|
||||
/// e.g. en_US
|
||||
locale: BoundedString<0, 16>,
|
||||
/// Client-side render distance in chunks.
|
||||
|
@ -189,7 +202,7 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
RequestCommandCompletion 0x08 {
|
||||
RequestCommandCompletion {
|
||||
transaction_id: VarInt,
|
||||
/// Text behind the cursor without the '/'.
|
||||
text: BoundedString<0, 32500>
|
||||
|
@ -197,33 +210,33 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
ButtonClick 0x09 {
|
||||
ButtonClick {
|
||||
window_id: i8,
|
||||
button_id: i8,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
ClickSlot 0x0a {
|
||||
ClickSlot {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
CloseHandledScreen 0x0b {
|
||||
CloseHandledScreen {
|
||||
window_id: u8,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
CustomPayload 0x0c {
|
||||
CustomPayload {
|
||||
channel: Ident,
|
||||
data: RawBytes,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
BookUpdate 0x0d {
|
||||
BookUpdate {
|
||||
slot: VarInt,
|
||||
entries: Vec<String>,
|
||||
title: Option<String>,
|
||||
|
@ -231,14 +244,14 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
QueryEntityNbt 0x0e {
|
||||
QueryEntityNbt {
|
||||
transaction_id: VarInt,
|
||||
entity_id: VarInt,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
PlayerInteractEntity 0x0f {
|
||||
PlayerInteractEntity {
|
||||
entity_id: VarInt,
|
||||
kind: InteractKind,
|
||||
sneaking: bool,
|
||||
|
@ -262,7 +275,7 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
JigsawGenerate 0x10 {
|
||||
JigsawGenerate {
|
||||
location: BlockPos,
|
||||
levels: VarInt,
|
||||
keep_jigsaws: bool,
|
||||
|
@ -270,26 +283,26 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
KeepAlive 0x11 {
|
||||
KeepAlive {
|
||||
id: i64,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
UpdateDifficultyLock 0x12 {
|
||||
UpdateDifficultyLock {
|
||||
locked: bool
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
MovePlayerPosition 0x13 {
|
||||
MovePlayerPosition {
|
||||
position: Vec3<f64>,
|
||||
on_ground: bool,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
MovePlayerPositionAndRotation 0x14 {
|
||||
MovePlayerPositionAndRotation {
|
||||
// Absolute position
|
||||
position: Vec3<f64>,
|
||||
/// Absolute rotation on X axis in degrees.
|
||||
|
@ -301,7 +314,7 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
MovePlayerRotation 0x15 {
|
||||
MovePlayerRotation {
|
||||
/// Absolute rotation on X axis in degrees.
|
||||
yaw: f32,
|
||||
/// Absolute rotation on Y axis in degrees.
|
||||
|
@ -311,13 +324,13 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
MovePlayerOnGround 0x16 {
|
||||
MovePlayerOnGround {
|
||||
on_ground: bool
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
MoveVehicle 0x17 {
|
||||
MoveVehicle {
|
||||
/// Absolute position
|
||||
position: Vec3<f64>,
|
||||
/// Degrees
|
||||
|
@ -328,20 +341,20 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
BoatPaddleState 0x18 {
|
||||
BoatPaddleState {
|
||||
left_paddle_turning: bool,
|
||||
right_paddle_turning: bool,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
PickFromInventory 0x19 {
|
||||
PickFromInventory {
|
||||
slot_to_use: VarInt,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
CraftRequest 0x1a {
|
||||
CraftRequest {
|
||||
window_id: i8,
|
||||
recipe: Ident,
|
||||
make_all: bool,
|
||||
|
@ -349,14 +362,14 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_enum! {
|
||||
UpdatePlayerAbilities 0x1b: i8 {
|
||||
UpdatePlayerAbilities: i8 {
|
||||
NotFlying = 0,
|
||||
Flying = 0b10,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
PlayerAction 0x1c {
|
||||
PlayerAction {
|
||||
status: DiggingStatus,
|
||||
location: BlockPos,
|
||||
face: BlockFace,
|
||||
|
@ -395,7 +408,7 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
PlayerCommand 0x1d {
|
||||
PlayerCommand {
|
||||
entity_id: VarInt,
|
||||
action_id: PlayerCommandId,
|
||||
jump_boost: BoundedInt<VarInt, 0, 100>,
|
||||
|
@ -417,7 +430,7 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
PlayerInput 0x1e {
|
||||
PlayerInput {
|
||||
sideways: f32,
|
||||
forward: f32,
|
||||
flags: PlayerInputFlags,
|
||||
|
@ -432,13 +445,13 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
PlayPong 0x1f {
|
||||
PlayPong {
|
||||
id: i32,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
RecipeBookChangeSettings 0x20 {
|
||||
RecipeBookChangeSettings {
|
||||
book_id: RecipeBookId,
|
||||
book_open: bool,
|
||||
filter_active: bool,
|
||||
|
@ -455,19 +468,19 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
RecipeBookSeenRecipe 0x21 {
|
||||
RecipeBookSeenRecipe {
|
||||
recipe_id: Ident,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
RenameItem 0x22 {
|
||||
RenameItem {
|
||||
item_name: BoundedString<0, 50>,
|
||||
}
|
||||
}
|
||||
|
||||
def_enum! {
|
||||
ResourcePackStatus 0x23: VarInt {
|
||||
ResourcePackStatus: VarInt {
|
||||
SuccessfullyLoaded = 0,
|
||||
Declined = 1,
|
||||
FailedDownload = 2,
|
||||
|
@ -476,20 +489,20 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_enum! {
|
||||
AdvancementTab 0x24: VarInt {
|
||||
AdvancementTab: VarInt {
|
||||
OpenedTab: Ident = 0,
|
||||
ClosedScreen = 1,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
SelectMerchantTrade 0x25 {
|
||||
SelectMerchantTrade {
|
||||
selected_slot: VarInt,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
UpdateBeacon 0x26 {
|
||||
UpdateBeacon {
|
||||
// TODO: potion ids
|
||||
primary_effect: Option<VarInt>,
|
||||
secondary_effect: Option<VarInt>,
|
||||
|
@ -497,13 +510,13 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
UpdateSelectedSlot 0x27 {
|
||||
UpdateSelectedSlot {
|
||||
slot: BoundedInt<i16, 0, 8>,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
UpdateCommandBlock 0x28 {
|
||||
UpdateCommandBlock {
|
||||
location: BlockPos,
|
||||
command: String,
|
||||
mode: CommandBlockMode,
|
||||
|
@ -528,7 +541,7 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
UpdateCommandBlockMinecart 0x29 {
|
||||
UpdateCommandBlockMinecart {
|
||||
entity_id: VarInt,
|
||||
command: String,
|
||||
track_output: bool,
|
||||
|
@ -536,14 +549,14 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
UpdateCreativeModeSlot 0x2a {
|
||||
UpdateCreativeModeSlot {
|
||||
slot: i16,
|
||||
// TODO: clicked_item: Slot,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
UpdateJigsaw 0x2b {
|
||||
UpdateJigsaw {
|
||||
location: BlockPos,
|
||||
name: Ident,
|
||||
target: Ident,
|
||||
|
@ -554,7 +567,7 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
UpdateStructureBlock 0x2c {
|
||||
UpdateStructureBlock {
|
||||
location: BlockPos,
|
||||
action: StructureBlockAction,
|
||||
mode: StructureBlockMode,
|
||||
|
@ -614,26 +627,26 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
UpdateSign 0x2d {
|
||||
UpdateSign {
|
||||
location: BlockPos,
|
||||
lines: [BoundedString<0, 384>; 4],
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
HandSwing 0x2e {
|
||||
HandSwing {
|
||||
hand: Hand,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
SpectatorTeleport 0x2f {
|
||||
SpectatorTeleport {
|
||||
target: Uuid,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
PlayerInteractBlock 0x30 {
|
||||
PlayerInteractBlock {
|
||||
hand: Hand,
|
||||
location: BlockPos,
|
||||
face: BlockFace,
|
||||
|
@ -644,7 +657,7 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
PlayerInteractItem 0x31 {
|
||||
PlayerInteractItem {
|
||||
hand: Hand,
|
||||
sequence: VarInt,
|
||||
}
|
||||
|
@ -652,56 +665,56 @@ pub mod play {
|
|||
|
||||
def_packet_group! {
|
||||
C2sPlayPacket {
|
||||
TeleportConfirm,
|
||||
QueryBlockNbt,
|
||||
UpdateDifficulty,
|
||||
CommandExecution,
|
||||
ChatMessage,
|
||||
RequestChatPreview,
|
||||
ClientStatus,
|
||||
ClientSettings,
|
||||
RequestCommandCompletion,
|
||||
ButtonClick,
|
||||
ClickSlot,
|
||||
CloseHandledScreen,
|
||||
CustomPayload,
|
||||
BookUpdate,
|
||||
QueryEntityNbt,
|
||||
PlayerInteractEntity,
|
||||
JigsawGenerate,
|
||||
KeepAlive,
|
||||
UpdateDifficultyLock,
|
||||
MovePlayerPosition,
|
||||
MovePlayerPositionAndRotation,
|
||||
MovePlayerRotation,
|
||||
MovePlayerOnGround,
|
||||
MoveVehicle,
|
||||
BoatPaddleState,
|
||||
PickFromInventory,
|
||||
CraftRequest,
|
||||
UpdatePlayerAbilities,
|
||||
PlayerAction,
|
||||
PlayerCommand,
|
||||
PlayerInput,
|
||||
PlayPong,
|
||||
RecipeBookChangeSettings,
|
||||
RecipeBookSeenRecipe,
|
||||
RenameItem,
|
||||
ResourcePackStatus,
|
||||
AdvancementTab,
|
||||
SelectMerchantTrade,
|
||||
UpdateBeacon,
|
||||
UpdateSelectedSlot,
|
||||
UpdateCommandBlock,
|
||||
UpdateCommandBlockMinecart,
|
||||
UpdateCreativeModeSlot,
|
||||
UpdateJigsaw,
|
||||
UpdateStructureBlock,
|
||||
UpdateSign,
|
||||
HandSwing,
|
||||
SpectatorTeleport,
|
||||
PlayerInteractBlock,
|
||||
PlayerInteractItem,
|
||||
TeleportConfirm = 0,
|
||||
QueryBlockNbt = 1,
|
||||
UpdateDifficulty = 2,
|
||||
CommandExecution = 3,
|
||||
ChatMessage = 4,
|
||||
RequestChatPreview = 5,
|
||||
ClientStatus = 6,
|
||||
ClientSettings = 7,
|
||||
RequestCommandCompletion = 8,
|
||||
ButtonClick = 9,
|
||||
ClickSlot = 10,
|
||||
CloseHandledScreen = 11,
|
||||
CustomPayload = 12,
|
||||
BookUpdate = 13,
|
||||
QueryEntityNbt = 14,
|
||||
PlayerInteractEntity = 15,
|
||||
JigsawGenerate = 16,
|
||||
KeepAlive = 17,
|
||||
UpdateDifficultyLock = 18,
|
||||
MovePlayerPosition = 19,
|
||||
MovePlayerPositionAndRotation = 20,
|
||||
MovePlayerRotation = 21,
|
||||
MovePlayerOnGround = 22,
|
||||
MoveVehicle = 23,
|
||||
BoatPaddleState = 24,
|
||||
PickFromInventory = 25,
|
||||
CraftRequest = 26,
|
||||
UpdatePlayerAbilities = 27,
|
||||
PlayerAction = 28,
|
||||
PlayerCommand = 29,
|
||||
PlayerInput = 30,
|
||||
PlayPong = 31,
|
||||
RecipeBookChangeSettings = 32,
|
||||
RecipeBookSeenRecipe = 33,
|
||||
RenameItem = 34,
|
||||
ResourcePackStatus = 35,
|
||||
AdvancementTab = 36,
|
||||
SelectMerchantTrade = 37,
|
||||
UpdateBeacon = 38,
|
||||
UpdateSelectedSlot = 39,
|
||||
UpdateCommandBlock = 40,
|
||||
UpdateCommandBlockMinecart = 41,
|
||||
UpdateCreativeModeSlot = 42,
|
||||
UpdateJigsaw = 43,
|
||||
UpdateStructureBlock = 44,
|
||||
UpdateSign = 45,
|
||||
HandSwing = 46,
|
||||
SpectatorTeleport = 47,
|
||||
PlayerInteractBlock = 48,
|
||||
PlayerInteractItem = 49,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,30 +6,37 @@ pub mod status {
|
|||
use super::*;
|
||||
|
||||
def_struct! {
|
||||
QueryResponse 0x00 {
|
||||
QueryResponse {
|
||||
json_response: String
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
QueryPong 0x01 {
|
||||
QueryPong {
|
||||
/// Should be the same as the payload from ping.
|
||||
payload: u64
|
||||
}
|
||||
}
|
||||
|
||||
def_packet_group! {
|
||||
S2cStatusPacket {
|
||||
QueryResponse = 0,
|
||||
QueryPong = 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod login {
|
||||
use super::*;
|
||||
|
||||
def_struct! {
|
||||
LoginDisconnect 0x00 {
|
||||
LoginDisconnect {
|
||||
reason: Text,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
EncryptionRequest 0x01 {
|
||||
EncryptionRequest {
|
||||
/// Currently unused
|
||||
server_id: BoundedString<0, 20>,
|
||||
/// The RSA public key
|
||||
|
@ -39,7 +46,7 @@ pub mod login {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
LoginSuccess 0x02 {
|
||||
LoginSuccess {
|
||||
uuid: Uuid,
|
||||
username: BoundedString<3, 16>,
|
||||
properties: Vec<Property>,
|
||||
|
@ -47,13 +54,13 @@ pub mod login {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
LoginCompression 0x03 {
|
||||
LoginCompression {
|
||||
threshold: VarInt
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
LoginPluginRequest 0x04 {
|
||||
LoginPluginRequest {
|
||||
message_id: VarInt,
|
||||
channel: Ident,
|
||||
data: RawBytes,
|
||||
|
@ -62,11 +69,11 @@ pub mod login {
|
|||
|
||||
def_packet_group! {
|
||||
S2cLoginPacket {
|
||||
LoginDisconnect,
|
||||
EncryptionRequest,
|
||||
LoginSuccess,
|
||||
LoginCompression,
|
||||
LoginPluginRequest,
|
||||
LoginDisconnect = 0,
|
||||
EncryptionRequest = 1,
|
||||
LoginSuccess = 2,
|
||||
LoginCompression = 3,
|
||||
LoginPluginRequest = 4,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +82,7 @@ pub mod play {
|
|||
use super::*;
|
||||
|
||||
def_struct! {
|
||||
EntitySpawn 0x00 {
|
||||
EntitySpawn {
|
||||
entity_id: VarInt,
|
||||
object_uuid: Uuid,
|
||||
kind: VarInt,
|
||||
|
@ -89,7 +96,7 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
ExperienceOrbSpawn 0x01 {
|
||||
ExperienceOrbSpawn {
|
||||
entity_id: VarInt,
|
||||
position: Vec3<f64>,
|
||||
count: i16,
|
||||
|
@ -97,7 +104,7 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
PlayerSpawn 0x02 {
|
||||
PlayerSpawn {
|
||||
entity_id: VarInt,
|
||||
player_uuid: Uuid,
|
||||
position: Vec3<f64>,
|
||||
|
@ -107,20 +114,20 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
EntityAnimation 0x03 {
|
||||
EntityAnimation {
|
||||
entity_id: VarInt,
|
||||
animation: u8,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
PlayerActionResponse 0x05 {
|
||||
PlayerActionResponse {
|
||||
sequence: VarInt,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
BlockBreakingProgress 0x06 {
|
||||
BlockBreakingProgress {
|
||||
entity_id: VarInt,
|
||||
location: BlockPos,
|
||||
destroy_stage: BoundedInt<u8, 0, 10>,
|
||||
|
@ -128,7 +135,7 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
BlockEntityUpdate 0x07 {
|
||||
BlockEntityUpdate {
|
||||
location: BlockPos,
|
||||
kind: VarInt, // TODO: use enum here
|
||||
data: nbt::Blob,
|
||||
|
@ -136,7 +143,7 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
BlockEvent 0x08 {
|
||||
BlockEvent {
|
||||
location: BlockPos,
|
||||
action_id: u8,
|
||||
action_param: u8,
|
||||
|
@ -145,14 +152,14 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
BlockUpdate 0x09 {
|
||||
BlockUpdate {
|
||||
location: BlockPos,
|
||||
block_id: VarInt,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
BossBar 0x0a {
|
||||
BossBar {
|
||||
uuid: Uuid,
|
||||
action: BossBarAction,
|
||||
}
|
||||
|
@ -199,7 +206,7 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
SetDifficulty 0x0b {
|
||||
SetDifficulty {
|
||||
difficulty: Difficulty,
|
||||
locked: bool,
|
||||
}
|
||||
|
@ -215,33 +222,33 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
ClearTitles 0x0d {
|
||||
ClearTitles {
|
||||
reset: bool,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
Disconnect 0x17 {
|
||||
Disconnect {
|
||||
reason: Text,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
EntityStatus 0x18 {
|
||||
EntityStatus {
|
||||
entity_id: i32,
|
||||
entity_status: u8,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
UnloadChunk 0x1a {
|
||||
UnloadChunk {
|
||||
chunk_x: i32,
|
||||
chunk_z: i32
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
GameStateChange 0x1b {
|
||||
GameStateChange {
|
||||
reason: GameStateChangeReason,
|
||||
value: f32,
|
||||
}
|
||||
|
@ -265,7 +272,7 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
WorldBorderInitialize 0x1d {
|
||||
WorldBorderInitialize {
|
||||
x: f64,
|
||||
z: f64,
|
||||
old_diameter: f64,
|
||||
|
@ -278,13 +285,13 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
KeepAlive 0x1e {
|
||||
KeepAlive {
|
||||
id: i64,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
ChunkData 0x1f {
|
||||
ChunkData {
|
||||
chunk_x: i32,
|
||||
chunk_z: i32,
|
||||
heightmaps: Nbt<ChunkDataHeightmaps>,
|
||||
|
@ -316,7 +323,7 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
GameJoin 0x23 {
|
||||
GameJoin {
|
||||
/// Entity ID of the joining player
|
||||
entity_id: i32,
|
||||
is_hardcore: bool,
|
||||
|
@ -508,7 +515,7 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
MoveRelative 0x26 {
|
||||
MoveRelative {
|
||||
entity_id: VarInt,
|
||||
delta: Vec3<i16>,
|
||||
on_ground: bool,
|
||||
|
@ -516,7 +523,7 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
RotateAndMoveRelative 0x27 {
|
||||
RotateAndMoveRelative {
|
||||
entity_id: VarInt,
|
||||
delta: Vec3<i16>,
|
||||
yaw: ByteAngle,
|
||||
|
@ -526,7 +533,7 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
Rotate 0x28 {
|
||||
Rotate {
|
||||
entity_id: VarInt,
|
||||
yaw: ByteAngle,
|
||||
pitch: ByteAngle,
|
||||
|
@ -535,7 +542,7 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
ChatMessage 0x30 {
|
||||
ChatMessage {
|
||||
message: Text,
|
||||
/// Index into the chat type registry
|
||||
kind: VarInt,
|
||||
|
@ -545,7 +552,7 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_enum! {
|
||||
UpdatePlayerList 0x34: VarInt {
|
||||
UpdatePlayerList: VarInt {
|
||||
AddPlayer: Vec<PlayerListAddPlayer> = 0,
|
||||
UpdateGameMode: Vec<(Uuid, GameMode)> = 1,
|
||||
UpdateLatency: Vec<(Uuid, VarInt)> = 2,
|
||||
|
@ -567,7 +574,7 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
PlayerPositionLook 0x36 {
|
||||
PlayerPositionLook {
|
||||
position: Vec3<f64>,
|
||||
yaw: f32,
|
||||
pitch: f32,
|
||||
|
@ -588,13 +595,13 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
EntitiesDestroy 0x38 {
|
||||
EntitiesDestroy {
|
||||
entities: Vec<VarInt>,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
PlayerRespawn 0x3b {
|
||||
PlayerRespawn {
|
||||
dimension_type_name: Ident,
|
||||
dimension_name: Ident,
|
||||
hashed_seed: u64,
|
||||
|
@ -608,14 +615,14 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
EntitySetHeadYaw 0x3c {
|
||||
EntitySetHeadYaw {
|
||||
entity_id: VarInt,
|
||||
head_yaw: ByteAngle,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
ChunkSectionUpdate 0x3d {
|
||||
ChunkSectionUpdate {
|
||||
chunk_section_position: i64,
|
||||
invert_trust_edges: bool,
|
||||
blocks: Vec<VarLong>,
|
||||
|
@ -623,53 +630,53 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
UpdateSelectedSlot 0x47 {
|
||||
UpdateSelectedSlot {
|
||||
slot: BoundedInt<u8, 0, 9>,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
ChunkRenderDistanceCenter 0x48 {
|
||||
ChunkRenderDistanceCenter {
|
||||
chunk_x: VarInt,
|
||||
chunk_z: VarInt,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
ChunkLoadDistance 0x49 {
|
||||
ChunkLoadDistance {
|
||||
view_distance: BoundedInt<VarInt, 2, 32>,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
PlayerSpawnPosition 0x4a {
|
||||
PlayerSpawnPosition {
|
||||
location: BlockPos,
|
||||
angle: f32,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
EntityTrackerUpdate 0x4d {
|
||||
EntityTrackerUpdate {
|
||||
entity_id: VarInt,
|
||||
metadata: RawBytes,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
EntityVelocityUpdate 0x4f {
|
||||
EntityVelocityUpdate {
|
||||
entity_id: VarInt,
|
||||
velocity: Vec3<i16>,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
UpdateSubtitle 0x58 {
|
||||
UpdateSubtitle {
|
||||
subtitle_text: Text,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
WorldTimeUpdate 0x59 {
|
||||
WorldTimeUpdate {
|
||||
/// The age of the world in 1/20ths of a second.
|
||||
world_age: i64,
|
||||
/// The current time of day in 1/20ths of a second.
|
||||
|
@ -680,14 +687,14 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
UpdateTitle 0x5a {
|
||||
UpdateTitle {
|
||||
text: Text,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
#[derive(Copy, PartialEq, Eq)]
|
||||
TitleAnimationTimes 0x5b {
|
||||
TitleAnimationTimes {
|
||||
/// Ticks to spend fading in.
|
||||
fade_in: u32,
|
||||
/// Ticks to keep the title displayed.
|
||||
|
@ -698,7 +705,7 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
GameMessage 0x5f {
|
||||
GameMessage {
|
||||
chat: Text,
|
||||
/// Index into the chat type registry.
|
||||
kind: VarInt,
|
||||
|
@ -706,14 +713,14 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
PlayerListHeaderFooter 0x60 {
|
||||
PlayerListHeaderFooter {
|
||||
header: Text,
|
||||
footer: Text,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
EntityPosition 0x63 {
|
||||
EntityPosition {
|
||||
entity_id: VarInt,
|
||||
position: Vec3<f64>,
|
||||
yaw: ByteAngle,
|
||||
|
@ -723,7 +730,7 @@ pub mod play {
|
|||
}
|
||||
|
||||
def_struct! {
|
||||
EntityAttributes 0x65 {
|
||||
EntityAttributes {
|
||||
entity_id: VarInt,
|
||||
properties: Vec<EntityAttributesProperty>,
|
||||
}
|
||||
|
@ -747,48 +754,48 @@ pub mod play {
|
|||
|
||||
def_packet_group! {
|
||||
S2cPlayPacket {
|
||||
EntitySpawn,
|
||||
ExperienceOrbSpawn,
|
||||
PlayerSpawn,
|
||||
EntityAnimation,
|
||||
PlayerActionResponse,
|
||||
BlockBreakingProgress,
|
||||
BlockEntityUpdate,
|
||||
BlockEvent,
|
||||
BlockUpdate,
|
||||
BossBar,
|
||||
ClearTitles,
|
||||
Disconnect,
|
||||
EntityStatus,
|
||||
UnloadChunk,
|
||||
GameStateChange,
|
||||
KeepAlive,
|
||||
ChunkData,
|
||||
GameJoin,
|
||||
MoveRelative,
|
||||
RotateAndMoveRelative,
|
||||
Rotate,
|
||||
ChatMessage,
|
||||
UpdatePlayerList,
|
||||
PlayerPositionLook,
|
||||
EntitiesDestroy,
|
||||
PlayerRespawn,
|
||||
EntitySetHeadYaw,
|
||||
ChunkSectionUpdate,
|
||||
UpdateSelectedSlot,
|
||||
ChunkRenderDistanceCenter,
|
||||
ChunkLoadDistance,
|
||||
PlayerSpawnPosition,
|
||||
EntityTrackerUpdate,
|
||||
EntityVelocityUpdate,
|
||||
UpdateSubtitle,
|
||||
WorldTimeUpdate,
|
||||
UpdateTitle,
|
||||
TitleAnimationTimes,
|
||||
GameMessage,
|
||||
PlayerListHeaderFooter,
|
||||
EntityPosition,
|
||||
EntityAttributes,
|
||||
EntitySpawn = 0,
|
||||
ExperienceOrbSpawn = 1,
|
||||
PlayerSpawn = 2,
|
||||
EntityAnimation = 3,
|
||||
PlayerActionResponse = 5,
|
||||
BlockBreakingProgress = 6,
|
||||
BlockEntityUpdate = 7,
|
||||
BlockEvent = 8,
|
||||
BlockUpdate = 9,
|
||||
BossBar = 10,
|
||||
ClearTitles = 13,
|
||||
Disconnect = 23,
|
||||
EntityStatus = 24,
|
||||
UnloadChunk = 26,
|
||||
GameStateChange = 27,
|
||||
KeepAlive = 30,
|
||||
ChunkData = 31,
|
||||
GameJoin = 35,
|
||||
MoveRelative = 38,
|
||||
RotateAndMoveRelative = 39,
|
||||
Rotate = 40,
|
||||
ChatMessage = 48,
|
||||
UpdatePlayerList = 52,
|
||||
PlayerPositionLook = 54,
|
||||
EntitiesDestroy = 56,
|
||||
PlayerRespawn = 59,
|
||||
EntitySetHeadYaw = 60,
|
||||
ChunkSectionUpdate = 61,
|
||||
UpdateSelectedSlot = 71,
|
||||
ChunkRenderDistanceCenter = 72,
|
||||
ChunkLoadDistance = 73,
|
||||
PlayerSpawnPosition = 74,
|
||||
EntityTrackerUpdate = 77,
|
||||
EntityVelocityUpdate = 79,
|
||||
UpdateSubtitle = 88,
|
||||
WorldTimeUpdate = 89,
|
||||
UpdateTitle = 90,
|
||||
TitleAnimationTimes = 91,
|
||||
GameMessage = 95,
|
||||
PlayerListHeaderFooter = 96,
|
||||
EntityPosition = 99,
|
||||
EntityAttributes = 101,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue