summaryrefslogtreecommitdiffstats
path: root/src/Entities
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Entities/Boat.cpp29
-rw-r--r--src/Entities/Boat.h1
-rw-r--r--src/Entities/Entity.cpp2
-rw-r--r--src/Entities/Entity.h8
4 files changed, 35 insertions, 5 deletions
diff --git a/src/Entities/Boat.cpp b/src/Entities/Boat.cpp
index c88df4952..d0ac27228 100644
--- a/src/Entities/Boat.cpp
+++ b/src/Entities/Boat.cpp
@@ -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;
diff --git a/src/Entities/Boat.h b/src/Entities/Boat.h
index aa6dc0637..3b9889fc1 100644
--- a/src/Entities/Boat.h
+++ b/src/Entities/Boat.h
@@ -39,6 +39,7 @@ public:
// 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;
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 983cc96be..206e6af60 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -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),
@@ -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),
diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h
index b151f745d..563db7b9e 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -656,6 +656,10 @@ protected:
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;
@@ -752,10 +756,6 @@ private:
/** 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;