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/BlockEntities/HopperEntity.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src/BlockEntities/HopperEntity.cpp') diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp index 9c9f229e4..58a5fd565 100644 --- a/src/BlockEntities/HopperEntity.cpp +++ b/src/BlockEntities/HopperEntity.cpp @@ -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; -- cgit v1.2.3