From 4cd49d7eca5f8fd53eb98577a1f218a5086704bb Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 5 Apr 2021 01:38:43 +0100 Subject: Fix sending incorrect date values on world change Yak shave: make more things use cTickTime. Fix a couple of incorrect modulo-on-millisecond-value by making them use WorldTickAge. --- src/Entities/Boat.cpp | 4 ++-- src/Entities/Entity.cpp | 4 ++-- src/Entities/Player.cpp | 14 +++++++------- src/Entities/Player.h | 7 ++----- 4 files changed, 13 insertions(+), 16 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Boat.cpp b/src/Entities/Boat.cpp index b47771a6e..9d804052d 100644 --- a/src/Entities/Boat.cpp +++ b/src/Entities/Boat.cpp @@ -46,8 +46,8 @@ void cBoat::BroadcastMovementUpdate(const cClientHandle * a_Exclude) // Cannot use super::BroadcastMovementUpdate here, broadcasting position when not // expected by the client breaks things. See https://github.com/cuberite/cuberite/pull/4488 - // Process packet sending every two ticks - if (GetWorld()->GetWorldAge() % 2 != 0) + // Process packet sending every two ticks: + if ((GetWorld()->GetWorldTickAge() % 2_tick) != 0_tick) { return; } diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index a6f7dd58c..9fc3f80cf 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -1884,8 +1884,8 @@ void cEntity::TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ) void cEntity::BroadcastMovementUpdate(const cClientHandle * a_Exclude) { - // Process packet sending every two ticks - if (GetWorld()->GetWorldAge() % 2 != 0) + // Process packet sending every two ticks: + if ((GetWorld()->GetWorldTickAge() % 2_tick) != 0_tick) { return; } diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index d9c51fcef..91882ad6a 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -59,8 +59,8 @@ const int cPlayer::MAX_HEALTH = 20; const int cPlayer::MAX_FOOD_LEVEL = 20; -/** Number of ticks it takes to eat an item */ -const int cPlayer::EATING_TICKS = 30; +// Number of ticks it takes to eat an item. +#define EATING_TICKS 30_tick @@ -530,7 +530,7 @@ void cPlayer::StartEating(void) void cPlayer::FinishEating(void) { // Reset the timer: - m_EatingFinishTick = -1; + m_EatingFinishTick = -1_tick; // Send the packets: m_ClientHandle->SendEntityStatus(*this, esPlayerEatingAccepted); @@ -553,7 +553,7 @@ void cPlayer::FinishEating(void) void cPlayer::AbortEating(void) { - m_EatingFinishTick = -1; + m_EatingFinishTick = -1_tick; m_World->BroadcastEntityMetadata(*this); } @@ -2929,7 +2929,7 @@ void cPlayer::TickFreezeCode() } } } - else if (GetWorld()->GetWorldAge() % 100 == 0) + else if ((GetWorld()->GetWorldTickAge() % 100_tick) == 0_tick) { // Despite the client side freeze, the player may be able to move a little by // Jumping or canceling flight. Re-freeze every now and then @@ -3115,7 +3115,7 @@ void cPlayer::OnAddToWorld(cWorld & a_World) m_ClientHandle->SendWeather(a_World.GetWeather()); // Send time: - m_ClientHandle->SendTimeUpdate(a_World.GetWorldAge(), a_World.GetTimeOfDay(), a_World.IsDaylightCycleEnabled()); + m_ClientHandle->SendTimeUpdate(a_World.GetWorldAge(), a_World.GetWorldDate(), a_World.IsDaylightCycleEnabled()); // Finally, deliver the notification hook: cRoot::Get()->GetPluginManager()->CallHookPlayerSpawned(*this); @@ -3298,7 +3298,7 @@ void cPlayer::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { m_World->CollectPickupsByPlayer(*this); - if ((m_EatingFinishTick >= 0) && (m_EatingFinishTick <= m_World->GetWorldAge())) + if ((m_EatingFinishTick >= 0_tick) && (m_EatingFinishTick <= m_World->GetWorldAge())) { FinishEating(); } diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 65dbfaed7..40797fa34 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -86,9 +86,6 @@ public: static const int MAX_FOOD_LEVEL; - /** Number of ticks it takes to eat an item */ - static const int EATING_TICKS; - // tolua_end CLASS_PROTODEF(cPlayer) @@ -371,7 +368,7 @@ public: void AddFoodExhaustion(double a_Exhaustion); /** Returns true if the player is currently in the process of eating the currently equipped item */ - bool IsEating(void) const { return (m_EatingFinishTick >= 0); } + bool IsEating(void) const { return m_EatingFinishTick >= 0_tick; } /** Returns true if the player is currently flying */ bool IsFlying(void) const { return m_IsFlying; } @@ -734,7 +731,7 @@ private: bool m_IsVisible; /** The world tick in which eating will be finished. -1 if not eating */ - Int64 m_EatingFinishTick; + cTickTimeLong m_EatingFinishTick; /** Player Xp level */ int m_LifetimeTotalXp; -- cgit v1.2.3