diff --git a/pumpkin-world/src/global_registry.rs b/pumpkin-world/src/global_registry.rs index fd88c08aa..150562c6b 100644 --- a/pumpkin-world/src/global_registry.rs +++ b/pumpkin-world/src/global_registry.rs @@ -9,12 +9,11 @@ const REGISTRY_JSON: &str = include_str!("../assets/registries.json"); #[derive(serde::Deserialize, Debug, Clone, PartialEq, Eq)] pub struct RegistryElement { default: Option, - entries: HashMap, + pub entries: HashMap>, } lazy_static! { - static ref REGISTRY: HashMap = - serde_json::from_str(REGISTRY_JSON).expect("Could not parse items.json registry."); + pub static ref REGISTRY: HashMap = serde_json::from_str(REGISTRY_JSON).expect("Could not parse registry.json registry."); } @@ -24,6 +23,7 @@ pub fn get_protocol_id(category: &str, entry: &str) -> u32 { .expect("Invalid Category in registry") .entries .get(entry) + .map(|p|p.get("protocol_id").unwrap()) .expect("No Entry found") } @@ -34,3 +34,11 @@ pub fn get_default<'a>(category: &str) -> Option<&'a str> { .default .as_deref() } + +pub fn find_minecraft_id(category: &str, protocol_id: u32) -> Option<&str> { + REGISTRY.get(category)? + .entries + .iter() + .find(|(_,other_protocol_id)|*other_protocol_id.get("protocol_id").unwrap()==protocol_id) + .map(|(id,_)|id.as_str()) +}