summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-10-03 23:23:56 +0200
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-10-03 23:23:56 +0200
commit4774323154a2d07c656ee477c7424440ef3914ef (patch)
tree63762c685a7f665541f87d7d65ca0be6358f51e9 /src
parentLilypad placement calls block place hook (diff)
downloadcuberite-4774323154a2d07c656ee477c7424440ef3914ef.tar
cuberite-4774323154a2d07c656ee477c7424440ef3914ef.tar.gz
cuberite-4774323154a2d07c656ee477c7424440ef3914ef.tar.bz2
cuberite-4774323154a2d07c656ee477c7424440ef3914ef.tar.lz
cuberite-4774323154a2d07c656ee477c7424440ef3914ef.tar.xz
cuberite-4774323154a2d07c656ee477c7424440ef3914ef.tar.zst
cuberite-4774323154a2d07c656ee477c7424440ef3914ef.zip
Diffstat (limited to '')
-rw-r--r--src/Entities/Entity.cpp156
-rw-r--r--src/Entities/Entity.h103
-rw-r--r--src/Entities/Player.cpp39
-rw-r--r--src/Entities/Player.h15
4 files changed, 122 insertions, 191 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index da85dec50..02fcd5f1b 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -1456,17 +1456,6 @@ void cEntity::SetSwimState(cChunk & a_Chunk)
-void cEntity::DoSetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ)
-{
- m_Speed.Set(a_SpeedX, a_SpeedY, a_SpeedZ);
-
- WrapSpeed();
-}
-
-
-
-
-
void cEntity::HandleAir(void)
{
// Ref.: http://www.minecraftwiki.net/wiki/Chunk_format
@@ -1770,15 +1759,6 @@ void cEntity::SetHeadYaw(double a_HeadYaw)
-void cEntity::SetHeight(double a_Height)
-{
- m_Height = a_Height;
-}
-
-
-
-
-
void cEntity::SetMass(double a_Mass)
{
// Make sure that mass is not zero. 1g is the default because we
@@ -1823,97 +1803,18 @@ void cEntity::SetRoll(double a_Roll)
-void cEntity::SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ)
+void cEntity::SetSpeed(const Vector3d & a_Speed)
{
- DoSetSpeed(a_SpeedX, a_SpeedY, a_SpeedZ);
-}
-
-
-
-
-void cEntity::SetSpeedX(double a_SpeedX)
-{
- SetSpeed(a_SpeedX, m_Speed.y, m_Speed.z);
-}
-
-
-
-
-void cEntity::SetSpeedY(double a_SpeedY)
-{
- SetSpeed(m_Speed.x, a_SpeedY, m_Speed.z);
-}
-
-
-
-
-void cEntity::SetSpeedZ(double a_SpeedZ)
-{
- SetSpeed(m_Speed.x, m_Speed.y, a_SpeedZ);
-}
-
-
-
-
-
-void cEntity::SetWidth(double a_Width)
-{
- m_Width = a_Width;
-}
-
-
-
-
-
-void cEntity::AddPosX(double a_AddPosX)
-{
- m_Pos.x += a_AddPosX;
-}
-
-
-
-
-void cEntity::AddPosY(double a_AddPosY)
-{
- m_Pos.y += a_AddPosY;
-}
-
-
-
-
-void cEntity::AddPosZ(double a_AddPosZ)
-{
- m_Pos.z += a_AddPosZ;
-}
-
-
-
-
-void cEntity::AddPosition(double a_AddPosX, double a_AddPosY, double a_AddPosZ)
-{
- m_Pos.x += a_AddPosX;
- m_Pos.y += a_AddPosY;
- m_Pos.z += a_AddPosZ;
-}
-
-
-
-
-void cEntity::AddSpeed(double a_AddSpeedX, double a_AddSpeedY, double a_AddSpeedZ)
-{
- m_Speed.x += a_AddSpeedX;
- m_Speed.y += a_AddSpeedY;
- m_Speed.z += a_AddSpeedZ;
+ m_Speed = a_Speed;
WrapSpeed();
}
-
-void cEntity::AddSpeedX(double a_AddSpeedX)
+void cEntity::AddSpeed(const Vector3d & a_AddSpeed)
{
- m_Speed.x += a_AddSpeedX;
+ m_Speed += a_AddSpeed;
WrapSpeed();
}
@@ -1921,20 +1822,17 @@ void cEntity::AddSpeedX(double a_AddSpeedX)
-void cEntity::AddSpeedY(double a_AddSpeedY)
+void cEntity::SetPosition(const Vector3d & a_Pos)
{
- m_Speed.y += a_AddSpeedY;
- WrapSpeed();
+ m_Pos = a_Pos;
}
-
-void cEntity::AddSpeedZ(double a_AddSpeedZ)
+void cEntity::AddPosition(const Vector3d & a_AddPos)
{
- m_Speed.z += a_AddSpeedZ;
- WrapSpeed();
+ m_Pos += a_AddPos;
}
@@ -1983,41 +1881,3 @@ Vector3d cEntity::GetLookVector(void) const
-
-////////////////////////////////////////////////////////////////////////////////
-// Set position
-void cEntity::SetPosition(double a_PosX, double a_PosY, double a_PosZ)
-{
- m_Pos.Set(a_PosX, a_PosY, a_PosZ);
-}
-
-
-
-
-
-void cEntity::SetPosX(double a_PosX)
-{
- m_Pos.x = a_PosX;
-}
-
-
-
-
-
-void cEntity::SetPosY(double a_PosY)
-{
- m_Pos.y = a_PosY;
-}
-
-
-
-
-
-void cEntity::SetPosZ(double a_PosZ)
-{
- m_Pos.z = a_PosZ;
-}
-
-
-
-
diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h
index 3fa7e80c1..3d7177fd4 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -205,45 +205,88 @@ public:
int GetChunkZ(void) const {return (int)floor(m_Pos.z / cChunkDef::Width); }
void SetHeadYaw (double a_HeadYaw);
- void SetHeight (double a_Height);
+ void SetHeight (double a_Height) { m_Height = a_Height; }
+ void SetWidth (double a_Width) { m_Width = a_Width; }
void SetMass (double a_Mass);
- void SetPosX (double a_PosX);
- void SetPosY (double a_PosY);
- void SetPosZ (double a_PosZ);
- void SetPosition(double a_PosX, double a_PosY, double a_PosZ);
- void SetPosition(const Vector3d & a_Pos) { SetPosition(a_Pos.x, a_Pos.y, a_Pos.z); }
void SetRot (const Vector3f & a_Rot); // OBSOLETE, use individual SetYaw(), SetPitch(), SetRoll() components
void SetYaw (double a_Yaw); // In degrees, normalizes to [-180, +180)
void SetPitch (double a_Pitch); // In degrees, normalizes to [-180, +180)
void SetRoll (double a_Roll); // In degrees, normalizes to [-180, +180)
- /** Sets the speed of the entity, measured in m / sec */
- void SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ);
+ /** Sets the speed of the entity, measured in m / sec
+ The default implementation just sets the member variable value;
+ overrides can provide further processing, such as forcing players to move at the given speed
+ */
+ virtual void SetSpeed(const Vector3d & a_Speed);
/** Sets the speed of the entity, measured in m / sec */
- void SetSpeed(const Vector3d & a_Speed) { SetSpeed(a_Speed.x, a_Speed.y, a_Speed.z); }
-
- /** Sets the speed in the X axis, leaving the other speed components intact. Measured in m / sec. */
- void SetSpeedX(double a_SpeedX);
-
- /** Sets the speed in the Y axis, leaving the other speed components intact. Measured in m / sec. */
- void SetSpeedY(double a_SpeedY);
+ void SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ) { SetSpeed(Vector3d(a_SpeedX, a_SpeedY, a_SpeedZ)); }
- /** Sets the speed in the Z axis, leaving the other speed components intact. Measured in m / sec. */
- void SetSpeedZ(double a_SpeedZ);
+ /** Sets the speed in the X axis, leaving the other speed components intact. Measured in m / sec */
+ void SetSpeedX(double a_SpeedX) { SetSpeed(a_SpeedX, m_Speed.y, m_Speed.z); }
- void SetWidth (double a_Width);
+ /** Sets the speed in the Y axis, leaving the other speed components intact. Measured in m / sec */
+ void SetSpeedY(double a_SpeedY) { SetSpeed(m_Speed.x, a_SpeedY, m_Speed.z); }
- void AddPosX (double a_AddPosX);
- void AddPosY (double a_AddPosY);
- void AddPosZ (double a_AddPosZ);
- void AddPosition(double a_AddPosX, double a_AddPosY, double a_AddPosZ);
- void AddPosition(const Vector3d & a_AddPos) { AddPosition(a_AddPos.x, a_AddPos.y, a_AddPos.z); }
- void AddSpeed (double a_AddSpeedX, double a_AddSpeedY, double a_AddSpeedZ);
- void AddSpeed (const Vector3d & a_AddSpeed) { AddSpeed(a_AddSpeed.x, a_AddSpeed.y, a_AddSpeed.z); }
- void AddSpeedX (double a_AddSpeedX);
- void AddSpeedY (double a_AddSpeedY);
- void AddSpeedZ (double a_AddSpeedZ);
+ /** Sets the speed in the Z axis, leaving the other speed components intact. Measured in m / sec */
+ void SetSpeedZ(double a_SpeedZ) { SetSpeed(m_Speed.x, m_Speed.y, a_SpeedZ); }
+
+
+ /** Adds to the speed of the entity, measured in m / sec
+ The default implementation just increases the member variable value;
+ overrides can provide further processing, such as forcing players to move at the given speed
+ */
+ virtual void AddSpeed(const Vector3d & a_AddSpeed);
+
+ /** Adds to the speed of the entity, measured in m / sec */
+ void AddSpeed(double a_AddSpeedX, double a_AddSpeedY, double a_AddSpeedZ) { AddSpeed(Vector3d(a_AddSpeedX, a_AddSpeedY, a_AddSpeedZ)); }
+
+ /** Adds to the X speed of the entity, measured in m / sec */
+ void AddSpeedX(double a_AddSpeedX) { AddSpeed(a_AddSpeedX, m_Speed.y, m_Speed.z); }
+
+ /** Adds to the Y speed of the entity, measured in m / sec */
+ void AddSpeedY(double a_AddSpeedY) { AddSpeed(m_Speed.x, a_AddSpeedY, m_Speed.z); }
+
+ /** Adds to the Z speed of the entity, measured in m / sec */
+ void AddSpeedZ(double a_AddSpeedZ) { AddSpeed(m_Speed.x, m_Speed.y, a_AddSpeedZ); }
+
+
+ /** Sets the absolute position of an entity
+ The default implementation just sets the member variable value;
+ overrides can provide further processing, such as teleporting players to the specified location
+ */
+ virtual void SetPosition(const Vector3d & a_Pos);
+
+ /** Sets the absolute position of an entity */
+ void SetPosition(double a_PosX, double a_PosY, double a_PosZ) { SetPosition(Vector3d(a_PosX, a_PosY, a_PosZ)); }
+
+ /** Sets the absolute X position of an entity */
+ void SetPosX(double a_PosX) { SetPosition(a_PosX, m_Pos.y, m_Pos.z); }
+
+ /** Sets the absolute Y position of an entity */
+ void SetPosY(double a_PosY) { SetPosition(m_Pos.x, a_PosY, m_Pos.z); }
+
+ /** Sets the absolute Z position of an entity */
+ void SetPosZ(double a_PosZ) { SetPosition(m_Pos.x, m_Pos.y, a_PosZ); }
+
+
+ /** Adds to the absolute position of an entity
+ The default implementation just adds to the member variable value;
+ overrides can provide further processing, such as teleporting players to the specified location
+ */
+ virtual void AddPosition(const Vector3d & a_AddPos);
+
+ /** Adds to the absolute position of an entity */
+ void AddPosition(double a_AddPosX, double a_AddPosY, double a_AddPosZ) { AddPosition(Vector3d(a_AddPosX, a_AddPosY, a_AddPosZ)); }
+
+ /** Adds to the absolute X position of an entity */
+ void AddPosX(double a_AddPosX) { AddPosition(a_AddPosX, m_Pos.y, m_Pos.z); }
+
+ /** Adds to the absolute Y position of an entity */
+ void AddPosY(double a_AddPosY) { AddPosition(m_Pos.x, a_AddPosY, m_Pos.z); }
+
+ /** Adds to the absolute Z position of an entity */
+ void AddPosZ(double a_AddPosZ) { AddPosition(m_Pos.x, m_Pos.y, a_AddPosZ); }
virtual void HandleSpeedFromAttachee(float a_Forward, float a_Sideways);
void SteerVehicle(float a_Forward, float a_Sideways);
@@ -529,10 +572,6 @@ protected:
/// Time, in ticks, since the last damage dealt by the void. Reset to zero when moving out of the void.
int m_TicksSinceLastVoidDamage;
- /** Does the actual speed-setting. The default implementation just sets the member variable value;
- overrides can provide further processing, such as forcing players to move at the given speed. */
- virtual void DoSetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ);
-
virtual void Destroyed(void) {} // Called after the entity has been destroyed
/** Applies friction to an entity
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index f58a0a016..3a0d96e7d 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -1271,7 +1271,7 @@ unsigned int cPlayer::AwardAchievement(const eStatistic a_Ach)
void cPlayer::TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ)
{
- SetPosition(a_PosX, a_PosY, a_PosZ);
+ cEntity::SetPosition(a_PosX, a_PosY, a_PosZ);
m_LastGroundHeight = (float)a_PosY;
m_LastJumpHeight = (float)a_PosY;
m_bIsTeleporting = true;
@@ -1325,20 +1325,23 @@ Vector3d cPlayer::GetThrowSpeed(double a_SpeedCoeff) const
-void cPlayer::ForceSetSpeed(const Vector3d & a_Speed)
+void cPlayer::SetSpeed(const Vector3d & a_Speed)
{
- SetSpeed(a_Speed);
+ super::SetSpeed(a_Speed);
+
+ // Send the speed to the client
+ m_ClientHandle->SendEntityVelocity(*this);
}
-void cPlayer::DoSetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ)
+void cPlayer::AddSpeed(const Vector3d & a_Speed)
{
- super::DoSetSpeed(a_SpeedX, a_SpeedY, a_SpeedZ);
+ super::AddSpeed(a_Speed);
- // Send the speed to the client so he actualy moves
+ // Send the speed to the client
m_ClientHandle->SendEntityVelocity(*this);
}
@@ -1346,6 +1349,30 @@ void cPlayer::DoSetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ)
+void cPlayer::SetPosition(const Vector3d & a_Position)
+{
+ super::SetPosition(a_Position);
+
+ // Teleport the client
+ TeleportToCoords(a_Position.x, a_Position.y, a_Position.z);
+}
+
+
+
+
+
+void cPlayer::AddPosition(const Vector3d & a_Position)
+{
+ super::AddPosition(a_Position);
+
+ // Teleport the client
+ TeleportToCoords(GetPosX(), GetPosY(), GetPosZ());
+}
+
+
+
+
+
void cPlayer::MoveTo( const Vector3d & a_NewPos)
{
if ((a_NewPos.y < -990) && (GetPosY() > -100))
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index 22d6a2ae2..556a118b5 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -201,10 +201,6 @@ public:
// Sets the current gamemode, doesn't check validity, doesn't send update packets to client
void LoginSetGameMode(eGameMode a_GameMode);
- /** Forces the player to move in the given direction.
- @deprecated Use SetSpeed instead. */
- void ForceSetSpeed(const Vector3d & a_Speed); // tolua_export
-
/** Tries to move to a new position, with attachment-related checks (y == -999) */
void MoveTo(const Vector3d & a_NewPos); // tolua_export
@@ -585,7 +581,16 @@ protected:
AString m_CustomName;
/** Sets the speed and sends it to the client, so that they are forced to move so. */
- virtual void DoSetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ) override;
+ virtual void SetSpeed(const Vector3d & a_Speed) override;
+
+ /** Adds to the speed and sends it to the client, so that they are forced to move so. */
+ virtual void AddSpeed(const Vector3d & a_Speed) override;
+
+ /** Sets the speed and sends it to the client, so that they are forced to move so. */
+ virtual void SetPosition(const Vector3d & a_Position) override;
+
+ /** Adds to the speed and sends it to the client, so that they are forced to move so. */
+ virtual void AddPosition(const Vector3d & a_Position) override;
void ResolvePermissions(void);
void ResolveGroups(void);