fix: fixed entity knockback
This commit is contained in:
1 parent
2461f85978
commit
bcdde4526f
8 files changed
+75
-73
No files matched your search
@@ -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<f64>) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<ZombieEntity>,
|
||||
}
|
||||
|
||||
impl ZombieVillagerEntity {
|
||||
pub async fn make(entity: Entity) -> Arc<Self> {
|
||||
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
|
||||
}
|
||||
}
|
||||
+25
-37
@@ -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<dyn EntityBase>, 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<dyn EntityBase> = 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)),
|
||||
|
||||
+17
-21
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user