Cuberite
A lightweight, fast and extensible game server for Minecraft
ThrownEnderPearlEntity.cpp
Go to the documentation of this file.
1 
2 #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
3 
5 #include "Player.h"
6 
7 
8 
9 
10 
12  super(pkEnderPearl, a_Creator, a_Pos, 0.25, 0.25),
13  m_DestroyTimer(-1)
14 {
15  SetSpeed(a_Speed);
16 }
17 
18 
19 
20 
21 
23 {
24  // TODO: Tweak a_HitPos based on block face.
25  TeleportCreator(a_HitPos);
26 
27  m_DestroyTimer = 2;
28 }
29 
30 
31 
32 
33 
35 {
36  int TotalDamage = 0;
37  // TODO: If entity is Ender Crystal, destroy it
38 
39  TeleportCreator(a_HitPos);
40  a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1);
41 
42  m_DestroyTimer = 5;
43 }
44 
45 
46 
47 
48 
49 void cThrownEnderPearlEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
50 {
51  if (m_DestroyTimer > 0)
52  {
54  if (m_DestroyTimer == 0)
55  {
56  Destroy();
57  return;
58  }
59  }
60  else
61  {
62  super::Tick(a_Dt, a_Chunk);
63  }
64 }
65 
66 
67 
68 
69 
71 {
72  if (m_CreatorData.m_Name.empty())
73  {
74  return;
75  }
76 
78  {
79  // Teleport the creator here, make them take 5 damage:
80  a_Entity.TeleportToCoords(a_HitPos.x, a_HitPos.y + 0.2, a_HitPos.z);
81  a_Entity.TakeDamage(dtEnderPearl, this, 5, 0);
82  return true;
83  }
84  );
85 }
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...
CreatorData m_CreatorData
The structure for containing the entity ID and name who has created this projectile The ID and / or n...
Definition: Player.h:27
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
cThrownEnderPearlEntity(cEntity *a_Creator, Vector3d a_Pos, Vector3d a_Speed)
Definition: Chunk.h:49
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
void TeleportCreator(Vector3d a_HitPos)
Teleports the creator where the ender pearl lands.
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.
bool FindAndDoWithPlayer(const AString &a_PlayerNameHint, cPlayerListCallback a_Callback)
Finds a player from a partial or complete player name and calls the callback - case-insensitive.
Definition: World.cpp:2586
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
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
Definition: Entity.h:73
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
cWorld * GetWorld(void) const
Definition: Entity.h:201