1
0

Merge pull request #2617 from Gargaj/pushcomestoshove

Implement pushing/shoving
This commit is contained in:
worktycho 2015-11-07 13:26:11 +00:00
commit 4a01e486e3

View File

@ -4,6 +4,7 @@
#include "Pawn.h"
#include "../World.h"
#include "../Bindings/PluginManager.h"
#include "BoundingBox.h"
@ -43,6 +44,41 @@ void cPawn::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
// TODO: Check for discrepancies between client and server effect values
}
class Pusher : public cEntityCallback
{
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))
{
return false;
}
Vector3d v3Delta = a_Entity->GetPosition() - m_Pusher->GetPosition();
v3Delta.y = 0.0; // we only push sideways
v3Delta *= 1.0 / v3Delta.Length(); // 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);
m_World->ForEachEntityInBox(cBoundingBox(GetPosition(), GetWidth(), GetHeight()), Callback);
super::Tick(a_Dt, a_Chunk);
}