summaryrefslogtreecommitdiffstats
path: root/src/Entities/ThrownSnowballEntity.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2021-04-10 00:19:50 +0200
committerTiger Wang <ziwei.tiger@outlook.com>2021-04-12 23:35:07 +0200
commit17c091a97f35ac4fceb6facea1b65588f498e3a0 (patch)
tree7a1e2eee7970abeb2794cc67b5b50497d9a9e1f1 /src/Entities/ThrownSnowballEntity.cpp
parentImprove bed handling robustness (diff)
downloadcuberite-17c091a97f35ac4fceb6facea1b65588f498e3a0.tar
cuberite-17c091a97f35ac4fceb6facea1b65588f498e3a0.tar.gz
cuberite-17c091a97f35ac4fceb6facea1b65588f498e3a0.tar.bz2
cuberite-17c091a97f35ac4fceb6facea1b65588f498e3a0.tar.lz
cuberite-17c091a97f35ac4fceb6facea1b65588f498e3a0.tar.xz
cuberite-17c091a97f35ac4fceb6facea1b65588f498e3a0.tar.zst
cuberite-17c091a97f35ac4fceb6facea1b65588f498e3a0.zip
Diffstat (limited to 'src/Entities/ThrownSnowballEntity.cpp')
-rw-r--r--src/Entities/ThrownSnowballEntity.cpp58
1 files changed, 18 insertions, 40 deletions
diff --git a/src/Entities/ThrownSnowballEntity.cpp b/src/Entities/ThrownSnowballEntity.cpp
index 63068e69d..ab8a5f012 100644
--- a/src/Entities/ThrownSnowballEntity.cpp
+++ b/src/Entities/ThrownSnowballEntity.cpp
@@ -8,19 +8,8 @@
cThrownSnowballEntity::cThrownSnowballEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed):
- Super(pkSnowball, a_Creator, a_Pos, 0.25f, 0.25f),
- m_DestroyTimer(-1)
+ Super(pkSnowball, a_Creator, a_Pos, a_Speed, 0.25f, 0.25f)
{
- 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);
- int TotalDamage = 0;
- if (a_EntityHit.IsMob())
+ int Damage = 0;
+ if (a_EntityHit.IsMob() && (static_cast<cMonster &>(a_EntityHit).GetMobType() == mtBlaze))
+ {
+ // Blazes take 3 damage:
+ Damage = 3;
+ }
+ else if (a_EntityHit.IsEnderCrystal())
{
- eMonsterType MobType = static_cast<cMonster &>(a_EntityHit).GetMobType();
- if (MobType == mtBlaze)
- {
- TotalDamage = 3;
- }
+ // 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);
+ Destroy();
}
-void cThrownSnowballEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
+void cThrownSnowballEntity::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::SnowballPoofs);
+ Destroy();
+}