diff options
author | Tiger Wang <ziwei.tiger@outlook.com> | 2021-04-10 21:01:01 +0200 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@outlook.com> | 2021-04-12 23:35:07 +0200 |
commit | d06930de7592e731493cbe5f3004ee3d1457a38f (patch) | |
tree | 292b6ab71cea21b83dd6068c338802750b7f6598 /src/Chunk.cpp | |
parent | Hoppers: use 'locked' bit in meta (diff) | |
download | cuberite-d06930de7592e731493cbe5f3004ee3d1457a38f.tar cuberite-d06930de7592e731493cbe5f3004ee3d1457a38f.tar.gz cuberite-d06930de7592e731493cbe5f3004ee3d1457a38f.tar.bz2 cuberite-d06930de7592e731493cbe5f3004ee3d1457a38f.tar.lz cuberite-d06930de7592e731493cbe5f3004ee3d1457a38f.tar.xz cuberite-d06930de7592e731493cbe5f3004ee3d1457a38f.tar.zst cuberite-d06930de7592e731493cbe5f3004ee3d1457a38f.zip |
Diffstat (limited to 'src/Chunk.cpp')
-rw-r--r-- | src/Chunk.cpp | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/src/Chunk.cpp b/src/Chunk.cpp index aa2a2887c..aa1544c7d 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -849,27 +849,35 @@ void cChunk::CheckBlocks() void cChunk::TickBlocks(void) { - cChunkInterface ChunkInterface(this->GetWorld()->GetChunkMap()); - cBlockInServerPluginInterface PluginInterface(*this->GetWorld()); + cChunkInterface ChunkInterface(m_World->GetChunkMap()); + cBlockInServerPluginInterface PluginInterface(*m_World); + + // Tick random blocks, but the first one should be m_BlockToTick (so that SetNextBlockToTick() works): + cBlockHandler::For(GetBlock(m_BlockToTick)).OnUpdate(ChunkInterface, *m_World, PluginInterface, *this, m_BlockToTick); - // Tick random blocks, but the first one should be m_BlockToTick (so that SetNextBlockToTick() works) - auto Idx = cChunkDef::MakeIndexNoCheck(m_BlockToTick); auto & Random = GetRandomProvider(); - for (int i = 0; i < 50; ++i) + // Set a new random coord for the next tick: + m_BlockToTick = cChunkDef::IndexToCoordinate(Random.RandInt<size_t>(cChunkDef::NumBlocks - 1)); + + // Choose a number of blocks for each section to randomly tick. + // http://minecraft.fandom.com/wiki/Tick#Random_tick + for (size_t Y = 0; Y < cChunkDef::NumSections; ++Y) { - auto Pos = cChunkDef::IndexToCoordinate(static_cast<size_t>(Idx)); - Idx = Random.RandInt(cChunkDef::NumBlocks - 1); - if (Pos.y > cChunkDef::GetHeight(m_HeightMap, Pos.x, Pos.z)) + const auto Section = m_BlockData.GetSection(Y); + if (Section == nullptr) { - continue; // It's all air up here + continue; } - cBlockHandler::For(GetBlock(Pos)).OnUpdate(ChunkInterface, *this->GetWorld(), PluginInterface, *this, Pos); - } // for i + for (int Tick = 0; Tick != 3; Tick++) // TODO: configurability via gamerule randomTickSpeed + { + const auto Index = Random.RandInt<size_t>(ChunkBlockData::SectionBlockCount - 1); + const auto Position = cChunkDef::IndexToCoordinate(Y * ChunkBlockData::SectionBlockCount + Index); - // Set a new random coord for the next tick: - m_BlockToTick = cChunkDef::IndexToCoordinate(static_cast<size_t>(Idx)); + cBlockHandler::For((*Section)[Index]).OnUpdate(ChunkInterface, *m_World, PluginInterface, *this, Position); + } + } } |