File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ pub trait GamePacket: Sized + ProtoCodec {
3232}
3333
3434pub trait GamePacketsAll : Sized {
35+ fn id ( & self ) -> u16 ;
3536 fn compress ( & self ) -> bool ;
3637 fn encrypt ( & self ) -> bool ;
3738
You can’t perform that action at this time.
0 commit comments