Skip to content

Commit

Permalink
Fixed entity registry
Browse files Browse the repository at this point in the history
  • Loading branch information
OfficialKris committed Dec 27, 2024
1 parent 80d5528 commit 2b5bfbd
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions pumpkin-world/src/entity/entity_registry.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
use std::{collections::HashMap, sync::LazyLock};

use serde::Deserialize;

const ENTITIES_JSON: &str = include_str!("../../../assets/entities.json");

pub static ENTITIES: LazyLock<Vec<String>> = LazyLock::new(|| {
pub static ENTITIES: LazyLock<HashMap<String, Entity>> = LazyLock::new(|| {
serde_json::from_str(ENTITIES_JSON).expect("Could not parse entity.json registry.")
});

pub static ENTITIES_BY_ID: LazyLock<HashMap<String, u16>> = LazyLock::new(|| {
let mut map = HashMap::new();
for (i, entity_name) in ENTITIES.iter().enumerate() {
map.insert(entity_name.clone(), i as u16);
for (entity_name, entity) in ENTITIES.iter() {
map.insert(entity_name.clone(), entity.id);
}
map
});

pub fn get_entity_id(name: &str) -> Option<&u16> {
ENTITIES_BY_ID.get(&name.replace("minecraft:", ""))
}

#[derive(Deserialize, Clone, Debug)]
pub struct Entity {
pub id: u16,
pub max_health: Option<f64>,
pub attackable: bool,
pub summonable: bool,
pub fire_immune: bool,
pub dimension: Vec<f32>,
}

0 comments on commit 2b5bfbd

Please sign in to comment.