mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-05 01:16:15 +00:00
Improved Level->getTile() to a direct lookup instead of linear search
This commit is contained in:
@ -37,6 +37,9 @@ abstract class BaseFullChunk implements FullChunk{
|
||||
/** @var Tile[] */
|
||||
protected $tiles = [];
|
||||
|
||||
/** @var Tile[] */
|
||||
protected $tileList = [];
|
||||
|
||||
/** @var string */
|
||||
protected $biomeIds;
|
||||
|
||||
@ -234,11 +237,13 @@ abstract class BaseFullChunk implements FullChunk{
|
||||
|
||||
public function addTile(Tile $tile){
|
||||
$this->tiles[$tile->getID()] = $tile;
|
||||
$this->tiles[(($tile->z & 0x0f) << 8) | (($tile->x & 0x0f) << 4) | ($tile->y & 0x7f)] = $tile;
|
||||
$this->hasChanged = true;
|
||||
}
|
||||
|
||||
public function removeTile(Tile $tile){
|
||||
unset($this->tiles[$tile->getID()]);
|
||||
unset($this->tiles[(($tile->z & 0x0f) << 8) | (($tile->x & 0x0f) << 4) | ($tile->y & 0x7f)]);
|
||||
$this->hasChanged = true;
|
||||
}
|
||||
|
||||
@ -250,6 +255,11 @@ abstract class BaseFullChunk implements FullChunk{
|
||||
return $this->tiles;
|
||||
}
|
||||
|
||||
public function getTile($x, $y, $z){
|
||||
$index = ($z << 8) | ($x << 4) | $y;
|
||||
return isset($this->tileList[$index]) ? $this->tileList[$index] : null;
|
||||
}
|
||||
|
||||
public function isLoaded(){
|
||||
return $this->getProvider() === null ? false : $this->getProvider()->isChunkLoaded($this->getX(), $this->getZ());
|
||||
}
|
||||
|
Reference in New Issue
Block a user