summaryrefslogtreecommitdiffstats
path: root/src/Entities/LeashKnot.cpp
diff options
context:
space:
mode:
authorLogicParrot <LogicParrot@users.noreply.github.com>2017-09-02 12:35:22 +0200
committerLogicParrot <LogicParrot@users.noreply.github.com>2017-09-02 12:35:22 +0200
commit07a5bf0984559d04fce1091b82b0952217ac64cc (patch)
tree0d1eee372a782213c9e2b84deaefe717b379a04b /src/Entities/LeashKnot.cpp
parentSkeletons (diff)
parentRevert "Replace ItemCallbacks with lambdas (#3948)" (diff)
downloadcuberite-07a5bf0984559d04fce1091b82b0952217ac64cc.tar
cuberite-07a5bf0984559d04fce1091b82b0952217ac64cc.tar.gz
cuberite-07a5bf0984559d04fce1091b82b0952217ac64cc.tar.bz2
cuberite-07a5bf0984559d04fce1091b82b0952217ac64cc.tar.lz
cuberite-07a5bf0984559d04fce1091b82b0952217ac64cc.tar.xz
cuberite-07a5bf0984559d04fce1091b82b0952217ac64cc.tar.zst
cuberite-07a5bf0984559d04fce1091b82b0952217ac64cc.zip
Diffstat (limited to '')
-rw-r--r--src/Entities/LeashKnot.cpp61
1 files changed, 42 insertions, 19 deletions
diff --git a/src/Entities/LeashKnot.cpp b/src/Entities/LeashKnot.cpp
index 51002531d..a86dc9d53 100644
--- a/src/Entities/LeashKnot.cpp
+++ b/src/Entities/LeashKnot.cpp
@@ -1,4 +1,4 @@
-
+
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "LeashKnot.h"
@@ -38,42 +38,58 @@ void cLeashKnot::OnRightClicked(cPlayer & a_Player)
-void cLeashKnot::TiePlayersLeashedMobs(cPlayer & a_Player, bool a_ShouldBroadcast)
+void cLeashKnot::TiePlayersLeashedMobs(cPlayer & a_Player, bool a_ShouldBroadCast)
{
// Check leashed nearby mobs to tie them to this knot
- // taking world from player (instead from this) because this can be called before entity was initialized
- a_Player.GetWorld()->ForEachEntityInBox(cBoundingBox(GetPosition(), 8, 8, -4), [&](cEntity & a_Entity)
+ class LookForLeasheds : public cEntityCallback
+ {
+ public:
+ cLeashKnot * m_Knot;
+ cPlayer * m_Player;
+ bool m_ShouldBroadcast;
+
+ LookForLeasheds(cLeashKnot * a_Knot, cPlayer * a_PlayerLeashedTo, bool a_ShouldBroadcast) :
+ m_Knot(a_Knot),
+ m_Player(a_PlayerLeashedTo),
+ m_ShouldBroadcast(a_ShouldBroadcast)
+ {
+ }
+
+ virtual bool Item(cEntity * a_Entity) override
{
// If the entity is not a monster skip it
- if (a_Entity.GetEntityType() != cEntity::eEntityType::etMonster)
+ if (a_Entity->GetEntityType() != cEntity::eEntityType::etMonster)
{
return false;
}
- auto & PotentialLeashed = static_cast<cMonster&>(a_Entity);
+ cMonster * PotentialLeashed = static_cast<cMonster*>(a_Entity);
// If can't be leashed skip it
- if (!PotentialLeashed.CanBeLeashed())
+ if (!PotentialLeashed->CanBeLeashed())
{
return false;
}
// If it's not leashed to the player skip it
if (
- !PotentialLeashed.IsLeashed() ||
- !PotentialLeashed.GetLeashedTo()->IsPlayer() ||
- (PotentialLeashed.GetLeashedTo()->GetUniqueID() != a_Player.GetUniqueID())
+ !PotentialLeashed->IsLeashed() ||
+ !PotentialLeashed->GetLeashedTo()->IsPlayer() ||
+ (PotentialLeashed->GetLeashedTo()->GetUniqueID() != m_Player->GetUniqueID())
)
{
return false;
}
// All conditions met, unleash from player and leash to fence
- PotentialLeashed.Unleash(false, false);
- PotentialLeashed.LeashTo(*this, a_ShouldBroadcast);
+ PotentialLeashed->Unleash(false, false);
+ PotentialLeashed->LeashTo(*m_Knot, m_ShouldBroadcast);
return false;
}
- );
+ } LookForLeashedsCallback(this, &a_Player, a_ShouldBroadCast);
+
+ // taking world from player (instead from this) because this can be called before entity was initialized
+ a_Player.GetWorld()->ForEachEntityInBox(cBoundingBox(GetPosition(), 8, 8, -4), LookForLeashedsCallback);
}
@@ -142,19 +158,26 @@ void cLeashKnot::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
cLeashKnot * cLeashKnot::FindKnotAtPos(cWorldInterface & a_WorldInterface, Vector3i a_BlockPos)
{
- cLeashKnot * LeashKnot = nullptr;
- a_WorldInterface.ForEachEntityInBox(cBoundingBox(a_BlockPos, 0.5, 1), [&](cEntity & a_Entity)
+ class LookForKnot : public cEntityCallback
+ {
+ public:
+ cLeashKnot * m_LeashKnot = nullptr;
+
+ virtual bool Item(cEntity * a_Entity) override
{
- if (a_Entity.IsLeashKnot())
+ if (a_Entity->IsLeashKnot())
{
- LeashKnot = static_cast<cLeashKnot *>(&a_Entity);
+ m_LeashKnot = reinterpret_cast<cLeashKnot *>(a_Entity);
return true;
}
return false;
}
- );
- return LeashKnot;
+ } CallbackFindKnot;
+
+ a_WorldInterface.ForEachEntityInBox(cBoundingBox(a_BlockPos, 0.5, 1), CallbackFindKnot);
+
+ return CallbackFindKnot.m_LeashKnot;
}