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 
4 #include "FastRandom.h"
5 #include "Mobs/MonsterTypes.h"
7 #include "Player.h"
8 
9 
10 
11 
12 
14  Super(pkEnderPearl, a_Creator, a_Pos, a_Speed, 0.25f, 0.25f)
15 {
16 }
17 
18 
19 
20 
21 
23 {
24  Super::OnHitEntity(a_EntityHit, a_HitPos);
25 
26  int Damage = 0;
27  if (a_EntityHit.IsEnderCrystal())
28  {
29  // Endercrystals are destroyed:
30  Damage = CeilC(a_EntityHit.GetHealth());
31  }
32 
33  a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, 1);
34  TeleportCreator(a_HitPos);
35  Destroy();
36 }
37 
38 
39 
40 
41 
43 {
44  Super::OnHitSolidBlock(a_HitPos, a_HitFace);
45 
46  TeleportCreator(a_HitPos);
47  Destroy();
48 }
49 
50 
51 
52 
53 
55 {
56  if (m_CreatorData.m_Name.empty())
57  {
58  return;
59  }
60 
61 
62 
64  {
65 
66  auto & Random = GetRandomProvider();
67 
68  // 5% chance to spawn an endermite
69  if (Random.RandBool(0.05))
70  {
71  Vector3d PlayerPosition = a_Entity.GetPosition();
72  m_World->SpawnMob(PlayerPosition.x, PlayerPosition.y, PlayerPosition.z, mtEndermite);
73  }
74 
75 
76  // Teleport the creator here, make them take 5 damage:
77  a_Entity.TeleportToCoords(a_HitPos.x, a_HitPos.y + 0.2, a_HitPos.z);
78  a_Entity.TakeDamage(dtEnderPearl, this, 5, 0);
79 
80  return false;
81  });
82 }
@ dtEnderPearl
Definition: Defines.h:262
@ dtRangedAttack
Definition: Defines.h:247
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc.
Definition: Defines.h:38
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
Definition: Entity.h:76
bool IsEnderCrystal(void) const
Definition: Entity.h:159
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
cWorld * GetWorld(void) const
Definition: Entity.h:190
Definition: Player.h:29
virtual void TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ) override
Teleports to the coordinates specified.
Definition: Player.cpp:1404
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...
CreatorData m_CreatorData
The structure for containing the entity ID and name who has created this projectile The ID and / or n...
virtual void OnHitEntity(cEntity &a_EntityHit, Vector3d a_HitPos)
Called by the physics blocktracer when the entity hits another entity.
void TeleportCreator(Vector3d a_HitPos)
Teleports the creator where the ender pearl lands.
cThrownEnderPearlEntity(cEntity *a_Creator, Vector3d a_Pos, Vector3d a_Speed)
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.
T x
Definition: Vector3.h:17
T y
Definition: Vector3.h:17
T z
Definition: Vector3.h:17
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:2303