Added SetDoDaylightCycle() and IsDaylightCycleEnabled() to cWorld.
I need this for a GameRule plugin.
This commit is contained in:
parent
eae42d91f9
commit
4271d719b6
@ -342,7 +342,16 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send time
|
// Send time
|
||||||
m_Protocol->SendTimeUpdate(World->GetWorldAge(), World->GetTimeOfDay());
|
Int64 TimeOfDay = World->GetTimeOfDay();
|
||||||
|
if (!World->IsDaylightCycleEnabled())
|
||||||
|
{
|
||||||
|
TimeOfDay *= -1;
|
||||||
|
if (TimeOfDay == 0)
|
||||||
|
{
|
||||||
|
TimeOfDay = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_Protocol->SendTimeUpdate(World->GetWorldAge(), TimeOfDay);
|
||||||
|
|
||||||
// Send contents of the inventory window
|
// Send contents of the inventory window
|
||||||
m_Protocol->SendWholeInventory(*m_Player->GetWindow());
|
m_Protocol->SendWholeInventory(*m_Player->GetWindow());
|
||||||
|
@ -179,7 +179,7 @@ public:
|
|||||||
void SendTabCompletionResults(const AStringVector & a_Results);
|
void SendTabCompletionResults(const AStringVector & a_Results);
|
||||||
void SendTeleportEntity (const cEntity & a_Entity);
|
void SendTeleportEntity (const cEntity & a_Entity);
|
||||||
void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ);
|
void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ);
|
||||||
void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay);
|
void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay); // tolua_export
|
||||||
void SendUnloadChunk (int a_ChunkX, int a_ChunkZ);
|
void SendUnloadChunk (int a_ChunkX, int a_ChunkZ);
|
||||||
void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity);
|
void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity);
|
||||||
void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4);
|
void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4);
|
||||||
|
@ -243,6 +243,7 @@ cWorld::cWorld(const AString & a_WorldName, eDimension a_Dimension, const AStrin
|
|||||||
#endif
|
#endif
|
||||||
m_Dimension(a_Dimension),
|
m_Dimension(a_Dimension),
|
||||||
m_IsSpawnExplicitlySet(false),
|
m_IsSpawnExplicitlySet(false),
|
||||||
|
m_DoDaylightCycle(true),
|
||||||
m_WorldAgeSecs(0),
|
m_WorldAgeSecs(0),
|
||||||
m_TimeOfDaySecs(0),
|
m_TimeOfDaySecs(0),
|
||||||
m_WorldAge(0),
|
m_WorldAge(0),
|
||||||
@ -828,8 +829,12 @@ void cWorld::Tick(float a_Dt, int a_LastTickDurationMSec)
|
|||||||
SetChunkData(**itr);
|
SetChunkData(**itr);
|
||||||
} // for itr - SetChunkDataQueue[]
|
} // for itr - SetChunkDataQueue[]
|
||||||
|
|
||||||
// We need sub-tick precision here, that's why we store the time in seconds and calculate ticks off of it
|
|
||||||
m_WorldAgeSecs += (double)a_Dt / 1000.0;
|
m_WorldAgeSecs += (double)a_Dt / 1000.0;
|
||||||
|
m_WorldAge = (Int64)(m_WorldAgeSecs * 20.0);
|
||||||
|
|
||||||
|
if (m_DoDaylightCycle)
|
||||||
|
{
|
||||||
|
// We need sub-tick precision here, that's why we store the time in seconds and calculate ticks off of it
|
||||||
m_TimeOfDaySecs += (double)a_Dt / 1000.0;
|
m_TimeOfDaySecs += (double)a_Dt / 1000.0;
|
||||||
|
|
||||||
// Wrap time of day each 20 minutes (1200 seconds)
|
// Wrap time of day each 20 minutes (1200 seconds)
|
||||||
@ -838,7 +843,6 @@ void cWorld::Tick(float a_Dt, int a_LastTickDurationMSec)
|
|||||||
m_TimeOfDaySecs -= 1200.0;
|
m_TimeOfDaySecs -= 1200.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_WorldAge = (Int64)(m_WorldAgeSecs * 20.0);
|
|
||||||
m_TimeOfDay = (Int64)(m_TimeOfDaySecs * 20.0);
|
m_TimeOfDay = (Int64)(m_TimeOfDaySecs * 20.0);
|
||||||
|
|
||||||
// Updates the sky darkness based on current time of day
|
// Updates the sky darkness based on current time of day
|
||||||
@ -850,6 +854,7 @@ void cWorld::Tick(float a_Dt, int a_LastTickDurationMSec)
|
|||||||
BroadcastTimeUpdate();
|
BroadcastTimeUpdate();
|
||||||
m_LastTimeUpdate = m_WorldAge;
|
m_LastTimeUpdate = m_WorldAge;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add entities waiting in the queue to be added:
|
// Add entities waiting in the queue to be added:
|
||||||
{
|
{
|
||||||
@ -2243,6 +2248,16 @@ void cWorld::BroadcastThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ, cons
|
|||||||
|
|
||||||
void cWorld::BroadcastTimeUpdate(const cClientHandle * a_Exclude)
|
void cWorld::BroadcastTimeUpdate(const cClientHandle * a_Exclude)
|
||||||
{
|
{
|
||||||
|
int TimeOfDay = m_TimeOfDay;
|
||||||
|
if (!m_DoDaylightCycle)
|
||||||
|
{
|
||||||
|
TimeOfDay *= -1;
|
||||||
|
if (TimeOfDay == 0)
|
||||||
|
{
|
||||||
|
TimeOfDay = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cCSLock Lock(m_CSPlayers);
|
cCSLock Lock(m_CSPlayers);
|
||||||
for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
|
for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
|
||||||
{
|
{
|
||||||
@ -2251,7 +2266,7 @@ void cWorld::BroadcastTimeUpdate(const cClientHandle * a_Exclude)
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ch->SendTimeUpdate(m_WorldAge, m_TimeOfDay);
|
ch->SendTimeUpdate(m_WorldAge, TimeOfDay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
src/World.h
12
src/World.h
@ -146,6 +146,16 @@ public:
|
|||||||
|
|
||||||
int GetTicksUntilWeatherChange(void) const { return m_WeatherInterval; }
|
int GetTicksUntilWeatherChange(void) const { return m_WeatherInterval; }
|
||||||
|
|
||||||
|
/** Is the daylight cyclus enabled? */
|
||||||
|
virtual bool IsDaylightCycleEnabled(void) const { return m_DoDaylightCycle; }
|
||||||
|
|
||||||
|
/** Sets the daylight cyclus to true/false. */
|
||||||
|
virtual void SetDoDaylightCycle(bool a_DoDaylightCycle)
|
||||||
|
{
|
||||||
|
m_DoDaylightCycle = a_DoDaylightCycle;
|
||||||
|
BroadcastTimeUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
virtual Int64 GetWorldAge (void) const override { return m_WorldAge; }
|
virtual Int64 GetWorldAge (void) const override { return m_WorldAge; }
|
||||||
virtual Int64 GetTimeOfDay(void) const override { return m_TimeOfDay; }
|
virtual Int64 GetTimeOfDay(void) const override { return m_TimeOfDay; }
|
||||||
|
|
||||||
@ -158,6 +168,7 @@ public:
|
|||||||
{
|
{
|
||||||
m_TimeOfDay = a_TimeOfDay;
|
m_TimeOfDay = a_TimeOfDay;
|
||||||
m_TimeOfDaySecs = (double)a_TimeOfDay / 20.0;
|
m_TimeOfDaySecs = (double)a_TimeOfDay / 20.0;
|
||||||
|
UpdateSkyDarkness();
|
||||||
BroadcastTimeUpdate();
|
BroadcastTimeUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -868,6 +879,7 @@ private:
|
|||||||
bool m_BroadcastDeathMessages;
|
bool m_BroadcastDeathMessages;
|
||||||
bool m_BroadcastAchievementMessages;
|
bool m_BroadcastAchievementMessages;
|
||||||
|
|
||||||
|
bool m_DoDaylightCycle; // Is the daylight cyclus enabled?
|
||||||
double m_WorldAgeSecs; // World age, in seconds. Is only incremented, cannot be set by plugins.
|
double m_WorldAgeSecs; // World age, in seconds. Is only incremented, cannot be set by plugins.
|
||||||
double m_TimeOfDaySecs; // Time of day in seconds. Can be adjusted. Is wrapped to zero each day.
|
double m_TimeOfDaySecs; // Time of day in seconds. Can be adjusted. Is wrapped to zero each day.
|
||||||
Int64 m_WorldAge; // World age in ticks, calculated off of m_WorldAgeSecs
|
Int64 m_WorldAge; // World age in ticks, calculated off of m_WorldAgeSecs
|
||||||
|
Loading…
Reference in New Issue
Block a user