mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-06 01:51:51 +00:00
World: Extracted a tickChunk() method from tickChunks()
most of what's left in tickChunks() is just selecting the chunks, rather than actually ticking them.
This commit is contained in:
parent
bab76f4a6e
commit
7abf50f503
@ -1002,35 +1002,7 @@ class World implements ChunkManager{
|
|||||||
foreach($chunkTickList as $index => $_){
|
foreach($chunkTickList as $index => $_){
|
||||||
World::getXZ($index, $chunkX, $chunkZ);
|
World::getXZ($index, $chunkX, $chunkZ);
|
||||||
|
|
||||||
$chunk = $this->chunks[$index];
|
$this->tickChunk($chunkX, $chunkZ);
|
||||||
foreach($chunk->getEntities() as $entity){
|
|
||||||
$entity->onRandomUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($chunk->getSubChunks() as $Y => $subChunk){
|
|
||||||
if(!$subChunk->isEmptyFast()){
|
|
||||||
$k = 0;
|
|
||||||
for($i = 0; $i < $this->tickedBlocksPerSubchunkPerTick; ++$i){
|
|
||||||
if(($i % 5) === 0){
|
|
||||||
//60 bits will be used by 5 blocks (12 bits each)
|
|
||||||
$k = mt_rand(0, (1 << 60) - 1);
|
|
||||||
}
|
|
||||||
$x = $k & 0x0f;
|
|
||||||
$y = ($k >> 4) & 0x0f;
|
|
||||||
$z = ($k >> 8) & 0x0f;
|
|
||||||
$k >>= 12;
|
|
||||||
|
|
||||||
$state = $subChunk->getFullBlock($x, $y, $z);
|
|
||||||
|
|
||||||
if(isset($this->randomTickBlocks[$state])){
|
|
||||||
/** @var Block $block */
|
|
||||||
$block = BlockFactory::getInstance()->fromFullBlock($state);
|
|
||||||
$block->position($this, $chunkX * 16 + $x, ($Y << 4) + $y, $chunkZ * 16 + $z);
|
|
||||||
$block->onRandomTick();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1094,6 +1066,41 @@ class World implements ChunkManager{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function tickChunk(int $chunkX, int $chunkZ) : void{
|
||||||
|
$chunk = $this->getChunk($chunkX, $chunkZ);
|
||||||
|
if($chunk === null){
|
||||||
|
throw new \InvalidArgumentException("Chunk is not loaded");
|
||||||
|
}
|
||||||
|
foreach($chunk->getEntities() as $entity){
|
||||||
|
$entity->onRandomUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($chunk->getSubChunks() as $Y => $subChunk){
|
||||||
|
if(!$subChunk->isEmptyFast()){
|
||||||
|
$k = 0;
|
||||||
|
for($i = 0; $i < $this->tickedBlocksPerSubchunkPerTick; ++$i){
|
||||||
|
if(($i % 5) === 0){
|
||||||
|
//60 bits will be used by 5 blocks (12 bits each)
|
||||||
|
$k = mt_rand(0, (1 << 60) - 1);
|
||||||
|
}
|
||||||
|
$x = $k & 0x0f;
|
||||||
|
$y = ($k >> 4) & 0x0f;
|
||||||
|
$z = ($k >> 8) & 0x0f;
|
||||||
|
$k >>= 12;
|
||||||
|
|
||||||
|
$state = $subChunk->getFullBlock($x, $y, $z);
|
||||||
|
|
||||||
|
if(isset($this->randomTickBlocks[$state])){
|
||||||
|
/** @var Block $block */
|
||||||
|
$block = BlockFactory::getInstance()->fromFullBlock($state);
|
||||||
|
$block->position($this, $chunkX * 16 + $x, ($Y << 4) + $y, $chunkZ * 16 + $z);
|
||||||
|
$block->onRandomTick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed[]
|
* @return mixed[]
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user