summaryrefslogtreecommitdiffstats
path: root/src/Entities/ProjectileEntity.cpp
diff options
context:
space:
mode:
authorLogicParrot <LogicParrot@users.noreply.github.com>2017-09-02 09:45:06 +0200
committerAlexander Harkness <me@bearbin.net>2017-09-02 09:50:23 +0200
commit49c443896dcac8c4eaf08c4024e8bd2366ad899a (patch)
treeb1ec46cab2b4e5731860c7136f1bbfca6fe9d458 /src/Entities/ProjectileEntity.cpp
parentSetSwimState now takes into account head height (diff)
downloadcuberite-49c443896dcac8c4eaf08c4024e8bd2366ad899a.tar
cuberite-49c443896dcac8c4eaf08c4024e8bd2366ad899a.tar.gz
cuberite-49c443896dcac8c4eaf08c4024e8bd2366ad899a.tar.bz2
cuberite-49c443896dcac8c4eaf08c4024e8bd2366ad899a.tar.lz
cuberite-49c443896dcac8c4eaf08c4024e8bd2366ad899a.tar.xz
cuberite-49c443896dcac8c4eaf08c4024e8bd2366ad899a.tar.zst
cuberite-49c443896dcac8c4eaf08c4024e8bd2366ad899a.zip
Diffstat (limited to '')
-rw-r--r--src/Entities/ProjectileEntity.cpp40
1 files changed, 24 insertions, 16 deletions
diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp
index 13ebe31bc..c2a1f782d 100644
--- a/src/Entities/ProjectileEntity.cpp
+++ b/src/Entities/ProjectileEntity.cpp
@@ -126,7 +126,8 @@ protected:
////////////////////////////////////////////////////////////////////////////////
// cProjectileEntityCollisionCallback:
-class cProjectileEntityCollisionCallback
+class cProjectileEntityCollisionCallback :
+ public cEntityCallback
{
public:
cProjectileEntityCollisionCallback(cProjectileEntity * a_Projectile, const Vector3d & a_Pos, const Vector3d & a_NextPos) :
@@ -139,11 +140,11 @@ public:
}
- bool operator () (cEntity & a_Entity)
+ virtual bool Item(cEntity * a_Entity) override
{
if (
- (&a_Entity == m_Projectile) || // Do not check collisions with self
- (a_Entity.GetUniqueID() == m_Projectile->GetCreatorUniqueID()) // Do not check whoever shot the projectile
+ (a_Entity == m_Projectile) || // Do not check collisions with self
+ (a_Entity->GetUniqueID() == m_Projectile->GetCreatorUniqueID()) // Do not check whoever shot the projectile
)
{
// Don't check creator only for the first 5 ticks so that projectiles can collide with the creator
@@ -153,7 +154,7 @@ public:
}
}
- cBoundingBox EntBox(a_Entity.GetPosition(), a_Entity.GetWidth() / 2, a_Entity.GetHeight());
+ cBoundingBox EntBox(a_Entity->GetPosition(), a_Entity->GetWidth() / 2, a_Entity->GetHeight());
// Instead of colliding the bounding box with another bounding box in motion, we collide an enlarged bounding box with a hairline.
// The results should be good enough for our purposes
@@ -167,20 +168,20 @@ public:
}
if (
- !a_Entity.IsMob() &&
- !a_Entity.IsMinecart() &&
+ !a_Entity->IsMob() &&
+ !a_Entity->IsMinecart() &&
(
- !a_Entity.IsPlayer() ||
- static_cast<cPlayer &>(a_Entity).IsGameModeSpectator()
+ !a_Entity->IsPlayer() ||
+ static_cast<cPlayer *>(a_Entity)->IsGameModeSpectator()
) &&
- !a_Entity.IsBoat()
+ !a_Entity->IsBoat()
)
{
// Not an entity that interacts with a projectile
return false;
}
- if (cPluginManager::Get()->CallHookProjectileHitEntity(*m_Projectile, a_Entity))
+ if (cPluginManager::Get()->CallHookProjectileHitEntity(*m_Projectile, *a_Entity))
{
// A plugin disagreed.
return false;
@@ -190,7 +191,7 @@ public:
{
// The entity is closer than anything we've stored so far, replace it as the potential victim
m_MinCoeff = LineCoeff;
- m_HitEntity = &a_Entity;
+ m_HitEntity = a_Entity;
}
// Don't break the enumeration, we want all the entities
@@ -326,13 +327,20 @@ void cProjectileEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_Hi
// If we were created by a player and we hit a pawn, notify attacking player's wolves
if (a_EntityHit.IsPawn() && (GetCreatorName() != ""))
{
- auto EntityHit = static_cast<cPawn *>(&a_EntityHit);
- m_World->DoWithEntityByID(GetCreatorUniqueID(), [=](cEntity & a_Hitter)
+ class cNotifyWolves : public cEntityCallback
+ {
+ public:
+ cPawn * m_EntityHit;
+
+ virtual bool Item(cEntity * a_Hitter) override
{
- static_cast<cPlayer&>(a_Hitter).NotifyNearbyWolves(EntityHit, true);
+ static_cast<cPlayer*>(a_Hitter)->NotifyNearbyWolves(m_EntityHit, true);
return true;
}
- );
+ } Callback;
+
+ Callback.m_EntityHit = static_cast<cPawn*>(&a_EntityHit);
+ m_World->DoWithEntityByID(GetCreatorUniqueID(), Callback);
}
}