Stop hardcoding chunk dimensions everywhere (#4443)

This commit is contained in:
Dylan T
2021-09-10 16:13:25 +01:00
committed by GitHub
parent 9d5a86fe53
commit 4111d92b98
24 changed files with 166 additions and 140 deletions

View File

@ -51,8 +51,8 @@ class SubChunkExplorer{
* @phpstan-return SubChunkExplorerStatus::*
*/
public function moveTo(int $x, int $y, int $z) : int{
$newChunkX = $x >> 4;
$newChunkZ = $z >> 4;
$newChunkX = $x >> SubChunk::COORD_BIT_SIZE;
$newChunkZ = $z >> SubChunk::COORD_BIT_SIZE;
if($this->currentChunk === null or $this->currentX !== $newChunkX or $this->currentZ !== $newChunkZ){
$this->currentX = $newChunkX;
$this->currentZ = $newChunkZ;
@ -64,7 +64,7 @@ class SubChunkExplorer{
}
}
$newChunkY = $y >> 4;
$newChunkY = $y >> SubChunk::COORD_BIT_SIZE;
if($this->currentSubChunk === null or $this->currentY !== $newChunkY){
$this->currentY = $newChunkY;
@ -85,7 +85,7 @@ class SubChunkExplorer{
*/
public function moveToChunk(int $chunkX, int $chunkY, int $chunkZ) : int{
//this is a cold path, so we don't care much if it's a bit slower (extra fcall overhead)
return $this->moveTo($chunkX << 4, $chunkY << 4, $chunkZ << 4);
return $this->moveTo($chunkX << SubChunk::COORD_BIT_SIZE, $chunkY << SubChunk::COORD_BIT_SIZE, $chunkZ << SubChunk::COORD_BIT_SIZE);
}
/**