From 17c091a97f35ac4fceb6facea1b65588f498e3a0 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 9 Apr 2021 23:19:50 +0100 Subject: Fix thrown snowball/egg hit animations + Snowballs destroy ender crystals --- src/Entities/ThrownEggEntity.cpp | 65 ++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 42 deletions(-) (limited to 'src/Entities/ThrownEggEntity.cpp') diff --git a/src/Entities/ThrownEggEntity.cpp b/src/Entities/ThrownEggEntity.cpp index b8289b64b..44cfda937 100644 --- a/src/Entities/ThrownEggEntity.cpp +++ b/src/Entities/ThrownEggEntity.cpp @@ -8,21 +8,8 @@ cThrownEggEntity::cThrownEggEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed): - Super(pkEgg, a_Creator, a_Pos, 0.25f, 0.25f), - m_DestroyTimer(-1) + Super(pkEgg, a_Creator, a_Pos, a_Speed, 0.25f, 0.25f) { - SetSpeed(a_Speed); -} - - - - - -void cThrownEggEntity::OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace) -{ - TrySpawnChicken(a_HitPos); - - m_DestroyTimer = 2; } @@ -31,41 +18,39 @@ void cThrownEggEntity::OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace) void cThrownEggEntity::OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos) { - int TotalDamage = 0; - // If entity is an Ender Dragon or Ender Crystal, it is damaged. - if ( - (a_EntityHit.IsMob() && (static_cast(a_EntityHit).GetMobType() == mtEnderDragon)) || - a_EntityHit.IsEnderCrystal() - ) + Super::OnHitEntity(a_EntityHit, a_HitPos); + + int Damage = 0; + if (a_EntityHit.IsMob() && (static_cast(a_EntityHit).GetMobType() == mtEnderDragon)) { - TotalDamage = 1; + // Enderdragons take 1 damage: + Damage = 1; + } + else if (a_EntityHit.IsEnderCrystal()) + { + // Endercrystals are destroyed: + Damage = CeilC(a_EntityHit.GetHealth()); } - TrySpawnChicken(a_HitPos); - a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); + a_EntityHit.TakeDamage(dtRangedAttack, GetCreatorUniqueID(), Damage, 1); + m_World->BroadcastEntityAnimation(*this, EntityAnimation::EggCracks); - m_DestroyTimer = 5; + TrySpawnChicken(a_HitPos); + Destroy(); } -void cThrownEggEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) +void cThrownEggEntity::OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace) { - if (m_DestroyTimer > 0) - { - m_DestroyTimer--; - if (m_DestroyTimer == 0) - { - Destroy(); - return; - } - } - else - { - Super::Tick(a_Dt, a_Chunk); - } + Super::OnHitSolidBlock(a_HitPos, a_HitFace); + + m_World->BroadcastEntityAnimation(*this, EntityAnimation::EggCracks); + + TrySpawnChicken(a_HitPos); + Destroy(); } @@ -87,7 +72,3 @@ void cThrownEggEntity::TrySpawnChicken(Vector3d a_HitPos) m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, mtChicken, true); } } - - - - -- cgit v1.2.3