1
0

Rewrite explosion knock back (#4251)

1. Base knockback on an entity's bounding box intersection with the explosion 
2. Armor blast protection reduces knockback
3. Don't apply knockback to players flying in creative mode

Fixes #4139
This commit is contained in:
changyong guo
2018-07-23 17:24:00 +08:00
committed by peterbell10
parent 7b0db672d1
commit 01e72ddb65
7 changed files with 129 additions and 20 deletions

View File

@@ -1814,10 +1814,21 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_
a_Entity.TakeDamage(dtExplosion, nullptr, static_cast<int>((1 / DistanceFromExplosion.Length()) * 6 * ExplosionSizeInt), 0);
}
// Apply force to entities around the explosion - code modified from World.cpp DoExplosionAt()
DistanceFromExplosion.Normalize();
DistanceFromExplosion *= ExplosionSizeInt * ExplosionSizeInt;
a_Entity.AddSpeed(DistanceFromExplosion);
double Length = DistanceFromExplosion.Length();
if (Length <= ExplosionSizeInt) // Entity is impacted by explosion
{
float EntityExposure = a_Entity.GetExplosionExposureRate(ExplosionPos, ExplosionSizeInt);
// Exposure reduced by armor
EntityExposure = EntityExposure * (1.0f - a_Entity.GetEnchantmentBlastKnockbackReduction());
double Impact = (1 - ((Length / ExplosionSizeInt) / 2)) * EntityExposure;
DistanceFromExplosion.Normalize();
DistanceFromExplosion *= Impact;
a_Entity.AddSpeed(DistanceFromExplosion);
}
return false;
}