@@ -3,9 +3,11 @@ use ahash::RandomState;
33use bitcode_derive:: { Decode , Encode } ;
44use deepsize:: DeepSizeOf ;
55use lazy_static:: lazy_static;
6+ use once_cell:: sync:: Lazy ;
67use std:: collections:: HashMap ;
78use std:: fmt:: Display ;
89use std:: process:: exit;
10+ use std:: str:: FromStr ;
911use temper_codec:: net_types:: var_int:: VarInt ;
1012use tracing:: { error, warn} ;
1113
@@ -109,6 +111,10 @@ impl BlockData {
109111 . to_block_data ( )
110112 . expect ( "Block state ID not found in block mappings file" )
111113 }
114+
115+ pub fn try_to_block_state_id ( & self ) -> Option < BlockStateId > {
116+ Some ( BlockStateId :: from_block_data ( self ) )
117+ }
112118}
113119impl From < BlockData > for BlockStateId {
114120 fn from ( block_data : BlockData ) -> Self {
@@ -144,3 +150,19 @@ impl Default for BlockStateId {
144150 Self ( 0 )
145151 }
146152}
153+
154+ const ITEM_TO_BLOCK_MAPPING_FILE : & str =
155+ include_str ! ( "../../../assets/data/item_to_block_mapping.json" ) ;
156+ pub static ITEM_TO_BLOCK_MAPPING : Lazy < HashMap < i32 , BlockStateId > > = Lazy :: new ( || {
157+ let str_form: HashMap < String , String > = serde_json:: from_str ( ITEM_TO_BLOCK_MAPPING_FILE )
158+ . expect ( "Failed to parse item_to_block_mapping.json" ) ;
159+ str_form
160+ . into_iter ( )
161+ . map ( |( k, v) | {
162+ (
163+ i32:: from_str ( & k) . unwrap ( ) ,
164+ BlockStateId :: new ( u32:: from_str ( & v) . unwrap ( ) ) ,
165+ )
166+ } )
167+ . collect ( )
168+ } ) ;
0 commit comments