mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-11 00:09:39 +00:00
SimpleChunkManager: remove post-mature optimisation
these methods are not used in hot paths and are inherently slow anyway, not to mention the introduction of morton codes eliminating the hashtable indexing problem.
This commit is contained in:
parent
ddda2d1e64
commit
d0470a80ab
@ -28,8 +28,6 @@ use pocketmine\block\BlockFactory;
|
|||||||
use pocketmine\block\VanillaBlocks;
|
use pocketmine\block\VanillaBlocks;
|
||||||
use pocketmine\utils\Limits;
|
use pocketmine\utils\Limits;
|
||||||
use pocketmine\world\format\Chunk;
|
use pocketmine\world\format\Chunk;
|
||||||
use pocketmine\world\utils\SubChunkExplorer;
|
|
||||||
use pocketmine\world\utils\SubChunkExplorerStatus;
|
|
||||||
|
|
||||||
class SimpleChunkManager implements ChunkManager{
|
class SimpleChunkManager implements ChunkManager{
|
||||||
|
|
||||||
@ -39,28 +37,23 @@ class SimpleChunkManager implements ChunkManager{
|
|||||||
/** @var int */
|
/** @var int */
|
||||||
protected $worldHeight;
|
protected $worldHeight;
|
||||||
|
|
||||||
/** @var SubChunkExplorer */
|
|
||||||
protected $terrainPointer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SimpleChunkManager constructor.
|
* SimpleChunkManager constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct(int $worldHeight = World::Y_MAX){
|
public function __construct(int $worldHeight = World::Y_MAX){
|
||||||
$this->worldHeight = $worldHeight;
|
$this->worldHeight = $worldHeight;
|
||||||
$this->terrainPointer = new SubChunkExplorer($this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBlockAt(int $x, int $y, int $z) : Block{
|
public function getBlockAt(int $x, int $y, int $z) : Block{
|
||||||
if($this->terrainPointer->moveTo($x, $y, $z) !== SubChunkExplorerStatus::INVALID){
|
if(($chunk = $this->getChunk($x >> 4, $z >> 4)) !== null){
|
||||||
return BlockFactory::getInstance()->fromFullBlock($this->terrainPointer->currentSubChunk->getFullBlock($x & 0xf, $y & 0xf, $z & 0xf));
|
return BlockFactory::getInstance()->fromFullBlock($chunk->getFullBlock($x & 0xf, $y, $z));
|
||||||
}
|
}
|
||||||
return VanillaBlocks::AIR();
|
return VanillaBlocks::AIR();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setBlockAt(int $x, int $y, int $z, Block $block) : void{
|
public function setBlockAt(int $x, int $y, int $z, Block $block) : void{
|
||||||
if($this->terrainPointer->moveTo($x, $y, $z) !== SubChunkExplorerStatus::INVALID){
|
if(($chunk = $this->getChunk($x >> 4, $z >> 4)) !== null){
|
||||||
$this->terrainPointer->currentSubChunk->setFullBlock($x & 0xf, $y & 0xf, $z & 0xf, $block->getFullId());
|
$chunk->setFullBlock($x & 0xf, $y, $z & 0xf, $block->getFullId());
|
||||||
$this->terrainPointer->currentChunk->setDirtyFlag(Chunk::DIRTY_FLAG_TERRAIN, true);
|
|
||||||
}else{
|
}else{
|
||||||
throw new \InvalidArgumentException("Cannot set block at coordinates x=$x,y=$y,z=$z, terrain is not loaded or out of bounds");
|
throw new \InvalidArgumentException("Cannot set block at coordinates x=$x,y=$y,z=$z, terrain is not loaded or out of bounds");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user