summaryrefslogtreecommitdiffstats
path: root/src/Entities/Floater.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/Floater.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 'src/Entities/Floater.cpp')
-rw-r--r--src/Entities/Floater.cpp45
1 files changed, 37 insertions, 8 deletions
diff --git a/src/Entities/Floater.cpp b/src/Entities/Floater.cpp
index de5824068..eeaa6cf3d 100644
--- a/src/Entities/Floater.cpp
+++ b/src/Entities/Floater.cpp
@@ -13,7 +13,8 @@
////////////////////////////////////////////////////////////////////////////////
// cFloaterEntityCollisionCallback
-class cFloaterEntityCollisionCallback
+class cFloaterEntityCollisionCallback :
+ public cEntityCallback
{
public:
cFloaterEntityCollisionCallback(cFloater * a_Floater, const Vector3d & a_Pos, const Vector3d & a_NextPos) :
@@ -24,14 +25,14 @@ public:
m_HitEntity(nullptr)
{
}
- bool operator () (cEntity & a_Entity)
+ virtual bool Item(cEntity * a_Entity) override
{
- if (!a_Entity.IsMob()) // Floaters can only pull mobs not other entities.
+ if (!a_Entity->IsMob()) // Floaters can only pull mobs not other entities.
{
return false;
}
- cBoundingBox EntBox(a_Entity.GetPosition(), a_Entity.GetWidth() / 2, a_Entity.GetHeight());
+ cBoundingBox EntBox(a_Entity->GetPosition(), a_Entity->GetWidth() / 2, a_Entity->GetHeight());
double LineCoeff;
eBlockFace Face;
@@ -46,7 +47,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
@@ -74,6 +75,32 @@ protected:
+////////////////////////////////////////////////////////////////////////////////
+// cFloaterCheckEntityExist
+class cFloaterCheckEntityExist :
+ public cEntityCallback
+{
+public:
+ cFloaterCheckEntityExist(void) :
+ m_EntityExists(false)
+ {
+ }
+
+ bool Item(cEntity * a_Entity) override
+ {
+ m_EntityExists = true;
+ return false;
+ }
+
+ bool DoesExist(void) const { return m_EntityExists; }
+protected:
+ bool m_EntityExists;
+} ;
+
+
+
+
+
cFloater::cFloater(double a_X, double a_Y, double a_Z, Vector3d a_Speed, UInt32 a_PlayerID, int a_CountDownTime) :
cEntity(etFloater, a_X, a_Y, a_Z, 0.2, 0.2),
m_BitePos(Vector3d(a_X, a_Y, a_Z)),
@@ -173,16 +200,18 @@ void cFloater::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
}
}
- if (!m_World->DoWithEntityByID(m_PlayerID, [](cEntity &) { return true; })) // The owner doesn't exist anymore. Destroy the floater entity.
+ cFloaterCheckEntityExist EntityCallback;
+ m_World->DoWithEntityByID(m_PlayerID, EntityCallback);
+ if (!EntityCallback.DoesExist()) // The owner doesn't exist anymore. Destroy the floater entity.
{
Destroy(true);
}
if (m_AttachedMobID != cEntity::INVALID_ID)
{
- if (!m_World->DoWithEntityByID(m_AttachedMobID, [](cEntity &) { return true; }))
+ m_World->DoWithEntityByID(m_AttachedMobID, EntityCallback); // The mob the floater was attached to doesn't exist anymore.
+ if (!EntityCallback.DoesExist())
{
- // The mob the floater was attached to doesn't exist anymore.
m_AttachedMobID = cEntity::INVALID_ID;
}
}