fix global registry and add function to easily access minecraft ids
This commit is contained in:
1 file changed
+11
-3
@@ -9,12 +9,11 @@ const REGISTRY_JSON: &str = include_str!("../assets/registries.json");
|
|||||||
#[derive(serde::Deserialize, Debug, Clone, PartialEq, Eq)]
|
#[derive(serde::Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct RegistryElement {
|
pub struct RegistryElement {
|
||||||
default: Option<String>,
|
default: Option<String>,
|
||||||
entries: HashMap<String, u32>,
|
pub entries: HashMap<String, HashMap<String,u32>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref REGISTRY: HashMap<String, RegistryElement> =
|
pub static ref REGISTRY: HashMap<String, RegistryElement> =
|
||||||
serde_json::from_str(REGISTRY_JSON).expect("Could not parse items.json registry.");
|
|
||||||
serde_json::from_str(REGISTRY_JSON).expect("Could not parse registry.json registry.");
|
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")
|
.expect("Invalid Category in registry")
|
||||||
.entries
|
.entries
|
||||||
.get(entry)
|
.get(entry)
|
||||||
|
.map(|p|p.get("protocol_id").unwrap())
|
||||||
.expect("No Entry found")
|
.expect("No Entry found")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,3 +34,11 @@ pub fn get_default<'a>(category: &str) -> Option<&'a str> {
|
|||||||
.default
|
.default
|
||||||
.as_deref()
|
.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())
|
||||||
|
}
|
||||||
Reference in new issue
Block a user