Fix thrown snowball/egg hit animations

+ Snowballs destroy ender crystals
This commit is contained in:
Tiger Wang 2021-04-09 23:19:50 +01:00
parent 2fc86476ae
commit 17c091a97f
4 changed files with 50 additions and 111 deletions

View File

@ -8,21 +8,8 @@
cThrownEggEntity::cThrownEggEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed): cThrownEggEntity::cThrownEggEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed):
Super(pkEgg, a_Creator, a_Pos, 0.25f, 0.25f), Super(pkEgg, a_Creator, a_Pos, a_Speed, 0.25f, 0.25f)
m_DestroyTimer(-1)
{ {
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) void cThrownEggEntity::OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos)
{ {
int TotalDamage = 0; Super::OnHitEntity(a_EntityHit, a_HitPos);
// If entity is an Ender Dragon or Ender Crystal, it is damaged.
if ( int Damage = 0;
(a_EntityHit.IsMob() && (static_cast<cMonster &>(a_EntityHit).GetMobType() == mtEnderDragon)) || if (a_EntityHit.IsMob() && (static_cast<cMonster &>(a_EntityHit).GetMobType() == mtEnderDragon))
a_EntityHit.IsEnderCrystal()
)
{ {
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, GetCreatorUniqueID(), Damage, 1);
a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 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) Super::OnHitSolidBlock(a_HitPos, a_HitFace);
{
m_DestroyTimer--; m_World->BroadcastEntityAnimation(*this, EntityAnimation::EggCracks);
if (m_DestroyTimer == 0)
{ TrySpawnChicken(a_HitPos);
Destroy(); Destroy();
return;
}
}
else
{
Super::Tick(a_Dt, a_Chunk);
}
} }
@ -87,7 +72,3 @@ void cThrownEggEntity::TrySpawnChicken(Vector3d a_HitPos)
m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, mtChicken, true); m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, mtChicken, true);
} }
} }

View File

@ -30,23 +30,13 @@ public: // tolua_export
cThrownEggEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed); cThrownEggEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed);
protected:
// cProjectileEntity overrides:
virtual void OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace) override;
virtual void OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos) override;
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
// Randomly decides whether to spawn a chicken where the egg lands.
void TrySpawnChicken(Vector3d a_HitPos);
private: private:
/** Time in ticks to wait for the hit animation to begin before destroying */ /** Randomly decides whether to spawn a chicken where the egg lands. */
int m_DestroyTimer; void TrySpawnChicken(Vector3d a_HitPos);
// cProjectileEntity overrides:
virtual void OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos) override;
virtual void OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace) override;
} ; // tolua_export } ; // tolua_export

View File

@ -8,19 +8,8 @@
cThrownSnowballEntity::cThrownSnowballEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed): cThrownSnowballEntity::cThrownSnowballEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed):
Super(pkSnowball, a_Creator, a_Pos, 0.25f, 0.25f), Super(pkSnowball, a_Creator, a_Pos, a_Speed, 0.25f, 0.25f)
m_DestroyTimer(-1)
{ {
SetSpeed(a_Speed);
}
void cThrownSnowballEntity::OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace)
{
m_DestroyTimer = 2;
} }
@ -31,42 +20,31 @@ void cThrownSnowballEntity::OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos
{ {
Super::OnHitEntity(a_EntityHit, a_HitPos); Super::OnHitEntity(a_EntityHit, a_HitPos);
int TotalDamage = 0; int Damage = 0;
if (a_EntityHit.IsMob()) if (a_EntityHit.IsMob() && (static_cast<cMonster &>(a_EntityHit).GetMobType() == mtBlaze))
{ {
eMonsterType MobType = static_cast<cMonster &>(a_EntityHit).GetMobType(); // Blazes take 3 damage:
if (MobType == mtBlaze) Damage = 3;
{
TotalDamage = 3;
} }
else if (a_EntityHit.IsEnderCrystal())
{
// Endercrystals are destroyed:
Damage = CeilC(a_EntityHit.GetHealth());
} }
// TODO: If entity is Ender Crystal, destroy it
a_EntityHit.TakeDamage(dtRangedAttack, GetCreatorUniqueID(), TotalDamage, 1);
m_DestroyTimer = 5; a_EntityHit.TakeDamage(dtRangedAttack, GetCreatorUniqueID(), Damage, 1);
} m_World->BroadcastEntityAnimation(*this, EntityAnimation::SnowballPoofs);
void cThrownSnowballEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
if (m_DestroyTimer > 0)
{
m_DestroyTimer--;
if (m_DestroyTimer == 0)
{
Destroy(); Destroy();
return;
}
}
else
{
Super::Tick(a_Dt, a_Chunk);
}
} }
void cThrownSnowballEntity::OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace)
{
Super::OnHitSolidBlock(a_HitPos, a_HitFace);
m_World->BroadcastEntityAnimation(*this, EntityAnimation::SnowballPoofs);
Destroy();
}

View File

@ -30,20 +30,10 @@ public: // tolua_export
cThrownSnowballEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed); cThrownSnowballEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed);
protected:
// cProjectileEntity overrides:
virtual void OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace) override;
virtual void OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos) override;
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
private: private:
/** Time in ticks to wait for the hit animation to begin before destroying */ // cProjectileEntity overrides:
int m_DestroyTimer; virtual void OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos) override;
virtual void OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace) override;
} ; // tolua_export } ; // tolua_export