Skip to content

Commit

Permalink
Added correct bounding boxes per entity
Browse files Browse the repository at this point in the history
  • Loading branch information
OfficialKris committed Dec 27, 2024
1 parent 2b5bfbd commit 84b7382
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
4 changes: 4 additions & 0 deletions pumpkin-world/src/entity/entity_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 16 additions & 7 deletions pumpkin/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -200,16 +201,24 @@ impl Server {
entity_type: EntityType,
) -> (Arc<LivingEntity>, Arc<World>, 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,
Expand Down

0 comments on commit 84b7382

Please sign in to comment.