mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
add ProtocolPacket::name function
This commit is contained in:
parent
f2d8d4211b
commit
b6ddde99ea
2 changed files with 34 additions and 2 deletions
|
@ -196,6 +196,8 @@ pub fn declare_state_packets(input: TokenStream) -> TokenStream {
|
|||
let mut serverbound_enum_contents = quote!();
|
||||
let mut clientbound_id_match_contents = quote!();
|
||||
let mut serverbound_id_match_contents = quote!();
|
||||
let mut clientbound_name_match_contents = quote!();
|
||||
let mut serverbound_name_match_contents = quote!();
|
||||
let mut clientbound_write_match_contents = quote!();
|
||||
let mut serverbound_write_match_contents = quote!();
|
||||
let mut clientbound_read_match_contents = quote!();
|
||||
|
@ -218,7 +220,10 @@ pub fn declare_state_packets(input: TokenStream) -> TokenStream {
|
|||
#variant_name(#module_name::#struct_name),
|
||||
});
|
||||
clientbound_id_match_contents.extend(quote! {
|
||||
#clientbound_state_name::#variant_name(_packet) => #id,
|
||||
#clientbound_state_name::#variant_name(..) => #id,
|
||||
});
|
||||
clientbound_name_match_contents.extend(quote! {
|
||||
#clientbound_state_name::#variant_name(..) => #packet_name_litstr,
|
||||
});
|
||||
clientbound_write_match_contents.extend(quote! {
|
||||
#clientbound_state_name::#variant_name(packet) => packet.write(buf),
|
||||
|
@ -267,7 +272,10 @@ pub fn declare_state_packets(input: TokenStream) -> TokenStream {
|
|||
#variant_name(#module_name::#struct_name),
|
||||
});
|
||||
serverbound_id_match_contents.extend(quote! {
|
||||
#serverbound_state_name::#variant_name(_packet) => #id,
|
||||
#serverbound_state_name::#variant_name(..) => #id,
|
||||
});
|
||||
serverbound_name_match_contents.extend(quote! {
|
||||
#serverbound_state_name::#variant_name(..) => #packet_name_litstr,
|
||||
});
|
||||
serverbound_write_match_contents.extend(quote! {
|
||||
#serverbound_state_name::#variant_name(packet) => packet.write(buf),
|
||||
|
@ -297,6 +305,9 @@ pub fn declare_state_packets(input: TokenStream) -> TokenStream {
|
|||
serverbound_id_match_contents.extend(quote! {
|
||||
_ => unreachable!("This enum is empty and can't exist.")
|
||||
});
|
||||
serverbound_name_match_contents.extend(quote! {
|
||||
_ => unreachable!("This enum is empty and can't exist.")
|
||||
});
|
||||
serverbound_write_match_contents.extend(quote! {
|
||||
_ => unreachable!("This enum is empty and can't exist.")
|
||||
});
|
||||
|
@ -305,6 +316,9 @@ pub fn declare_state_packets(input: TokenStream) -> TokenStream {
|
|||
clientbound_id_match_contents.extend(quote! {
|
||||
_ => unreachable!("This enum is empty and can't exist.")
|
||||
});
|
||||
clientbound_name_match_contents.extend(quote! {
|
||||
_ => unreachable!("This enum is empty and can't exist.")
|
||||
});
|
||||
clientbound_write_match_contents.extend(quote! {
|
||||
_ => unreachable!("This enum is empty and can't exist.")
|
||||
});
|
||||
|
@ -338,6 +352,12 @@ pub fn declare_state_packets(input: TokenStream) -> TokenStream {
|
|||
}
|
||||
}
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
match self {
|
||||
#serverbound_name_match_contents
|
||||
}
|
||||
}
|
||||
|
||||
fn write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
|
||||
match self {
|
||||
#serverbound_write_match_contents
|
||||
|
@ -376,6 +396,12 @@ pub fn declare_state_packets(input: TokenStream) -> TokenStream {
|
|||
}
|
||||
}
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
match self {
|
||||
#clientbound_name_match_contents
|
||||
}
|
||||
}
|
||||
|
||||
fn write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
|
||||
match self {
|
||||
#clientbound_write_match_contents
|
||||
|
|
|
@ -44,6 +44,12 @@ where
|
|||
{
|
||||
fn id(&self) -> u32;
|
||||
|
||||
/// Returns Mojang's resource name for the packet.
|
||||
///
|
||||
/// This doesn't include the "minecraft:" prefix, it just returns a string
|
||||
/// like `pong`.
|
||||
fn name(&self) -> &'static str;
|
||||
|
||||
/// Read a packet by its id, `ConnectionProtocol`, and flow
|
||||
fn read(id: u32, buf: &mut Cursor<&[u8]>) -> Result<Self, Box<ReadPacketError>>;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue