summaryrefslogtreecommitdiffstats
path: root/src/Entities/Player.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Entities/Player.cpp73
1 files changed, 17 insertions, 56 deletions
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index fb2274cad..93368f6fb 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -1005,36 +1005,21 @@ bool cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI)
void cPlayer::NotifyNearbyWolves(cPawn * a_Opponent, bool a_IsPlayerInvolved)
{
ASSERT(a_Opponent != nullptr);
- class LookForWolves : public cEntityCallback
- {
- public:
- cPlayer * m_Player;
- cPawn * m_Attacker;
- bool m_IsPlayerInvolved;
-
- LookForWolves(cPlayer * a_Me, cPawn * a_MyAttacker, bool a_PlayerInvolved) :
- m_Player(a_Me),
- m_Attacker(a_MyAttacker),
- m_IsPlayerInvolved(a_PlayerInvolved)
- {
- }
- virtual bool Item(cEntity * a_Entity) override
+ m_World->ForEachEntityInBox(cBoundingBox(GetPosition(), 16), [&] (cEntity & a_Entity)
{
- if (a_Entity->IsMob())
+ if (a_Entity.IsMob())
{
- cMonster * Mob = static_cast<cMonster*>(a_Entity);
- if (Mob->GetMobType() == mtWolf)
+ auto & Mob = static_cast<cMonster&>(a_Entity);
+ if (Mob.GetMobType() == mtWolf)
{
- cWolf * Wolf = static_cast<cWolf*>(Mob);
- Wolf->ReceiveNearbyFightInfo(m_Player->GetUUID(), m_Attacker, m_IsPlayerInvolved);
+ auto & Wolf = static_cast<cWolf&>(Mob);
+ Wolf.ReceiveNearbyFightInfo(GetUUID(), a_Opponent, a_IsPlayerInvolved);
}
}
return false;
}
- } Callback(this, a_Opponent, a_IsPlayerInvolved);
-
- m_World->ForEachEntityInBox(cBoundingBox(GetPosition(), 16), Callback);
+ );
}
@@ -2432,17 +2417,12 @@ void cPlayer::HandleFloater()
{
return;
}
- class cFloaterCallback :
- public cEntityCallback
- {
- public:
- virtual bool Item(cEntity * a_Entity) override
+ m_World->DoWithEntityByID(m_FloaterID, [](cEntity & a_Entity)
{
- a_Entity->Destroy(true);
+ a_Entity.Destroy(true);
return true;
}
- } Callback;
- m_World->DoWithEntityByID(m_FloaterID, Callback);
+ );
SetIsFishing(false);
}
@@ -2686,29 +2666,18 @@ bool cPlayer::DoesPlacingBlocksIntersectEntity(const sSetBlockVector & a_Blocks)
cWorld * World = GetWorld();
// Check to see if any entity intersects any block being placed
- class DoesIntersectBlock : public cEntityCallback
- {
- public:
- const std::vector<cBoundingBox> & m_BoundingBoxes;
-
- // The distance inside the block the entity can still be.
- const double EPSILON = 0.0005;
-
- DoesIntersectBlock(const std::vector<cBoundingBox> & a_BoundingBoxes) :
- m_BoundingBoxes(a_BoundingBoxes)
+ return !World->ForEachEntityInBox(PlacingBounds, [&](cEntity & a_Entity)
{
- }
+ // The distance inside the block the entity can still be.
+ const double EPSILON = 0.0005;
- virtual bool Item(cEntity * a_Entity) override
- {
- if (!a_Entity->DoesPreventBlockPlacement())
+ if (!a_Entity.DoesPreventBlockPlacement())
{
return false;
}
- cBoundingBox EntBox(a_Entity->GetPosition(), a_Entity->GetWidth() / 2, a_Entity->GetHeight());
- for (auto BlockBox: m_BoundingBoxes)
+ cBoundingBox EntBox(a_Entity.GetPosition(), a_Entity.GetWidth() / 2, a_Entity.GetHeight());
+ for (auto BlockBox : PlacementBoxes)
{
-
// Put in a little bit of wiggle room
BlockBox.Expand(-EPSILON, -EPSILON, -EPSILON);
if (EntBox.DoesIntersect(BlockBox))
@@ -2718,15 +2687,7 @@ bool cPlayer::DoesPlacingBlocksIntersectEntity(const sSetBlockVector & a_Blocks)
}
return false;
}
- } Callback(PlacementBoxes);
-
- // See if any entities in that bounding box collide with anyone
- if (!World->ForEachEntityInBox(PlacingBounds, Callback))
- {
- return true;
- }
-
- return false;
+ );
}