mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-18 04:00:29 +00:00
move runtime entity ID counter from EntityFactory back to Entity
EntityFactory is specialized for the purpose of deserializing data from worlds, and runtime ID assignment isn't related.
This commit is contained in:
@@ -77,6 +77,16 @@ abstract class Entity{
|
||||
|
||||
public const MOTION_THRESHOLD = 0.00001;
|
||||
|
||||
/** @var int */
|
||||
private static $entityCount = 1;
|
||||
|
||||
/**
|
||||
* Returns a new runtime entity ID for a new entity.
|
||||
*/
|
||||
public static function nextRuntimeId() : int{
|
||||
return self::$entityCount++;
|
||||
}
|
||||
|
||||
/** @var Player[] */
|
||||
protected $hasSpawned = [];
|
||||
|
||||
@@ -221,7 +231,7 @@ abstract class Entity{
|
||||
$this->eyeHeight = $this->height / 2 + 0.1;
|
||||
}
|
||||
|
||||
$this->id = EntityFactory::nextRuntimeId();
|
||||
$this->id = self::nextRuntimeId();
|
||||
$this->server = $location->getWorldNonNull()->getServer();
|
||||
|
||||
$this->location = $location->asLocation();
|
||||
|
@@ -65,9 +65,6 @@ use function reset;
|
||||
final class EntityFactory{
|
||||
use SingletonTrait;
|
||||
|
||||
/** @var int */
|
||||
private static $entityCount = 1;
|
||||
|
||||
/**
|
||||
* @var \Closure[] base class => creator function
|
||||
* @phpstan-var array<class-string<Entity>, \Closure(World, CompoundTag) : Entity>
|
||||
@@ -223,13 +220,6 @@ final class EntityFactory{
|
||||
$this->saveNames[$className] = $saveNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new runtime entity ID for a new entity.
|
||||
*/
|
||||
public static function nextRuntimeId() : int{
|
||||
return self::$entityCount++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an entity from data stored on a chunk.
|
||||
*
|
||||
|
Reference in New Issue
Block a user