1
0

Implemented SteerVehicle packet.

This commit is contained in:
madmaxoft 2013-09-06 00:04:49 +02:00 committed by Tiger Wang
parent e8d1ed36c5
commit f300ed54e5
5 changed files with 43 additions and 6 deletions

View File

@ -1090,6 +1090,15 @@ void cClientHandle::HandleSlotSelected(short a_SlotNum)
void cClientHandle::HandleSteerVehicle(float a_Forward, float a_Sideways)
{
m_Player->SteerVehicle(a_Forward, a_Sideways);
}
void cClientHandle::HandleWindowClose(char a_WindowID)
{
m_Player->CloseWindowIfID(a_WindowID);

View File

@ -177,6 +177,7 @@ public:
void HandleRespawn (void);
void HandleRightClick (int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, const cItem & a_HeldItem);
void HandleSlotSelected (short a_SlotNum);
void HandleSteerVehicle (float Forward, float Sideways);
void HandleTabCompletion (const AString & a_Text);
void HandleUpdateSign (
int a_BlockX, int a_BlockY, int a_BlockZ,

View File

@ -546,22 +546,24 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
}
else
{
// TODO: This condition belongs to minecarts, without it, they derails too much.
// But it shouldn't be here for other entities. We need a complete minecart physics overhaul.
if (
(BlockBelow != E_BLOCK_RAIL) &&
(BlockBelow != E_BLOCK_DETECTOR_RAIL) &&
(BlockBelow != E_BLOCK_POWERED_RAIL) &&
(BlockBelow != E_BLOCK_RAIL) &&
(BlockBelow != E_BLOCK_DETECTOR_RAIL) &&
(BlockBelow != E_BLOCK_POWERED_RAIL) &&
(BlockBelow != E_BLOCK_ACTIVATOR_RAIL)
)
)
{
// Friction
if (NextSpeed.SqrLength() > 0.0004f)
{
NextSpeed.x *= 0.7f / (1 + a_Dt);
NextSpeed.x *= 0.6666;
if (fabs(NextSpeed.x) < 0.05)
{
NextSpeed.x = 0;
}
NextSpeed.z *= 0.7f / (1 + a_Dt);
NextSpeed.z *= 0.6666;
if (fabs(NextSpeed.z) < 0.05)
{
NextSpeed.z = 0;
@ -1225,6 +1227,25 @@ void cEntity::AddSpeedZ(double a_AddSpeedZ)
void cEntity::SteerVehicle(float a_Forward, float a_Sideways)
{
if (m_AttachedTo == NULL)
{
return;
}
if ((a_Forward != 0) || (a_Sideways != 0))
{
Vector3d LookVector = GetLookVector();
double AddSpeedX = LookVector.x * a_Forward + LookVector.z * a_Sideways;
double AddSpeedZ = LookVector.z * a_Forward - LookVector.x * a_Sideways;
m_AttachedTo->AddSpeed(AddSpeedX, 0, AddSpeedZ);
}
}
//////////////////////////////////////////////////////////////////////////
// Get look vector (this is NOT a rotation!)
Vector3d cEntity::GetLookVector(void) const

View File

@ -185,6 +185,8 @@ public:
void AddSpeedX (double a_AddSpeedX);
void AddSpeedY (double a_AddSpeedY);
void AddSpeedZ (double a_AddSpeedZ);
void SteerVehicle(float a_Forward, float a_Sideways);
inline int GetUniqueID(void) const { return m_UniqueID; }
inline bool IsDestroyed(void) const { return !m_IsInitialized; }

View File

@ -213,6 +213,10 @@ int cProtocol161::ParseSteerVehicle(void)
{
m_Client->HandleUnmount();
}
else
{
m_Client->HandleSteerVehicle(Forward, Sideways);
}
return PARSE_OK;
}