add derive McBuf to every packet

This commit is contained in:
mat 2022-05-14 20:03:24 -05:00
parent 93730a550a
commit f0792f25bb
55 changed files with 99 additions and 103 deletions

View file

@ -182,8 +182,8 @@ fn as_packet_derive(input: TokenStream, state: proc_macro2::TokenStream) -> Toke
_ => panic!("#[derive(*Packet)] can only be used on structs with named fields"),
};
let mcbufreadable_impl = create_impl_mcbufreadable(&ident, &data);
let mcbufwritable_impl = create_impl_mcbufwritable(&ident, &data);
let _mcbufreadable_impl = create_impl_mcbufreadable(&ident, &data);
let _mcbufwritable_impl = create_impl_mcbufwritable(&ident, &data);
let contents = quote! {
impl #ident {
@ -202,10 +202,6 @@ fn as_packet_derive(input: TokenStream, state: proc_macro2::TokenStream) -> Toke
Ok(Self::read_into(buf)?.get())
}
}
#mcbufreadable_impl
#mcbufwritable_impl
};
contents.into()

View file

@ -1,7 +1,7 @@
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
use uuid::Uuid;
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundAddEntityPacket {
#[var]
pub id: i32,

View file

@ -1,7 +1,7 @@
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
use uuid::Uuid;
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundAddMobPacket {
#[var]
pub id: i32,

View file

@ -1,7 +1,7 @@
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
use uuid::Uuid;
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundAddPlayerPacket {
#[var]
pub id: i32,

View file

@ -1,6 +1,6 @@
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundAnimatePacket {
#[var]
pub id: u32,

View file

@ -1,7 +1,7 @@
use azalea_core::BlockPos;
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundBlockUpdatePacket {
pub pos: BlockPos,
// TODO: in vanilla this is a BlockState, but here we just have it as a number.

View file

@ -1,7 +1,7 @@
use azalea_core::difficulty::Difficulty;
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundChangeDifficultyPacket {
pub difficulty: Difficulty,
pub locked: bool,

View file

@ -2,7 +2,7 @@ use azalea_chat::component::Component;
use packet_macros::{GamePacket, McBuf};
use uuid::Uuid;
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundChatPacket {
pub message: Component,
pub type_: ChatType,

View file

@ -1,7 +1,7 @@
use azalea_core::Slot;
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundContainerSetContentPacket {
pub container_id: u8,
#[var]

View file

@ -1,8 +1,8 @@
use crate::mc_buf::UnsizedByteArray;
use azalea_core::resource_location::ResourceLocation;
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundCustomPayloadPacket {
pub identifier: ResourceLocation,
pub data: UnsizedByteArray,

View file

@ -1,7 +1,7 @@
use azalea_chat::component::Component;
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundDisconnectPacket {
pub reason: Component,
}

View file

@ -1,7 +1,7 @@
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
// we can't identify the status in azalea-protocol since they vary depending on the entity
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundEntityEventPacket {
pub entity_id: i32,
pub entity_status: i8,

View file

@ -1,6 +1,6 @@
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundEntityVelocityPacket {
#[var]
pub entity_id: u32,

View file

@ -1,6 +1,6 @@
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundGameEventPacket {
pub event: EventType,
pub param: f32,

View file

@ -1,6 +1,6 @@
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundInitializeBorderPacket {
pub new_center_x: f64,
pub new_center_z: f64,

View file

@ -1,6 +1,6 @@
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundKeepAlivePacket {
pub id: u64,
}

View file

@ -2,7 +2,7 @@ use packet_macros::{GamePacket, McBuf};
use super::clientbound_light_update_packet::ClientboundLightUpdatePacketData;
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundLevelChunkWithLightPacket {
pub x: i32,
pub z: i32,

View file

@ -1,7 +1,7 @@
use azalea_core::BlockPos;
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundLevelEventPacket {
pub type_: i32,
pub pos: BlockPos,

View file

@ -1,7 +1,7 @@
use crate::mc_buf::ParticleData;
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundLevelParticlesPacket {
pub particle_id: u32,
pub override_limiter: bool,

View file

@ -1,7 +1,7 @@
use crate::mc_buf::BitSet;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundLightUpdatePacket {
pub x: i32,
pub z: i32,

View file

@ -1,7 +1,7 @@
use azalea_core::{game_type::GameType, resource_location::ResourceLocation};
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundLoginPacket {
pub player_id: u32,
pub hardcore: bool,

View file

@ -1,6 +1,6 @@
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundMoveEntityPosPacket {
#[var]
pub entity_id: i32,

View file

@ -1,6 +1,6 @@
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundMoveEntityPosRotPacket {
#[var]
pub entity_id: i32,

View file

@ -1,6 +1,6 @@
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundMoveEntityRotPacket {
#[var]
pub entity_id: i32,

View file

@ -1,8 +1,8 @@
use crate::mc_buf::{McBufReadable, McBufWritable, Readable};
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
use std::io::{Read, Write};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundPlayerAbilitiesPacket {
pub flags: PlayerAbilitiesFlags,
pub flying_speed: f32,

View file

@ -4,7 +4,7 @@ use packet_macros::{GamePacket, McBuf};
use std::io::{Read, Write};
use uuid::Uuid;
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundPlayerInfoPacket {
pub action: Action,
}

View file

@ -1,8 +1,8 @@
use crate::mc_buf::{McBufReadable, McBufWritable, Readable};
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
use std::io::{Read, Write};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundPlayerPositionPacket {
pub x: f64,
pub y: f64,

View file

@ -3,7 +3,7 @@ use azalea_core::resource_location::ResourceLocation;
use packet_macros::{GamePacket, McBuf};
use std::io::{Read, Write};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundRecipePacket {
pub action: State,
pub settings: RecipeBookSettings,

View file

@ -1,6 +1,6 @@
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundRemoveEntitiesPacket {
#[var]
pub entity_ids: Vec<u32>,

View file

@ -1,6 +1,6 @@
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundRotateHeadPacket {
#[var]
pub entity_id: u32,

View file

@ -1,9 +1,9 @@
use crate::mc_buf::{McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable};
use azalea_core::{ChunkSectionBlockPos, ChunkSectionPos};
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
use std::io::{Read, Write};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundSectionBlocksUpdatePacket {
pub section_pos: ChunkSectionPos,
pub suppress_light_updates: bool,

View file

@ -1,7 +1,7 @@
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
/// Sent to change the player's slot selection.
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundSetCarriedItemPacket {
pub slot: u8,
}

View file

@ -1,6 +1,6 @@
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundSetChunkCacheCenterPacket {
#[var]
pub x: i32,

View file

@ -1,7 +1,7 @@
use azalea_core::BlockPos;
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundSetDefaultSpawnPositionPacket {
pub pos: BlockPos,
pub angle: f32,

View file

@ -1,7 +1,7 @@
use crate::mc_buf::EntityMetadata;
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundSetEntityDataPacket {
#[var]
pub id: i32,

View file

@ -1,6 +1,6 @@
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundSetEntityLinkPacket {
pub source_id: u32,
pub dest_id: u32,

View file

@ -1,6 +1,6 @@
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundSetExperiencePacket {
pub experience_progress: f32,
#[var]

View file

@ -1,6 +1,6 @@
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundSetHealthPacket {
pub health: f32,
#[var]

View file

@ -1,6 +1,6 @@
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundSetTimePacket {
pub game_time: u64,
pub day_time: u64,

View file

@ -1,6 +1,6 @@
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundSoundPacket {
#[var]
/// TODO: use the sound registry instead of just being a u32

View file

@ -1,6 +1,6 @@
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundTeleportEntityPacket {
#[var]
pub id: u32,

View file

@ -7,7 +7,7 @@ use std::{
io::{Read, Write},
};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundUpdateAdvancementsPacket {
pub reset: bool,
pub added: HashMap<ResourceLocation, Advancement>,

View file

@ -4,7 +4,7 @@ use packet_macros::{GamePacket, McBuf};
use std::io::{Read, Write};
use uuid::Uuid;
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundUpdateAttributesPacket {
#[var]
pub entity_id: u32,

View file

@ -5,7 +5,7 @@ use packet_macros::{GamePacket, McBuf};
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundUpdateRecipesPacket {
pub recipes: Vec<Recipe>,
}

View file

@ -1,12 +1,12 @@
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
use azalea_core::resource_location::ResourceLocation;
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
use std::{
collections::HashMap,
io::{Read, Write},
};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundUpdateTagsPacket {
pub tags: HashMap<ResourceLocation, Vec<Tags>>,
}

View file

@ -1,6 +1,6 @@
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundUpdateViewDistancePacket {
#[var]
pub view_distance: i32,

View file

@ -1,8 +1,8 @@
use crate::mc_buf::UnsizedByteArray;
use azalea_core::resource_location::ResourceLocation;
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ServerboundCustomPayloadPacket {
pub identifier: ResourceLocation,
pub data: UnsizedByteArray,

View file

@ -1,6 +1,6 @@
use packet_macros::GamePacket;
use packet_macros::{GamePacket, McBuf};
#[derive(Clone, Debug, GamePacket)]
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ServerboundKeepAlivePacket {
pub id: u64,
}

View file

@ -1,8 +1,8 @@
use crate::packets::ConnectionProtocol;
use packet_macros::HandshakePacket;
use packet_macros::{HandshakePacket, McBuf};
use std::hash::Hash;
#[derive(Hash, Clone, Debug, HandshakePacket)]
#[derive(Hash, Clone, Debug, McBuf, HandshakePacket)]
pub struct ClientIntentionPacket {
#[var]
pub protocol_version: u32,

View file

@ -1,9 +1,9 @@
use crate::mc_buf::UnsizedByteArray;
use azalea_core::resource_location::ResourceLocation;
use packet_macros::LoginPacket;
use packet_macros::{LoginPacket, McBuf};
use std::hash::Hash;
#[derive(Hash, Clone, Debug, LoginPacket)]
#[derive(Hash, Clone, Debug, McBuf, LoginPacket)]
pub struct ClientboundCustomQueryPacket {
#[var]
pub transaction_id: u32,

View file

@ -1,7 +1,7 @@
use azalea_chat::component::Component;
use packet_macros::LoginPacket;
use packet_macros::{LoginPacket, McBuf};
#[derive(Clone, Debug, LoginPacket)]
#[derive(Clone, Debug, McBuf, LoginPacket)]
pub struct ClientboundLoginDisconnectPacket {
pub reason: Component,
}

View file

@ -1,7 +1,7 @@
use packet_macros::LoginPacket;
use packet_macros::{LoginPacket, McBuf};
use std::hash::Hash;
#[derive(Hash, Clone, Debug, LoginPacket)]
#[derive(Hash, Clone, Debug, McBuf, LoginPacket)]
pub struct ServerboundHelloPacket {
pub username: String,
}

View file

@ -1,7 +1,7 @@
use packet_macros::LoginPacket;
use packet_macros::{LoginPacket, McBuf};
use std::hash::Hash;
#[derive(Hash, Clone, Debug, LoginPacket)]
#[derive(Hash, Clone, Debug, McBuf, LoginPacket)]
pub struct ServerboundKeyPacket {
pub shared_secret: Vec<u8>,
pub nonce: Vec<u8>,

View file

@ -1,4 +1,4 @@
use packet_macros::StatusPacket;
use packet_macros::{McBuf, StatusPacket};
#[derive(Clone, Debug, StatusPacket)]
#[derive(Clone, Debug, McBuf, StatusPacket)]
pub struct ServerboundStatusRequestPacket {}

View file

@ -84,8 +84,8 @@ def generate(burger_packets, mappings: Mappings, target_packet_id, target_packet
generated_packet_code = []
uses = set()
generated_packet_code.append(
f'#[derive(Clone, Debug, {to_camel_case(state)}Packet)]')
uses.add(f'packet_macros::{to_camel_case(state)}Packet')
f'#[derive(Clone, Debug, McBuf, {to_camel_case(state)}Packet)]')
uses.add(f'packet_macros::{{to_camel_case(state)}Packet, McBuf}')
obfuscated_class_name = packet['class'].split('.')[0].split('$')[0]
class_name = mappings.get_class(