NBT is no longer needed to create an entity

it's still able to be provided, but shouldn't be needed in the majority of cases (constructor args and/or API methods should be sufficient).
This commit is contained in:
Dylan K. Taylor
2020-06-19 09:49:06 +01:00
parent 0a1bb0041b
commit 4b528aa637
14 changed files with 19 additions and 24 deletions

View File

@@ -213,7 +213,7 @@ abstract class Entity{
/** @var int|null */
protected $targetId = null;
public function __construct(Location $location, CompoundTag $nbt){
public function __construct(Location $location, ?CompoundTag $nbt = null){
$this->timings = Timings::getEntityTimings($this);
$this->temporalVector = new Vector3();
@@ -241,7 +241,7 @@ abstract class Entity{
}
$this->motion = new Vector3(0, 0, 0);
if($nbt->hasTag("Motion", ListTag::class)){
if($nbt !== null and $nbt->hasTag("Motion", ListTag::class)){
/** @var float[] $motion */
$motion = $nbt->getListTag("Motion")->getAllValues();
$this->setMotion($this->temporalVector->setComponents(...$motion));
@@ -254,7 +254,7 @@ abstract class Entity{
$this->attributeMap = new AttributeMap();
$this->addAttributes();
$this->initEntity($nbt);
$this->initEntity($nbt ?? new CompoundTag());
$this->chunk->addEntity($this);
$this->getWorld()->addEntity($this);