Cuberite
A lightweight, fast and extensible game server for Minecraft
ThrownEggEntity.cpp
Go to the documentation of this file.
1 #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
2 
3 #include "ThrownEggEntity.h"
4 #include "../World.h"
5 
6 
7 
8 
9 
11  Super(pkEgg, a_Creator, a_Pos, a_Speed, 0.25f, 0.25f)
12 {
13 }
14 
15 
16 
17 
18 
19 void cThrownEggEntity::OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos)
20 {
21  Super::OnHitEntity(a_EntityHit, a_HitPos);
22 
23  int Damage = 0;
24  if (a_EntityHit.IsMob() && (static_cast<cMonster &>(a_EntityHit).GetMobType() == mtEnderDragon))
25  {
26  // Enderdragons take 1 damage:
27  Damage = 1;
28  }
29  else if (a_EntityHit.IsEnderCrystal())
30  {
31  // Endercrystals are destroyed:
32  Damage = CeilC(a_EntityHit.GetHealth());
33  }
34 
35  a_EntityHit.TakeDamage(dtRangedAttack, GetCreatorUniqueID(), Damage, 1);
37 
38  TrySpawnChicken(a_HitPos);
39  Destroy();
40 }
41 
42 
43 
44 
45 
47 {
48  Super::OnHitSolidBlock(a_HitPos, a_HitFace);
49 
51 
52  TrySpawnChicken(a_HitPos);
53  Destroy();
54 }
55 
56 
57 
58 
59 
61 {
62  auto & Random = GetRandomProvider();
63  if (Random.RandBool(0.125))
64  {
65  m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, mtChicken, true);
66  }
67  else if (Random.RandBool(1.0 / 33.0))
68  {
69  m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, mtChicken, true);
70  m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, mtChicken, true);
71  m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, mtChicken, true);
72  m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, mtChicken, true);
73  }
74 }
@ dtRangedAttack
Definition: Defines.h:247
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc.
Definition: Defines.h:38
MTRand & GetRandomProvider()
Returns the current thread's random number source.
Definition: FastRandom.cpp:12
std::enable_if< std::is_arithmetic< T >::value, C >::type CeilC(T a_Value)
Ceils a value, then casts it to C (an int by default).
Definition: Globals.h:354
@ mtEnderDragon
Definition: MonsterTypes.h:26
@ mtChicken
Definition: MonsterTypes.h:18
Definition: Entity.h:76
bool IsEnderCrystal(void) const
Definition: Entity.h:159
cWorld * m_World
Definition: Entity.h:624
void Destroy()
Destroys the entity, schedules it for memory freeing and broadcasts the DestroyEntity packet.
Definition: Entity.cpp:243
void TakeDamage(cEntity &a_Attacker)
Makes this pawn take damage from an attack by a_Attacker.
Definition: Entity.cpp:272
float GetHealth(void) const
Returns the health of this entity.
Definition: Entity.h:367
bool IsMob(void) const
Definition: Entity.h:162
UInt32 GetCreatorUniqueID(void) const
Returns the unique ID of the entity who created this projectile May return an ID <0.
virtual void OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace)
Called by the physics blocktracer when the entity hits a solid block, the hit position and the face h...
virtual void OnHitEntity(cEntity &a_EntityHit, Vector3d a_HitPos)
Called by the physics blocktracer when the entity hits another entity.
virtual void OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace) override
Called by the physics blocktracer when the entity hits a solid block, the hit position and the face h...
virtual void OnHitEntity(cEntity &a_EntityHit, Vector3d a_HitPos) override
Called by the physics blocktracer when the entity hits another entity.
cThrownEggEntity(cEntity *a_Creator, Vector3d a_Pos, Vector3d a_Speed)
void TrySpawnChicken(Vector3d a_HitPos)
Randomly decides whether to spawn a chicken where the egg lands.
eMonsterType GetMobType(void) const
Definition: Monster.h:70
T x
Definition: Vector3.h:17
T y
Definition: Vector3.h:17
T z
Definition: Vector3.h:17
virtual UInt32 SpawnMob(double a_PosX, double a_PosY, double a_PosZ, eMonsterType a_MonsterType, bool a_Baby=false) override
Spawns a mob of the specified type.
Definition: World.cpp:2897
virtual void BroadcastEntityAnimation(const cEntity &a_Entity, EntityAnimation a_Animation, const cClientHandle *a_Exclude=nullptr) override