diff --git a/pumpkin/src/entity/combat.rs b/pumpkin/src/entity/combat.rs index f0d1d185b..d3dd33725 100644 --- a/pumpkin/src/entity/combat.rs +++ b/pumpkin/src/entity/combat.rs @@ -4,7 +4,6 @@ use pumpkin_data::{ particle::Particle, sound::{Sound, SoundCategory}, }; -use pumpkin_protocol::{codec::var_int::VarInt, java::client::play::CEntityVelocity}; use pumpkin_util::math::vector3::Vector3; use crate::{ @@ -51,25 +50,16 @@ impl AttackType { } } -pub async fn handle_knockback(attacker: &Entity, world: &World, victim: &Entity, strength: f64) { +pub fn handle_knockback(attacker: &Entity, victim: &Entity, strength: f64) { let yaw = attacker.yaw.load(); - - let saved_velo = victim.velocity.load(); victim.knockback( strength * 0.5, f64::from((yaw.to_radians()).sin()), f64::from(-(yaw.to_radians()).cos()), ); - let entity_id = VarInt(victim.entity_id); - let victim_velocity = victim.velocity.load(); - - let packet = CEntityVelocity::new(entity_id, victim_velocity); let velocity = attacker.velocity.load(); attacker.velocity.store(velocity.multiply(0.6, 1.0, 0.6)); - - victim.velocity.store(saved_velo); - world.broadcast_packet_all(&packet).await; } pub async fn spawn_sweep_particle(attacker_entity: &Entity, world: &World, pos: &Vector3) { diff --git a/pumpkin/src/entity/living.rs b/pumpkin/src/entity/living.rs index d2cbb042c..35fef99c7 100644 --- a/pumpkin/src/entity/living.rs +++ b/pumpkin/src/entity/living.rs @@ -1154,7 +1154,7 @@ impl EntityBase for LivingEntity { } if self.health.load() <= 0.0 { let time = self.death_time.fetch_add(1, Relaxed); - if time == 20 { + if time >= 20 && self.entity.is_alive() { // Spawn Death particles self.entity .world diff --git a/pumpkin/src/entity/mob/mod.rs b/pumpkin/src/entity/mob/mod.rs index 621d1d8f1..1b459ffe3 100644 --- a/pumpkin/src/entity/mob/mod.rs +++ b/pumpkin/src/entity/mob/mod.rs @@ -21,6 +21,7 @@ pub mod creeper; pub mod drowned; pub mod skeleton; pub mod zombie; +pub mod zombie_villager; pub struct MobEntity { pub living_entity: LivingEntity, diff --git a/pumpkin/src/entity/mob/zombie_villager.rs b/pumpkin/src/entity/mob/zombie_villager.rs new file mode 100644 index 000000000..7c698174d --- /dev/null +++ b/pumpkin/src/entity/mob/zombie_villager.rs @@ -0,0 +1,24 @@ +use super::{Mob, MobEntity}; +use crate::entity::mob::zombie::ZombieEntity; +use crate::entity::{Entity, NBTStorage}; +use std::sync::Arc; + +pub struct ZombieVillagerEntity { + pub mob_entity: Arc, +} + +impl ZombieVillagerEntity { + pub async fn make(entity: Entity) -> Arc { + let mob_entity = ZombieEntity::make(entity).await; + let zombie = Self { mob_entity }; + Arc::new(zombie) + } +} + +impl NBTStorage for ZombieVillagerEntity {} + +impl Mob for ZombieVillagerEntity { + fn get_mob_entity(&self) -> &MobEntity { + &self.mob_entity.mob_entity + } +} diff --git a/pumpkin/src/entity/mod.rs b/pumpkin/src/entity/mod.rs index c35a22cc0..ca1ff47d8 100644 --- a/pumpkin/src/entity/mod.rs +++ b/pumpkin/src/entity/mod.rs @@ -807,58 +807,46 @@ impl Entity { */ } - // Returns whether the entity's eye level is in a wall - async fn tick_block_collisions(&self, caller: &Arc, server: &Server) -> bool { let bounding_box = self.bounding_box.load(); - - let mut suffocating = false; - let aabb = bounding_box.expand(-0.001, -0.001, -0.001); let min = aabb.min_block_pos(); - let max = aabb.max_block_pos(); - let mut eye_level_box = aabb; - let eye_height = f64::from(self.entity_dimension.load().eye_height); - + let mut eye_level_box = aabb; eye_level_box.min.y += eye_height; - eye_level_box.max.y = eye_level_box.min.y; - for x in min.0.x..=max.0.x { - for y in min.0.y..=max.0.y { - for z in min.0.z..=max.0.z { - let pos = BlockPos::new(x, y, z); + let mut suffocating = false; + let pos_iter = BlockPos::iterate(min, max); - let (block, state) = self.world.get_block_and_state(&pos).await; + for pos in pos_iter { + let (block, state) = self.world.get_block_and_state(&pos).await; + if state.is_air() { + continue; + } - let collided = World::check_outline( - &bounding_box, - pos, - state, - !suffocating && state.is_solid(), - |collision_shape: &BoundingBox| { - suffocating = collision_shape.intersects(&eye_level_box); - }, - ); + let check_suffocation = !suffocating && state.is_solid(); - if collided { - self.world - .block_registry - .on_entity_collision( - block, - &self.world, - caller.as_ref(), - &pos, - state, - server, - ) - .await; + let collided = World::check_outline( + &bounding_box, + pos, + state, + check_suffocation, + |collision_shape: &BoundingBox| { + if collision_shape.intersects(&eye_level_box) { + suffocating = true; } - } + }, + ); + + if collided { + self.world + .block_registry + .on_entity_collision(block, &self.world, caller.as_ref(), &pos, state, server) + .await; } } diff --git a/pumpkin/src/entity/player.rs b/pumpkin/src/entity/player.rs index 8fe50f515..31057c690 100644 --- a/pumpkin/src/entity/player.rs +++ b/pumpkin/src/entity/player.rs @@ -690,8 +690,7 @@ impl Player { _ => {} } if config.knockback { - combat::handle_knockback(attacker_entity, world, victim_entity, knockback_strength) - .await; + combat::handle_knockback(attacker_entity, victim_entity, knockback_strength); } } diff --git a/pumpkin/src/entity/type.rs b/pumpkin/src/entity/type.rs index ddaaf8bbd..f097bad31 100644 --- a/pumpkin/src/entity/type.rs +++ b/pumpkin/src/entity/type.rs @@ -11,7 +11,10 @@ use crate::{ armor_stand::ArmorStandEntity, end_crystal::EndCrystalEntity, painting::PaintingEntity, }, living::LivingEntity, - mob::{creeper::CreeperEntity, drowned::DrownedEntity, zombie::ZombieEntity}, + mob::{ + creeper::CreeperEntity, drowned::DrownedEntity, zombie::ZombieEntity, + zombie_villager::ZombieVillagerEntity, + }, passive::wolf::WolfEntity, }, world::World, @@ -28,6 +31,7 @@ pub async fn from_type( let mob: Arc = match entity_type.id { id if id == EntityType::ZOMBIE.id => ZombieEntity::make(entity).await, id if id == EntityType::DROWNED.id => DrownedEntity::make(entity).await, + id if id == EntityType::ZOMBIE_VILLAGER.id => ZombieVillagerEntity::make(entity).await, id if id == EntityType::CREEPER.id => CreeperEntity::make(entity).await, id if id == EntityType::WOLF.id => WolfEntity::make(entity).await, id if id == EntityType::ARMOR_STAND.id => Arc::new(ArmorStandEntity::new(entity)), diff --git a/pumpkin/src/world/mod.rs b/pumpkin/src/world/mod.rs index 34812c8b3..f1253f733 100644 --- a/pumpkin/src/world/mod.rs +++ b/pumpkin/src/world/mod.rs @@ -1044,33 +1044,29 @@ impl World { let mut positions = Vec::new(); - // Include downwards for fences - let min = BlockPos::floored_v(bounding_box.min.add_raw(0.0, -0.50001, 0.0)); - let max = bounding_box.max_block_pos(); + let pos_iter = BlockPos::iterate(min, max); - for x in min.0.x..=max.0.x { - for y in min.0.y..=max.0.y { - for z in min.0.z..=max.0.z { - let pos = BlockPos::new(x, y, z); + for pos in pos_iter { + let state = self.get_block_state(&pos).await; - let state = self.get_block_state(&pos).await; + if state.is_air() { + continue; + } - let collided = Self::check_collision( - &bounding_box, - pos, - state, - true, - |collision_shape: &BoundingBox| { - collisions.push(*collision_shape); - }, - ); + let collided = Self::check_collision( + &bounding_box, + pos, + state, + true, + |collision_shape: &BoundingBox| { + collisions.push(*collision_shape); + }, + ); - if collided { - positions.push((collisions.len(), pos)); - } - } + if collided { + positions.push((collisions.len(), pos)); } }