use std::sync::LazyLock; use serde::Deserialize; pub static BLOCKS: LazyLock = LazyLock::new(|| { serde_json::from_str(include_str!("../../../assets/blocks.json")) .expect("Could not parse blocks.json registry.") }); pub fn get_block(registry_id: &str) -> Option<&Block> { BLOCKS .blocks .iter() .find(|&block| block.name == registry_id) } pub fn get_block_by_id<'a>(id: u16) -> Option<&'a Block> { BLOCKS.blocks.iter().find(|&block| block.id == id) } pub fn get_block_by_item<'a>(item_id: u16) -> Option<&'a Block> { BLOCKS.blocks.iter().find(|&block| block.item_id == item_id) } #[expect(dead_code)] #[derive(Deserialize, Clone, Debug)] pub struct TopLevel { pub blocks: Vec, shapes: Vec, block_entity_types: Vec, } #[derive(Deserialize, Clone, Debug)] pub struct Block { pub id: u16, pub item_id: u16, pub wall_variant_id: Option, pub translation_key: String, pub name: String, pub properties: Vec, pub default_state_id: u16, pub states: Vec, } #[expect(dead_code)] #[derive(Deserialize, Clone, Debug)] struct BlockEntityKind { id: u32, ident: String, name: String, } #[expect(dead_code)] #[derive(Deserialize, Clone, Debug)] pub struct Property { name: String, values: Vec, } #[derive(Deserialize, Clone, Debug)] pub struct State { pub id: u16, pub air: bool, pub luminance: u8, pub burnable: bool, pub opacity: Option, pub replaceable: bool, pub collision_shapes: Vec, pub block_entity_type: Option, } #[expect(dead_code)] #[derive(Deserialize, Clone, Debug)] struct Shape { min_x: f64, min_y: f64, min_z: f64, max_x: f64, max_y: f64, max_z: f64, }