mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-30 20:14:23 +00:00
fix global registry and add function to easily access minecraft ids
This commit is contained in:
@@ -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<String>,
|
||||
entries: HashMap<String, u32>,
|
||||
pub entries: HashMap<String, HashMap<String,u32>>,
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref REGISTRY: HashMap<String, RegistryElement> =
|
||||
serde_json::from_str(REGISTRY_JSON).expect("Could not parse items.json registry.");
|
||||
pub static ref REGISTRY: HashMap<String, RegistryElement> =
|
||||
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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user