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.
This commit is contained in:
@@ -296,8 +296,10 @@ void cBeaconEntity::SendTo(cClientHandle & a_Client)
|
||||
|
||||
bool cBeaconEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
||||
{
|
||||
// Update the beacon every 4 seconds
|
||||
if ((GetWorld()->GetWorldAge() % 80) == 0)
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
// Update the beacon every 4 seconds:
|
||||
if ((GetWorld()->GetWorldTickAge() % 4s) == 0s)
|
||||
{
|
||||
UpdateBeacon();
|
||||
GiveEffects();
|
||||
|
||||
@@ -288,8 +288,8 @@ void cBrewingstandEntity::OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum)
|
||||
|
||||
void cBrewingstandEntity::UpdateProgressBars(bool a_ForceUpdate)
|
||||
{
|
||||
/** Sending an update every 3th tick, using a higher value lets look the progressbar ugly */
|
||||
if (!a_ForceUpdate && (m_World->GetWorldAge() % 3 != 0))
|
||||
// Send an update every 3rd tick, using a higher value makes the progressbar look ugly:
|
||||
if (!a_ForceUpdate && ((m_World->GetWorldTickAge() % 3_tick) != 0_tick))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -388,8 +388,8 @@ bool cFurnaceEntity::CanCookInputToOutput(void) const
|
||||
|
||||
void cFurnaceEntity::UpdateProgressBars(bool a_ForceUpdate)
|
||||
{
|
||||
// In order to preserve bandwidth, an update is sent only every 10th tick
|
||||
if (!a_ForceUpdate && (m_World->GetWorldAge() % 10 != 0))
|
||||
// In order to preserve bandwidth, an update is sent only every 10th tick:
|
||||
if (!a_ForceUpdate && ((m_World->GetWorldTickAge() % 10_tick) != 0_tick))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,13 @@
|
||||
|
||||
|
||||
|
||||
// How many ticks at minimum between two item transfers to or from the hopper.
|
||||
#define TICKS_PER_TRANSFER 8_tick
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cHopperEntity::cHopperEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld * a_World):
|
||||
Super(a_BlockType, a_BlockMeta, a_Pos, ContentsWidth, ContentsHeight, a_World),
|
||||
m_LastMoveItemsInTick(0),
|
||||
@@ -76,14 +83,14 @@ void cHopperEntity::CopyFrom(const cBlockEntity & a_Src)
|
||||
bool cHopperEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
||||
{
|
||||
UNUSED(a_Dt);
|
||||
Int64 CurrentTick = a_Chunk.GetWorld()->GetWorldAge();
|
||||
|
||||
bool isDirty = false;
|
||||
if (!m_Locked)
|
||||
{
|
||||
isDirty = MoveItemsIn (a_Chunk, CurrentTick) || isDirty;
|
||||
isDirty = MovePickupsIn(a_Chunk, CurrentTick) || isDirty;
|
||||
isDirty = MoveItemsOut (a_Chunk, CurrentTick) || isDirty;
|
||||
const auto CurrentTick = a_Chunk.GetWorld()->GetWorldAge();
|
||||
isDirty = MoveItemsIn(a_Chunk, CurrentTick) || isDirty;
|
||||
isDirty = MovePickupsIn(a_Chunk) || isDirty;
|
||||
isDirty = MoveItemsOut(a_Chunk, CurrentTick) || isDirty;
|
||||
}
|
||||
return isDirty;
|
||||
}
|
||||
@@ -147,7 +154,7 @@ void cHopperEntity::OpenNewWindow(void)
|
||||
|
||||
|
||||
|
||||
bool cHopperEntity::MoveItemsIn(cChunk & a_Chunk, Int64 a_CurrentTick)
|
||||
bool cHopperEntity::MoveItemsIn(cChunk & a_Chunk, const cTickTimeLong a_CurrentTick)
|
||||
{
|
||||
if (m_Pos.y >= cChunkDef::Height)
|
||||
{
|
||||
@@ -155,7 +162,7 @@ bool cHopperEntity::MoveItemsIn(cChunk & a_Chunk, Int64 a_CurrentTick)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (a_CurrentTick - m_LastMoveItemsInTick < TICKS_PER_TRANSFER)
|
||||
if ((a_CurrentTick - m_LastMoveItemsInTick) < TICKS_PER_TRANSFER)
|
||||
{
|
||||
// Too early after the previous transfer
|
||||
return false;
|
||||
@@ -201,10 +208,8 @@ bool cHopperEntity::MoveItemsIn(cChunk & a_Chunk, Int64 a_CurrentTick)
|
||||
|
||||
|
||||
|
||||
bool cHopperEntity::MovePickupsIn(cChunk & a_Chunk, Int64 a_CurrentTick)
|
||||
bool cHopperEntity::MovePickupsIn(cChunk & a_Chunk)
|
||||
{
|
||||
UNUSED(a_CurrentTick);
|
||||
|
||||
class cHopperPickupSearchCallback
|
||||
{
|
||||
public:
|
||||
@@ -290,9 +295,9 @@ bool cHopperEntity::MovePickupsIn(cChunk & a_Chunk, Int64 a_CurrentTick)
|
||||
|
||||
|
||||
|
||||
bool cHopperEntity::MoveItemsOut(cChunk & a_Chunk, Int64 a_CurrentTick)
|
||||
bool cHopperEntity::MoveItemsOut(cChunk & a_Chunk, const cTickTimeLong a_CurrentTick)
|
||||
{
|
||||
if (a_CurrentTick - m_LastMoveItemsOutTick < TICKS_PER_TRANSFER)
|
||||
if ((a_CurrentTick - m_LastMoveItemsOutTick) < TICKS_PER_TRANSFER)
|
||||
{
|
||||
// Too early after the previous transfer
|
||||
return false;
|
||||
|
||||
@@ -30,8 +30,7 @@ public:
|
||||
enum
|
||||
{
|
||||
ContentsHeight = 1,
|
||||
ContentsWidth = 5,
|
||||
TICKS_PER_TRANSFER = 8, ///< How many ticks at minimum between two item transfers to or from the hopper
|
||||
ContentsWidth = 5
|
||||
} ;
|
||||
|
||||
// tolua_end
|
||||
@@ -48,8 +47,8 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
Int64 m_LastMoveItemsInTick;
|
||||
Int64 m_LastMoveItemsOutTick;
|
||||
cTickTimeLong m_LastMoveItemsInTick;
|
||||
cTickTimeLong m_LastMoveItemsOutTick;
|
||||
|
||||
// cBlockEntity overrides:
|
||||
virtual void CopyFrom(const cBlockEntity & a_Src) override;
|
||||
@@ -61,13 +60,13 @@ protected:
|
||||
void OpenNewWindow(void);
|
||||
|
||||
/** Moves items from the container above it into this hopper. Returns true if the contents have changed. */
|
||||
bool MoveItemsIn(cChunk & a_Chunk, Int64 a_CurrentTick);
|
||||
bool MoveItemsIn(cChunk & a_Chunk, cTickTimeLong a_CurrentTick);
|
||||
|
||||
/** Moves pickups from above this hopper into it. Returns true if the contents have changed. */
|
||||
bool MovePickupsIn(cChunk & a_Chunk, Int64 a_CurrentTick);
|
||||
bool MovePickupsIn(cChunk & a_Chunk);
|
||||
|
||||
/** Moves items out from this hopper into the destination. Returns true if the contents have changed. */
|
||||
bool MoveItemsOut(cChunk & a_Chunk, Int64 a_CurrentTick);
|
||||
bool MoveItemsOut(cChunk & a_Chunk, cTickTimeLong a_CurrentTick);
|
||||
|
||||
/** Moves items from a chest (dblchest) above the hopper into this hopper. Returns true if contents have changed. */
|
||||
bool MoveItemsFromChest(cChunk & a_Chunk);
|
||||
|
||||
@@ -92,8 +92,10 @@ void cMobSpawnerEntity::UpdateActiveState(void)
|
||||
|
||||
bool cMobSpawnerEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
||||
{
|
||||
// Update the active flag every 5 seconds
|
||||
if ((m_World->GetWorldAge() % 100) == 0)
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
// Update the active flag every 5 seconds:
|
||||
if ((m_World->GetWorldTickAge() % 5s) == 0s)
|
||||
{
|
||||
UpdateActiveState();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user