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:
Dylan K. Taylor 2020-06-19 21:55:49 +01:00
parent 6d3750994b
commit 012acdd4cb
3 changed files with 13 additions and 13 deletions

View File

@ -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();

View File

@ -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.
*

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine\world\particle;
use pocketmine\entity\EntityFactory;
use pocketmine\entity\Entity;
use pocketmine\entity\Skin;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\convert\SkinAdapterSingleton;
@ -84,7 +84,7 @@ class FloatingTextParticle implements Particle{
$p = [];
if($this->entityId === null){
$this->entityId = EntityFactory::nextRuntimeId();
$this->entityId = Entity::nextRuntimeId();
}else{
$p[] = RemoveActorPacket::create($this->entityId);
}