Merge branch 'next-minor' into next-major

This commit is contained in:
Dylan K. Taylor
2022-11-13 14:32:54 +00:00
2 changed files with 53 additions and 2 deletions

View File

@ -1127,6 +1127,21 @@ class World implements ChunkManager{
unset($this->randomTickBlocks[$block->getStateId()]);
}
/**
* Returns the radius of chunks to be ticked around each ticking chunk loader (usually players). This is referred to
* as "simulation distance" in the Minecraft: Bedrock world options screen.
*/
public function getChunkTickRadius() : int{
return $this->chunkTickRadius;
}
/**
* Sets the radius of chunks ticked around each ticking chunk loader (usually players).
*/
public function setChunkTickRadius(int $radius) : void{
$this->chunkTickRadius = $radius;
}
private function tickChunks() : void{
if($this->chunkTickRadius <= 0 || count($this->tickingLoaders) === 0){
return;
@ -1137,12 +1152,23 @@ class World implements ChunkManager{
/** @var bool[] $chunkTickList chunkhash => dummy */
$chunkTickList = [];
$centerChunks = [];
$selector = new ChunkSelector();
foreach($this->tickingLoaders as $loader){
$centerChunkX = (int) floor($loader->getX()) >> Chunk::COORD_BIT_SIZE;
$centerChunkZ = (int) floor($loader->getZ()) >> Chunk::COORD_BIT_SIZE;
$centerChunkPosHash = World::chunkHash($centerChunkX, $centerChunkZ);
if(isset($centerChunks[$centerChunkPosHash])){
//we already queued chunks in this radius because of a previous loader on the same chunk
continue;
}
$centerChunks[$centerChunkPosHash] = true;
foreach($selector->selectChunks(
$this->chunkTickRadius,
(int) floor($loader->getX()) >> Chunk::COORD_BIT_SIZE,
(int) floor($loader->getZ()) >> Chunk::COORD_BIT_SIZE
$centerChunkX,
$centerChunkZ
) as $hash){
World::getXZ($hash, $chunkX, $chunkZ);
if(!isset($chunkTickList[$hash]) && isset($this->chunks[$hash]) && $this->isChunkTickable($chunkX, $chunkZ)){