mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-07 10:31:51 +00:00
Added a SubChunkIteratorManager class for faster subchunk handling
This commit is contained in:
parent
523a7f0999
commit
4703715063
78
src/pocketmine/level/utils/SubChunkIteratorManager.php
Normal file
78
src/pocketmine/level/utils/SubChunkIteratorManager.php
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace pocketmine\level\utils;
|
||||||
|
|
||||||
|
use pocketmine\level\ChunkManager;
|
||||||
|
use pocketmine\level\format\Chunk;
|
||||||
|
use pocketmine\level\format\EmptySubChunk;
|
||||||
|
use pocketmine\level\format\SubChunkInterface;
|
||||||
|
|
||||||
|
class SubChunkIteratorManager{
|
||||||
|
/** @var ChunkManager */
|
||||||
|
public $level;
|
||||||
|
|
||||||
|
/** @var Chunk|null */
|
||||||
|
public $currentChunk;
|
||||||
|
/** @var SubChunkInterface|null */
|
||||||
|
public $currentSubChunk;
|
||||||
|
|
||||||
|
/** @var int */
|
||||||
|
protected $currentX;
|
||||||
|
/** @var int */
|
||||||
|
protected $currentY;
|
||||||
|
/** @var int */
|
||||||
|
protected $currentZ;
|
||||||
|
/** @var bool */
|
||||||
|
protected $allocateEmptySubs = true;
|
||||||
|
|
||||||
|
public function __construct(ChunkManager $level, bool $allocateEmptySubs = true){
|
||||||
|
$this->level = $level;
|
||||||
|
$this->allocateEmptySubs = $allocateEmptySubs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function moveTo(int $x, int $y, int $z) : bool{
|
||||||
|
if($this->currentChunk === null or $this->currentX !== ($x >> 4) or $this->currentZ !== ($z >> 4)){
|
||||||
|
$this->currentX = $x >> 4;
|
||||||
|
$this->currentZ = $z >> 4;
|
||||||
|
$this->currentSubChunk = null;
|
||||||
|
|
||||||
|
$this->currentChunk = $this->level->getChunk($this->currentX, $this->currentZ);
|
||||||
|
if($this->currentChunk === null){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->currentSubChunk === null or $this->currentY !== ($y >> 4)){
|
||||||
|
$this->currentY = $y >> 4;
|
||||||
|
|
||||||
|
$this->currentSubChunk = $this->currentChunk->getSubChunk($y >> 4, $this->allocateEmptySubs);
|
||||||
|
if($this->currentSubChunk instanceof EmptySubChunk){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user