summaryrefslogtreecommitdiffstats
path: root/src/Entities/ThrownEnderPearlEntity.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-07-05 23:59:22 +0200
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-07-05 23:59:22 +0200
commit460d6bd0cbb799a6e68f1bc264f55c3d89eb8206 (patch)
tree5d5d769e0e624f20c40c90cfb32045e01ec4e3e4 /src/Entities/ThrownEnderPearlEntity.cpp
parentCrash and compile fix (diff)
downloadcuberite-460d6bd0cbb799a6e68f1bc264f55c3d89eb8206.tar
cuberite-460d6bd0cbb799a6e68f1bc264f55c3d89eb8206.tar.gz
cuberite-460d6bd0cbb799a6e68f1bc264f55c3d89eb8206.tar.bz2
cuberite-460d6bd0cbb799a6e68f1bc264f55c3d89eb8206.tar.lz
cuberite-460d6bd0cbb799a6e68f1bc264f55c3d89eb8206.tar.xz
cuberite-460d6bd0cbb799a6e68f1bc264f55c3d89eb8206.tar.zst
cuberite-460d6bd0cbb799a6e68f1bc264f55c3d89eb8206.zip
Diffstat (limited to 'src/Entities/ThrownEnderPearlEntity.cpp')
-rw-r--r--src/Entities/ThrownEnderPearlEntity.cpp35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/Entities/ThrownEnderPearlEntity.cpp b/src/Entities/ThrownEnderPearlEntity.cpp
index aeb727205..c7407e6ae 100644
--- a/src/Entities/ThrownEnderPearlEntity.cpp
+++ b/src/Entities/ThrownEnderPearlEntity.cpp
@@ -1,6 +1,7 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "ThrownEnderPearlEntity.h"
+#include "Player.h"
@@ -46,12 +47,34 @@ void cThrownEnderPearlEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d
void cThrownEnderPearlEntity::TeleportCreator(const Vector3d & a_HitPos)
{
- cEntity * Creator = GetCreator();
-
- // Teleport the creator here, make them take 5 damage:
- if (Creator != NULL)
+ if (m_CreatorData.m_Name.empty())
{
- Creator->TeleportToCoords(a_HitPos.x, a_HitPos.y + 0.2, a_HitPos.z);
- Creator->TakeDamage(dtEnderPearl, this, 5, 0);
+ return;
}
+
+ class cProjectileCreatorCallbackForPlayers : public cPlayerListCallback
+ {
+ public:
+ cProjectileCreatorCallbackForPlayers(cEntity * a_Attacker, Vector3i a_HitPos) :
+ m_Attacker(a_Attacker),
+ m_HitPos(a_HitPos)
+ {
+ }
+
+ virtual bool Item(cPlayer * a_Entity) override
+ {
+ // Teleport the creator here, make them take 5 damage:
+ a_Entity->TeleportToCoords(m_HitPos.x, m_HitPos.y + 0.2, m_HitPos.z);
+ a_Entity->TakeDamage(dtEnderPearl, m_Attacker, 5, 0);
+ return true;
+ }
+
+ private:
+
+ cEntity * m_Attacker;
+ Vector3i m_HitPos;
+ };
+
+ cProjectileCreatorCallbackForPlayers PCCFP(this, a_HitPos);
+ GetWorld()->FindAndDoWithPlayer(m_CreatorData.m_Name, PCCFP);
}