fix: use the correct health for entities

This commit is contained in:
Alexander Medvedev 2026-01-14 19:55:34 +01:00
parent 1b4b6121eb
commit 6889399e65
3 changed files with 7 additions and 6 deletions

View File

@ -43,7 +43,7 @@ pub fn read_data(id: DataComponent, data: &NbtTag) -> Option<Box<dyn DataCompone
MaxStackSize => Some(MaxStackSizeImpl::read_data(data)?.to_dyn()),
Enchantments => Some(EnchantmentsImpl::read_data(data)?.to_dyn()),
Damage => Some(DamageImpl::read_data(data)?.to_dyn()),
_ => todo!(),
_ => None,
}
}
// Also Pumpkin\pumpkin-protocol\src\codec\data_component.rs

View File

@ -96,11 +96,12 @@ impl LivingEntity {
// TODO: Extract default MOVEMENT_SPEED Entity Attribute
let default_movement_speed = 0.25;
let health = entity.entity_type.max_health.unwrap_or(20.0);
Self {
entity,
hurt_cooldown: AtomicI32::new(0),
last_damage_taken: AtomicCell::new(0.0),
health: AtomicCell::new(20.0),
health: AtomicCell::new(health),
fall_distance: AtomicCell::new(0.0),
death_time: AtomicU8::new(0),
dead: AtomicBool::new(false),

View File

@ -1,6 +1,6 @@
use std::sync::Arc;
use pumpkin_data::entity::{EntityType, MobCategory};
use pumpkin_data::entity::EntityType;
use pumpkin_util::math::vector3::Vector3;
use uuid::Uuid;
@ -28,10 +28,10 @@ pub async fn from_type(
id if id == EntityType::END_CRYSTAL.id => Arc::new(EndCrystalEntity::new(entity)),
// Fallback Entity
_ => {
if entity_type.category == &MobCategory::MISC {
Arc::new(entity)
} else {
if entity_type.max_health.is_some() {
Arc::new(LivingEntity::new(entity))
} else {
Arc::new(entity)
}
}
};