22declare(strict_types=1);
24namespace pocketmine\world\utils;
31 public ?
Chunk $currentChunk =
null;
32 public ?
SubChunk $currentSubChunk =
null;
34 protected int $currentX;
35 protected int $currentY;
36 protected int $currentZ;
38 public function __construct(
45 public function moveTo(
int $x,
int $y,
int $z) : int{
46 $newChunkX = $x >>
SubChunk::COORD_BIT_SIZE;
47 $newChunkZ = $z >> SubChunk::COORD_BIT_SIZE;
48 if($this->currentChunk ===
null || $this->currentX !== $newChunkX || $this->currentZ !== $newChunkZ){
49 $this->currentX = $newChunkX;
50 $this->currentZ = $newChunkZ;
51 $this->currentSubChunk =
null;
53 $this->currentChunk = $this->world->getChunk($this->currentX, $this->currentZ);
54 if($this->currentChunk ===
null){
59 $newChunkY = $y >> SubChunk::COORD_BIT_SIZE;
60 if($this->currentSubChunk ===
null || $this->currentY !== $newChunkY){
61 $this->currentY = $newChunkY;
63 if($this->currentY < Chunk::MIN_SUBCHUNK_INDEX || $this->currentY > Chunk::MAX_SUBCHUNK_INDEX){
64 $this->currentSubChunk =
null;
68 $this->currentSubChunk = $this->currentChunk->getSubChunk($newChunkY);
78 public function moveToChunk(
int $chunkX,
int $chunkY,
int $chunkZ) : int{
80 return $this->moveTo($chunkX <<
SubChunk::COORD_BIT_SIZE, $chunkY <<
SubChunk::COORD_BIT_SIZE, $chunkZ <<
SubChunk::COORD_BIT_SIZE);
87 return $this->currentSubChunk !== null;
90 public function invalidate() : void{
91 $this->currentChunk = null;
92 $this->currentSubChunk =
null;
moveToChunk(int $chunkX, int $chunkY, int $chunkZ)
moveTo(int $x, int $y, int $z)