summaryrefslogtreecommitdiffstats
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
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 '')
-rw-r--r--src/Entities/ProjectileEntity.cpp72
-rw-r--r--src/Entities/ProjectileEntity.h6
-rw-r--r--src/Entities/ThrownEnderPearlEntity.cpp35
-rw-r--r--src/Mobs/Creeper.cpp22
4 files changed, 53 insertions, 82 deletions
diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp
index 50f62b018..334973833 100644
--- a/src/Entities/ProjectileEntity.cpp
+++ b/src/Entities/ProjectileEntity.cpp
@@ -142,7 +142,7 @@ public:
{
if (
(a_Entity == m_Projectile) || // Do not check collisions with self
- (a_Entity == m_Projectile->GetCreator()) // Do not check whoever shot the projectile
+ (a_Entity->GetUniqueID() == m_Projectile->GetCreatorUniqueID()) // Do not check whoever shot the projectile
)
{
// TODO: Don't check creator only for the first 5 ticks
@@ -299,76 +299,6 @@ void cProjectileEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_
-cEntity * cProjectileEntity::GetCreator()
-{
- if (m_CreatorData.m_Name.empty() && (m_CreatorData.m_UniqueID >= 1))
- {
- class cProjectileCreatorCallback : public cEntityCallback
- {
- public:
- cProjectileCreatorCallback(void) :
- m_Entity(NULL)
- {
- }
-
- virtual bool Item(cEntity * a_Entity) override
- {
- m_Entity = a_Entity;
- return true;
- }
-
- cEntity * GetEntity(void)
- {
- return m_Entity;
- }
-
- private:
-
- cEntity * m_Entity;
- };
-
- cProjectileCreatorCallback PCC;
- GetWorld()->DoWithEntityByID(m_CreatorData.m_UniqueID, PCC);
- return PCC.GetEntity();
- }
- else if (!m_CreatorData.m_Name.empty())
- {
- class cProjectileCreatorCallbackForPlayers : public cPlayerListCallback
- {
- public:
- cProjectileCreatorCallbackForPlayers(void) :
- m_Entity(NULL)
- {
- }
-
- virtual bool Item(cPlayer * a_Entity) override
- {
- m_Entity = a_Entity;
- return true;
- }
-
- cPlayer * GetEntity(void)
- {
- return m_Entity;
- }
-
- private:
-
- cPlayer * m_Entity;
- };
-
- cProjectileCreatorCallbackForPlayers PCCFP;
- GetWorld()->FindAndDoWithPlayer(m_CreatorData.m_Name, PCCFP);
- return PCCFP.GetEntity();
- }
-
- return NULL;
-}
-
-
-
-
-
AString cProjectileEntity::GetMCAClassName(void) const
{
switch (m_ProjectileKind)
diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h
index 84eefb9ee..7b38169e2 100644
--- a/src/Entities/ProjectileEntity.h
+++ b/src/Entities/ProjectileEntity.h
@@ -66,10 +66,10 @@ public:
/// Returns the kind of the projectile (fast class identification)
eKind GetProjectileKind(void) const { return m_ProjectileKind; }
- /** Returns the entity who created this projectile through running its Unique ID through cWorld::DoWithEntityByID()
- May return NULL; do not store the returned pointer outside the scope of the tick thread!
+ /** Returns the unique ID of the entity who created this projectile
+ May return an ID <0
*/
- cEntity * GetCreator(void);
+ int GetCreatorUniqueID(void) { return m_CreatorData.m_UniqueID; }
/** Returns the name of the player that created the projectile
Will be empty for non-player creators
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);
}
diff --git a/src/Mobs/Creeper.cpp b/src/Mobs/Creeper.cpp
index a7b97f604..b9041bd5a 100644
--- a/src/Mobs/Creeper.cpp
+++ b/src/Mobs/Creeper.cpp
@@ -67,9 +67,27 @@ void cCreeper::GetDrops(cItems & a_Drops, cEntity * a_Killer)
}
AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER);
- if ((a_Killer != NULL) && (a_Killer->IsProjectile()))
+ if ((a_Killer != NULL) && a_Killer->IsProjectile() && (((cProjectileEntity *)a_Killer)->GetCreatorUniqueID() >= 0))
{
- if (((cMonster *)((cProjectileEntity *)a_Killer)->GetCreator())->GetMobType() == mtSkeleton)
+ class cProjectileCreatorCallback : public cEntityCallback
+ {
+ public:
+ cProjectileCreatorCallback(void)
+ {
+ }
+
+ virtual bool Item(cEntity * a_Entity) override
+ {
+ if (a_Entity->IsMob() && ((cMonster *)a_Entity)->GetMobType() == mtSkeleton)
+ {
+ return true;
+ }
+ return false;
+ }
+ };
+
+ cProjectileCreatorCallback PCC;
+ if (GetWorld()->DoWithEntityByID(((cProjectileEntity *)a_Killer)->GetCreatorUniqueID(), PCC))
{
// 12 music discs. TickRand starts from 0 to 11. Disk IDs start at 2256, so add that. There.
AddRandomDropItem(a_Drops, 1, 1, (short)m_World->GetTickRandomNumber(11) + 2256);