world = $world; } /** * @phpstan-return SubChunkExplorerStatus::* */ public function moveTo(int $x, int $y, int $z) : int{ $newChunkX = $x >> 4; $newChunkZ = $z >> 4; if($this->currentChunk === null or $this->currentX !== $newChunkX or $this->currentZ !== $newChunkZ){ $this->currentX = $newChunkX; $this->currentZ = $newChunkZ; $this->currentSubChunk = null; $this->currentChunk = $this->world->getChunk($this->currentX, $this->currentZ); if($this->currentChunk === null){ return SubChunkExplorerStatus::INVALID; } } $newChunkY = $y >> 4; if($this->currentSubChunk === null or $this->currentY !== $newChunkY){ $this->currentY = $newChunkY; if($this->currentY < 0 or $this->currentY >= $this->currentChunk->getHeight()){ $this->currentSubChunk = null; return SubChunkExplorerStatus::INVALID; } $this->currentSubChunk = $this->currentChunk->getSubChunk($newChunkY); return SubChunkExplorerStatus::MOVED; } return SubChunkExplorerStatus::OK; } /** * @phpstan-return SubChunkExplorerStatus::* */ 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); } /** * Returns whether we currently have a valid terrain pointer. */ public function isValid() : bool{ return $this->currentSubChunk !== null; } public function invalidate() : void{ $this->currentChunk = null; $this->currentSubChunk = null; } }