Skip to content

Commit f0519bf

Browse files
committed
GamePacketsAll::id
1 parent 535f42f commit f0519bf

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

crates/macros/src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,15 @@ pub fn gamepackets(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
195195
}
196196
});
197197

198+
let id = args.packets.clone();
199+
let id = id.iter().map(|(name, value)| {
200+
if let Some(v) = value {
201+
quote! { GamePackets::#name(_) => { return <#v as ::bedrockrs_proto_core::GamePacket>::ID; }, }
202+
} else {
203+
quote! { GamePackets::#name() => { todo!("impl GamePackets::{}", stringify!(name)); }, }
204+
}
205+
});
206+
198207
let compress = args.packets.clone();
199208
let compress = compress.iter().map(|(name, value)| {
200209
if let Some(v) = value {
@@ -281,6 +290,13 @@ pub fn gamepackets(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
281290
}
282291

283292
impl ::bedrockrs_proto_core::GamePacketsAll for GamePackets {
293+
#[inline]
294+
fn id(&self) -> u16 {
295+
match self {
296+
#(#id)*
297+
};
298+
}
299+
284300
#[inline]
285301
fn compress(&self) -> bool {
286302
match self {

crates/proto_core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub trait GamePacket: Sized + ProtoCodec {
3232
}
3333

3434
pub trait GamePacketsAll: Sized {
35+
fn id(&self) -> u16;
3536
fn compress(&self) -> bool;
3637
fn encrypt(&self) -> bool;
3738

0 commit comments

Comments
 (0)