PocketMine-MP 5.23.3 git-fbaa125d0ce21ffef98fc1630881a92bedfbaa73
Loading...
Searching...
No Matches
SubChunkExplorer.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\world\utils;
25
29
31 public ?Chunk $currentChunk = null;
32 public ?SubChunk $currentSubChunk = null;
33
34 protected int $currentX;
35 protected int $currentY;
36 protected int $currentZ;
37
38 public function __construct(
39 protected ChunkManager $world
40 ){}
41
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;
52
53 $this->currentChunk = $this->world->getChunk($this->currentX, $this->currentZ);
54 if($this->currentChunk === null){
56 }
57 }
58
59 $newChunkY = $y >> SubChunk::COORD_BIT_SIZE;
60 if($this->currentSubChunk === null || $this->currentY !== $newChunkY){
61 $this->currentY = $newChunkY;
62
63 if($this->currentY < Chunk::MIN_SUBCHUNK_INDEX || $this->currentY > Chunk::MAX_SUBCHUNK_INDEX){
64 $this->currentSubChunk = null;
66 }
67
68 $this->currentSubChunk = $this->currentChunk->getSubChunk($newChunkY);
70 }
71
73 }
74
78 public function moveToChunk(int $chunkX, int $chunkY, int $chunkZ) : int{
79 //this is a cold path, so we don't care much if it's a bit slower (extra fcall overhead)
80 return $this->moveTo($chunkX << SubChunk::COORD_BIT_SIZE, $chunkY << SubChunk::COORD_BIT_SIZE, $chunkZ << SubChunk::COORD_BIT_SIZE);
81 }
82
86 public function isValid() : bool{
87 return $this->currentSubChunk !== null;
88 }
89
90 public function invalidate() : void{
91 $this->currentChunk = null;
92 $this->currentSubChunk = null;
93 }
94}
moveToChunk(int $chunkX, int $chunkY, int $chunkZ)