diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp index 357c07105..3d819ee18 100644 --- a/source/ClientHandle.cpp +++ b/source/ClientHandle.cpp @@ -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); diff --git a/source/ClientHandle.h b/source/ClientHandle.h index 761cf25fe..9a2092361 100644 --- a/source/ClientHandle.h +++ b/source/ClientHandle.h @@ -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, diff --git a/source/Entities/Entity.cpp b/source/Entities/Entity.cpp index 56fd36a05..4066e81ab 100644 --- a/source/Entities/Entity.cpp +++ b/source/Entities/Entity.cpp @@ -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 diff --git a/source/Entities/Entity.h b/source/Entities/Entity.h index 2d058abae..b4777d249 100644 --- a/source/Entities/Entity.h +++ b/source/Entities/Entity.h @@ -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; } diff --git a/source/Protocol/Protocol16x.cpp b/source/Protocol/Protocol16x.cpp index 3a640da21..be5b45f19 100644 --- a/source/Protocol/Protocol16x.cpp +++ b/source/Protocol/Protocol16x.cpp @@ -213,6 +213,10 @@ int cProtocol161::ParseSteerVehicle(void) { m_Client->HandleUnmount(); } + else + { + m_Client->HandleSteerVehicle(Forward, Sideways); + } return PARSE_OK; }