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, 0.25, 0.25),
12  m_DestroyTimer(-1)
13 {
14  SetSpeed(a_Speed);
15 }
16 
17 
18 
19 
20 
22 {
23  TrySpawnChicken(a_HitPos);
24 
25  m_DestroyTimer = 2;
26 }
27 
28 
29 
30 
31 
32 void cThrownEggEntity::OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos)
33 {
34  int TotalDamage = 0;
35  // If entity is an Ender Dragon or Ender Crystal, it is damaged.
36  if (
37  (a_EntityHit.IsMob() && (static_cast<cMonster &>(a_EntityHit).GetMobType() == mtEnderDragon)) ||
38  a_EntityHit.IsEnderCrystal()
39  )
40  {
41  TotalDamage = 1;
42  }
43 
44  TrySpawnChicken(a_HitPos);
45  a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1);
46 
47  m_DestroyTimer = 5;
48 }
49 
50 
51 
52 
53 
54 void cThrownEggEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
55 {
56  if (m_DestroyTimer > 0)
57  {
59  if (m_DestroyTimer == 0)
60  {
61  Destroy();
62  return;
63  }
64  }
65  else
66  {
67  super::Tick(a_Dt, a_Chunk);
68  }
69 }
70 
71 
72 
73 
74 
76 {
77  auto & Random = GetRandomProvider();
78  if (Random.RandBool(0.125))
79  {
80  m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, mtChicken, true);
81  }
82  else if (Random.RandBool(1.0 / 33.0))
83  {
84  m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, mtChicken, true);
85  m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, mtChicken, true);
86  m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, mtChicken, true);
87  m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, mtChicken, true);
88  }
89 }
90 
91 
92 
93 
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:3190
T x
Definition: Vector3.h:17
MTRand & GetRandomProvider()
Returns the current thread&#39;s random number source.
Definition: FastRandom.cpp:20
cWorld * m_World
Definition: Entity.h:620
bool IsEnderCrystal(void) const
Definition: Entity.h:170
bool IsMob(void) const
Definition: Entity.h:173
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
void TrySpawnChicken(Vector3d a_HitPos)
Definition: Chunk.h:49
T y
Definition: Vector3.h:17
virtual void Destroy(bool a_ShouldBroadcast=true)
Destroys the entity and schedules it for memory freeing; if a_ShouldBroadcast is set to true...
Definition: Entity.cpp:219
T z
Definition: Vector3.h:17
int m_DestroyTimer
Time in ticks to wait for the hit animation to begin before destroying.
virtual void OnHitEntity(cEntity &a_EntityHit, Vector3d a_HitPos) override
Called by the physics blocktracer when the entity hits another entity.
void SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ)
Sets the speed of the entity, measured in m / sec.
Definition: Entity.cpp:2091
cThrownEggEntity(cEntity *a_Creator, Vector3d a_Pos, Vector3d a_Speed)
void TakeDamage(cEntity &a_Attacker)
Makes this pawn take damage from an attack by a_Attacker.
Definition: Entity.cpp:269
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc...
Definition: Defines.h:29
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
Definition: Entity.h:73
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...