diff options
author | LogicParrot <LogicParrot@users.noreply.github.com> | 2017-09-02 12:35:22 +0200 |
---|---|---|
committer | LogicParrot <LogicParrot@users.noreply.github.com> | 2017-09-02 12:35:22 +0200 |
commit | 07a5bf0984559d04fce1091b82b0952217ac64cc (patch) | |
tree | 0d1eee372a782213c9e2b84deaefe717b379a04b /src/Entities/Pawn.cpp | |
parent | Skeletons (diff) | |
parent | Revert "Replace ItemCallbacks with lambdas (#3948)" (diff) | |
download | cuberite-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 'src/Entities/Pawn.cpp')
-rw-r--r-- | src/Entities/Pawn.cpp | 68 |
1 files changed, 40 insertions, 28 deletions
diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index ac8e4b1ab..0fa11997b 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -1,4 +1,4 @@ - + #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Pawn.h" @@ -79,37 +79,49 @@ void cPawn::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) Effect->OnTick(*this); } - // Spectators cannot push entities around - if ((!IsPlayer()) || (!static_cast<cPlayer *>(this)->IsGameModeSpectator())) + class Pusher : public cEntityCallback { - m_World->ForEachEntityInBox(cBoundingBox(GetPosition(), GetWidth(), GetHeight()), [=](cEntity & a_Entity) + public: + cEntity * m_Pusher; + + Pusher(cEntity * a_Pusher) : + m_Pusher(a_Pusher) + { + } + + virtual bool Item(cEntity * a_Entity) override + { + if (a_Entity->GetUniqueID() == m_Pusher->GetUniqueID()) + { + return false; + } + + // we only push other mobs, boats and minecarts + if ((a_Entity->GetEntityType() != etMonster) && (a_Entity->GetEntityType() != etMinecart) && (a_Entity->GetEntityType() != etBoat)) { - if (a_Entity.GetUniqueID() == GetUniqueID()) - { - return false; - } - - // we only push other mobs, boats and minecarts - if ((a_Entity.GetEntityType() != etMonster) && (a_Entity.GetEntityType() != etMinecart) && (a_Entity.GetEntityType() != etBoat)) - { - return false; - } - - // do not push a boat / minecart you're sitting in - if (IsAttachedTo(&a_Entity)) - { - return false; - } - - Vector3d v3Delta = a_Entity.GetPosition() - GetPosition(); - v3Delta.y = 0.0; // we only push sideways - v3Delta *= 1.0 / (v3Delta.Length() + 0.01); // we push harder if we're close - // QUESTION: is there an additional multiplier for this? current shoving seems a bit weak - - a_Entity.AddSpeed(v3Delta); return false; } - ); + + // do not push a boat / minecart you're sitting in + if (m_Pusher->IsAttachedTo(a_Entity)) + { + return false; + } + + Vector3d v3Delta = a_Entity->GetPosition() - m_Pusher->GetPosition(); + v3Delta.y = 0.0; // we only push sideways + v3Delta *= 1.0 / (v3Delta.Length() + 0.01); // we push harder if we're close + // QUESTION: is there an additional multiplier for this? current shoving seems a bit weak + + a_Entity->AddSpeed(v3Delta); + return false; + } + } Callback(this); + + // Spectators cannot push entities around + if ((!IsPlayer()) || (!reinterpret_cast<cPlayer *>(this)->IsGameModeSpectator())) + { + m_World->ForEachEntityInBox(cBoundingBox(GetPosition(), GetWidth(), GetHeight()), Callback); } super::Tick(a_Dt, a_Chunk); |