diff options
author | peterbell10 <peterbell10@live.co.uk> | 2017-09-11 23:20:49 +0200 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2017-09-11 23:20:49 +0200 |
commit | e225b7f8262df48ad4d7094bc295add3007b0649 (patch) | |
tree | a42e9afcc88cfe6e9d1258458e3ad42764083d0e /src/Entities/LeashKnot.cpp | |
parent | cBlockArea: change MakeIndex to return size_t (diff) | |
download | cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.gz cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.bz2 cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.lz cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.xz cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.zst cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.zip |
Diffstat (limited to 'src/Entities/LeashKnot.cpp')
-rw-r--r-- | src/Entities/LeashKnot.cpp | 61 |
1 files changed, 19 insertions, 42 deletions
diff --git a/src/Entities/LeashKnot.cpp b/src/Entities/LeashKnot.cpp index a86dc9d53..51002531d 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,58 +38,42 @@ 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 - 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 + // 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) { // 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; } - cMonster * PotentialLeashed = static_cast<cMonster*>(a_Entity); + auto & 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() != m_Player->GetUniqueID()) + !PotentialLeashed.IsLeashed() || + !PotentialLeashed.GetLeashedTo()->IsPlayer() || + (PotentialLeashed.GetLeashedTo()->GetUniqueID() != a_Player.GetUniqueID()) ) { return false; } // All conditions met, unleash from player and leash to fence - PotentialLeashed->Unleash(false, false); - PotentialLeashed->LeashTo(*m_Knot, m_ShouldBroadcast); + PotentialLeashed.Unleash(false, false); + PotentialLeashed.LeashTo(*this, a_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); + ); } @@ -158,26 +142,19 @@ void cLeashKnot::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) cLeashKnot * cLeashKnot::FindKnotAtPos(cWorldInterface & a_WorldInterface, Vector3i a_BlockPos) { - class LookForKnot : public cEntityCallback - { - public: - cLeashKnot * m_LeashKnot = nullptr; - - virtual bool Item(cEntity * a_Entity) override + cLeashKnot * LeashKnot = nullptr; + a_WorldInterface.ForEachEntityInBox(cBoundingBox(a_BlockPos, 0.5, 1), [&](cEntity & a_Entity) { - if (a_Entity->IsLeashKnot()) + if (a_Entity.IsLeashKnot()) { - m_LeashKnot = reinterpret_cast<cLeashKnot *>(a_Entity); + LeashKnot = static_cast<cLeashKnot *>(&a_Entity); return true; } return false; } + ); - } CallbackFindKnot; - - a_WorldInterface.ForEachEntityInBox(cBoundingBox(a_BlockPos, 0.5, 1), CallbackFindKnot); - - return CallbackFindKnot.m_LeashKnot; + return LeashKnot; } |