Skip to content

Commit

Permalink
Don't send entity velocity for boats (cuberite#4488)
Browse files Browse the repository at this point in the history
* Don't send entity velocity for boats
  • Loading branch information
mathiascode authored Mar 7, 2020
1 parent 83a41c9 commit 5a2163d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
29 changes: 29 additions & 0 deletions src/Entities/Boat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,35 @@ void cBoat::SpawnOn(cClientHandle & a_ClientHandle)



void cBoat::BroadcastMovementUpdate(const cClientHandle * a_Exclude)
{
// Process packet sending every two ticks
if (GetWorld()->GetWorldAge() % 2 != 0)
{
return;
}

Vector3i Diff = (GetPosition() * 32.0).Floor() - (m_LastSentPosition * 32.0).Floor();

if (Diff.HasNonZeroLength()) // Have we moved?
{
if ((abs(Diff.x) <= 127) && (abs(Diff.y) <= 127) && (abs(Diff.z) <= 127)) // Limitations of a Byte
{
m_World->BroadcastEntityRelMove(*this, Vector3<Int8>(Diff), a_Exclude);
}
else
{
// Too big a movement, do a teleport
m_World->BroadcastTeleportEntity(*this, a_Exclude);
}
m_LastSentPosition = GetPosition();
}
}





bool cBoat::DoTakeDamage(TakeDamageInfo & TDI)
{
m_LastDamage = 10;
Expand Down
1 change: 1 addition & 0 deletions src/Entities/Boat.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class cBoat :

// cEntity overrides:
virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
virtual void BroadcastMovementUpdate(const cClientHandle * a_Exclude = nullptr) override;
virtual void OnRightClicked(cPlayer & a_Player) override;
virtual bool DoTakeDamage(TakeDamageInfo & TDI) override;
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
Expand Down
2 changes: 1 addition & 1 deletion src/Entities/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ cEntity::cEntity(eEntityType a_EntityType, Vector3d a_Pos, double a_Width, doubl
m_bOnGround(false),
m_Gravity(-9.81f),
m_AirDrag(0.02f),
m_LastSentPosition(a_Pos),
m_LastPosition(a_Pos),
m_EntityType(a_EntityType),
m_World(nullptr),
Expand All @@ -65,7 +66,6 @@ cEntity::cEntity(eEntityType a_EntityType, Vector3d a_Pos, double a_Width, doubl
m_HeadYaw(0.0),
m_Rot(0.0, 0.0, 0.0),
m_Position(a_Pos),
m_LastSentPosition(a_Pos),
m_WaterSpeed(0, 0, 0),
m_Mass (0.001), // Default 1g
m_Width(a_Width),
Expand Down
8 changes: 4 additions & 4 deletions src/Entities/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,10 @@ class cEntity
Data: https://minecraft.gamepedia.com/Entity#Motion_of_entities */
float m_AirDrag;

/** Last position sent to client via the Relative Move or Teleport packets (not Velocity)
Only updated if cEntity::BroadcastMovementUpdate() is called! */
Vector3d m_LastSentPosition;

Vector3d m_LastPosition;

eEntityType m_EntityType;
Expand Down Expand Up @@ -752,10 +756,6 @@ class cEntity
/** Position of the entity's XZ center and Y bottom */
Vector3d m_Position;

/** Last position sent to client via the Relative Move or Teleport packets (not Velocity)
Only updated if cEntity::BroadcastMovementUpdate() is called! */
Vector3d m_LastSentPosition;

/** Measured in meter / second */
Vector3d m_WaterSpeed;

Expand Down

0 comments on commit 5a2163d

Please sign in to comment.