diff --git a/pumpkin-world/src/entity/entity_registry.rs b/pumpkin-world/src/entity/entity_registry.rs index 3eb2971b..d0bbdd73 100644 --- a/pumpkin-world/src/entity/entity_registry.rs +++ b/pumpkin-world/src/entity/entity_registry.rs @@ -20,6 +20,10 @@ pub fn get_entity_id(name: &str) -> Option<&u16> { ENTITIES_BY_ID.get(&name.replace("minecraft:", "")) } +pub fn get_entity_by_id<'a>(entity_id: u16) -> Option<&'a Entity> { + ENTITIES.values().find(|&entity| entity.id == entity_id) +} + #[derive(Deserialize, Clone, Debug)] pub struct Entity { pub id: u16, diff --git a/pumpkin/src/server/mod.rs b/pumpkin/src/server/mod.rs index 1e90ec61..3a465cba 100644 --- a/pumpkin/src/server/mod.rs +++ b/pumpkin/src/server/mod.rs @@ -13,6 +13,7 @@ use pumpkin_protocol::client::login::CEncryptionRequest; use pumpkin_protocol::{client::config::CPluginMessage, ClientPacket}; use pumpkin_registry::{DimensionType, Registry}; use pumpkin_world::dimension::Dimension; +use pumpkin_world::entity::entity_registry::get_entity_by_id; use rand::prelude::SliceRandom; use std::collections::HashMap; use std::{ @@ -200,16 +201,24 @@ impl Server { entity_type: EntityType, ) -> (Arc, Arc, Uuid) { let entity_id = self.new_entity_id(); - // Basically the default world - // TODO: select default from config + // TODO: select current let world = &self.worlds[0]; - // TODO: set per each mob and update per state (death) - let bounding_box_size = BoundingBoxSize { - width: 0.6, - height: 1.8, - }; + // TODO: this should be resolved to a integer using a macro when calling this function + let bounding_box_size: BoundingBoxSize; + if let Some(entity) = get_entity_by_id(entity_type.clone() as u16) { + bounding_box_size = BoundingBoxSize { + width: f64::from(entity.dimension[0]), + height: f64::from(entity.dimension[1]), + }; + } else { + bounding_box_size = BoundingBoxSize { + width: 0.6, + height: 1.8, + }; + } + // TODO: standing eye height should be per mob let new_uuid = uuid::Uuid::new_v4(); let mob = Arc::new(LivingEntity::new(Entity::new( entity_id,