summaryrefslogtreecommitdiffstats
path: root/src/Entities/Pawn.cpp
diff options
context:
space:
mode:
authorpeterbell10 <peterbell10@live.co.uk>2017-09-11 23:20:49 +0200
committerMattes D <github@xoft.cz>2017-09-11 23:20:49 +0200
commite225b7f8262df48ad4d7094bc295add3007b0649 (patch)
treea42e9afcc88cfe6e9d1258458e3ad42764083d0e /src/Entities/Pawn.cpp
parentcBlockArea: change MakeIndex to return size_t (diff)
downloadcuberite-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/Pawn.cpp')
-rw-r--r--src/Entities/Pawn.cpp68
1 files changed, 28 insertions, 40 deletions
diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp
index 233cdfa85..a116f97e3 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"
@@ -80,49 +80,37 @@ void cPawn::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
Effect->OnTick(*this);
}
- class Pusher : public cEntityCallback
+ // Spectators cannot push entities around
+ if ((!IsPlayer()) || (!static_cast<cPlayer *>(this)->IsGameModeSpectator()))
{
- 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))
+ m_World->ForEachEntityInBox(cBoundingBox(GetPosition(), GetWidth(), GetHeight()), [=](cEntity & a_Entity)
{
+ 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);