@@ -222,12 +222,9 @@ impl ToTokens for BlockPropertyStruct {
222222 }
223223 } ) ;
224224
225- let block_ids = self
226- . data
227- . blocks
228- . iter ( )
229- . map ( |( _, id) | * id)
230- . collect :: < Vec < _ > > ( ) ;
225+ let block_ids = self . data . blocks . iter ( ) . map ( |( name, _) | {
226+ Ident :: new ( & const_block_name_from_block_name ( name) , Span :: call_site ( ) )
227+ } ) ;
231228
232229 let to_index_logic = self . data . variant_mappings . iter ( ) . rev ( ) . map ( |entry| {
233230 let field = Ident :: new_raw ( & entry. original_name , Span :: call_site ( ) ) ;
@@ -389,7 +386,7 @@ impl ToTokens for BlockPropertyStruct {
389386 #[ inline]
390387 #[ allow( clippy:: manual_range_patterns) ]
391388 fn handles_block_id( block_id: BlockId ) -> bool where Self : Sized {
392- matches!( block_id. as_u16 ( ) , #( #block_ids) |* )
389+ matches!( block_id, #( BlockId :: #block_ids) |* )
393390 }
394391
395392 fn to_state_id( & self , block: & Block ) -> BlockStateId {
@@ -433,7 +430,7 @@ impl ToTokens for BlockPropertyStruct {
433430 #[ allow( clippy:: manual_range_patterns) ]
434431 fn from_props( props: & [ ( & str , & str ) ] , block: & Block ) -> Self {
435432 #[ cfg( debug_assertions) ]
436- if !matches! ( block. id. as_u16 ( ) , # ( #block_ids ) | * ) {
433+ if !Self :: handles_block_id ( block. id) {
437434 panic!( "{} is not a valid block for {}" , block. name, #struct_name) ;
438435 }
439436 let mut block_props = Self :: default ( block) ;
@@ -1072,21 +1069,18 @@ pub fn build() -> TokenStream {
10721069 Span :: call_site ( ) ,
10731070 ) ;
10741071
1075- for ( block_name, id) in & property_group. blocks {
1076- let const_block_name = Ident :: new (
1077- & const_block_name_from_block_name ( block_name) ,
1078- Span :: call_site ( ) ,
1079- ) ;
1080- let id_lit = LitInt :: new ( & id. to_string ( ) , Span :: call_site ( ) ) ;
1081-
1082- block_properties_from_state_and_block_id_arms. push ( quote ! {
1083- #id_lit => Box :: new( #property_name:: from_state_id( state_id, & Block :: #const_block_name) ) ,
1084- } ) ;
1072+ let idents: Box < _ > = property_group
1073+ . blocks
1074+ . iter ( )
1075+ . map ( |( name, _) | Ident :: new ( & const_block_name_from_block_name ( name) , Span :: call_site ( ) ) )
1076+ . collect ( ) ;
10851077
1086- block_properties_from_props_and_name_arms. push ( quote ! {
1087- #id_lit => Box :: new( #property_name:: from_props( props, & Block :: #const_block_name) ) ,
1088- } ) ;
1089- }
1078+ block_properties_from_state_and_block_id_arms. push ( quote ! {
1079+ #( BlockId :: #idents) |* => Box :: new( #property_name:: from_state_id( state_id, self ) ) ,
1080+ } ) ;
1081+ block_properties_from_props_and_name_arms. push ( quote ! {
1082+ #( BlockId :: #idents) |* => Box :: new( #property_name:: from_props( props, self ) ) ,
1083+ } ) ;
10901084
10911085 block_properties. push ( BlockPropertyStruct {
10921086 data : property_group,
@@ -1351,7 +1345,7 @@ pub fn build() -> TokenStream {
13511345 #[ track_caller]
13521346 #[ doc = r" Get the properties of the block." ]
13531347 pub fn properties( & self , state_id: BlockStateId ) -> Option <Box <dyn BlockProperties >> {
1354- Some ( match self . id. as_u16 ( ) {
1348+ Some ( match self . id {
13551349 #( #block_properties_from_state_and_block_id_arms) *
13561350 _ => return None ,
13571351 } )
@@ -1360,7 +1354,7 @@ pub fn build() -> TokenStream {
13601354 #[ track_caller]
13611355 #[ doc = r" Get the properties of the block." ]
13621356 pub fn from_properties( & self , props: & [ ( & str , & str ) ] ) -> Box <dyn BlockProperties > {
1363- match self . id. as_u16 ( ) {
1357+ match self . id {
13641358 #( #block_properties_from_props_and_name_arms) *
13651359 _ => panic!( "Invalid props" )
13661360 }
0 commit comments