summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Ocelot.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/Mobs/Ocelot.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/Mobs/Ocelot.cpp61
1 files changed, 37 insertions, 24 deletions
diff --git a/src/Mobs/Ocelot.cpp b/src/Mobs/Ocelot.cpp
index 50dd249c0..e5004a1d1 100644
--- a/src/Mobs/Ocelot.cpp
+++ b/src/Mobs/Ocelot.cpp
@@ -90,25 +90,30 @@ void cOcelot::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
void cOcelot::TickFollowPlayer()
{
- Vector3d OwnerPos;
- bool OwnerFlying = false;
- auto Callback = [&](cPlayer & a_Player)
+ class cCallback :
+ public cPlayerListCallback
{
- OwnerPos = a_Player.GetPosition();
- OwnerFlying = a_Player.IsFlying();
- return true;
- };
+ virtual bool Item(cPlayer * a_Player) override
+ {
+ OwnerPos = a_Player->GetPosition();
+ OwnerFlying = a_Player->IsFlying();
+ return true;
+ }
+ public:
+ Vector3d OwnerPos;
+ bool OwnerFlying;
+ } Callback;
if (m_World->DoWithPlayerByUUID(m_OwnerUUID, Callback))
{
// The player is present in the world, follow him:
- double Distance = (OwnerPos - GetPosition()).Length();
+ double Distance = (Callback.OwnerPos - GetPosition()).Length();
if (Distance > 12)
{
- if (!OwnerFlying)
+ if (!Callback.OwnerFlying)
{
- OwnerPos.y = FindFirstNonAirBlockPosition(OwnerPos.x, OwnerPos.z);
- TeleportToCoords(OwnerPos.x, OwnerPos.y, OwnerPos.z);
+ Callback.OwnerPos.y = FindFirstNonAirBlockPosition(Callback.OwnerPos.x, Callback.OwnerPos.z);
+ TeleportToCoords(Callback.OwnerPos.x, Callback.OwnerPos.y, Callback.OwnerPos.z);
}
}
if (Distance < 2)
@@ -117,9 +122,9 @@ void cOcelot::TickFollowPlayer()
}
else
{
- if (!OwnerFlying)
+ if (!Callback.OwnerFlying)
{
- MoveToPosition(OwnerPos);
+ MoveToPosition(Callback.OwnerPos);
}
}
}
@@ -200,19 +205,27 @@ void cOcelot::SpawnOn(cClientHandle & a_ClientHandle)
+class cFindSittingCat :
+ public cEntityCallback
+{
+ virtual bool Item(cEntity * a_Entity) override
+ {
+ return (
+ (a_Entity->GetEntityType() == cEntity::etMonster) &&
+ (static_cast<cMonster *>(a_Entity)->GetMobType() == eMonsterType::mtOcelot) &&
+ (static_cast<cOcelot *>(a_Entity)->IsSitting())
+ );
+ }
+};
+
+
+
+
+
bool cOcelot::IsCatSittingOnBlock(cWorld * a_World, Vector3d a_BlockPosition)
{
- return a_World->ForEachEntityInBox(
- cBoundingBox(Vector3d(a_BlockPosition.x, a_BlockPosition.y + 1, a_BlockPosition.z), 1),
- [=](cEntity & a_Entity)
- {
- return (
- (a_Entity.GetEntityType() == cEntity::etMonster) &&
- (static_cast<cMonster &>(a_Entity).GetMobType() == eMonsterType::mtOcelot) &&
- (static_cast<cOcelot &>(a_Entity).IsSitting())
- );
- }
- );
+ cFindSittingCat FindSittingCat;
+ return a_World->ForEachEntityInBox(cBoundingBox(Vector3d(a_BlockPosition.x, a_BlockPosition.y + 1, a_BlockPosition.z), 1), FindSittingCat);
}