mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-18 20:14:31 +00:00
Revert "Level: Identify chunk loaders by their object ID"
This reverts commit 3bb450244f
.
PhpStorm you lying piece of shit... you only showed me the usages in Level!
This change should be revised and redone later.
This commit is contained in:
@@ -39,6 +39,14 @@ use pocketmine\math\Vector3;
|
||||
*/
|
||||
interface ChunkLoader{
|
||||
|
||||
/**
|
||||
* Returns the ChunkLoader id.
|
||||
* Call Level::generateChunkLoaderId($this) to generate and save it
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLoaderId() : int;
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
|
@@ -91,6 +91,7 @@ use pocketmine\utils\ReversePriorityQueue;
|
||||
class Level implements ChunkManager, Metadatable{
|
||||
|
||||
private static $levelIdCounter = 1;
|
||||
private static $chunkLoaderCounter = 1;
|
||||
|
||||
public const Y_MASK = 0xFF;
|
||||
public const Y_MAX = 0x100; //256
|
||||
@@ -279,6 +280,14 @@ class Level implements ChunkManager, Metadatable{
|
||||
$z = ($hash & 0xFFFFFFFF) << 32 >> 32;
|
||||
}
|
||||
|
||||
public static function generateChunkLoaderId(ChunkLoader $loader) : int{
|
||||
if($loader->getLoaderId() === 0){
|
||||
return self::$chunkLoaderCounter++;
|
||||
}else{
|
||||
throw new \InvalidStateException("ChunkLoader has a loader id already assigned: " . $loader->getLoaderId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $str
|
||||
* @return int
|
||||
@@ -615,7 +624,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
}
|
||||
|
||||
public function registerChunkLoader(ChunkLoader $loader, int $chunkX, int $chunkZ, bool $autoLoad = true){
|
||||
$hash = spl_object_id($loader);
|
||||
$hash = $loader->getLoaderId();
|
||||
|
||||
if(!isset($this->chunkLoaders[$index = Level::chunkHash($chunkX, $chunkZ)])){
|
||||
$this->chunkLoaders[$index] = [];
|
||||
@@ -644,7 +653,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
}
|
||||
|
||||
public function unregisterChunkLoader(ChunkLoader $loader, int $chunkX, int $chunkZ){
|
||||
if(isset($this->chunkLoaders[$index = Level::chunkHash($chunkX, $chunkZ)][$hash = spl_object_id($loader)])){
|
||||
if(isset($this->chunkLoaders[$index = Level::chunkHash($chunkX, $chunkZ)][$hash = $loader->getLoaderId()])){
|
||||
unset($this->chunkLoaders[$index][$hash]);
|
||||
unset($this->playerLoaders[$index][$hash]);
|
||||
if(count($this->chunkLoaders[$index]) === 0){
|
||||
|
Reference in New Issue
Block a user