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

View File

@@ -93,7 +93,7 @@ class Human extends Living implements ProjectileSource, InventoryHolder{
protected $baseOffset = 1.62;
public function __construct(Location $location, Skin $skin, CompoundTag $nbt){
public function __construct(Location $location, Skin $skin, ?CompoundTag $nbt = null){
$this->skin = $skin;
parent::__construct($location, $nbt);
}

View File

@@ -55,7 +55,7 @@ class FallingBlock extends Entity{
public $canCollide = false;
public function __construct(Location $location, Block $block, CompoundTag $nbt){
public function __construct(Location $location, Block $block, ?CompoundTag $nbt = null){
$this->block = $block;
parent::__construct($location, $nbt);
}

View File

@@ -65,7 +65,7 @@ class ItemEntity extends Entity{
/** @var int */
protected $despawnDelay = self::DEFAULT_DESPAWN_DELAY;
public function __construct(Location $location, Item $item, CompoundTag $nbt){
public function __construct(Location $location, Item $item, ?CompoundTag $nbt = null){
if($item->isNull()){
throw new \InvalidArgumentException("Item entity must have a non-air item with a count of at least 1");
}

View File

@@ -73,7 +73,7 @@ class Painting extends Entity{
/** @var string */
protected $motive;
public function __construct(Location $location, Vector3 $blockIn, int $facing, PaintingMotive $motive, CompoundTag $nbt){
public function __construct(Location $location, Vector3 $blockIn, int $facing, PaintingMotive $motive, ?CompoundTag $nbt = null){
$this->motive = $motive->getName(); //TODO: use motive directly
$this->blockIn = $blockIn->asVector3();
$this->facing = $facing;

View File

@@ -71,7 +71,7 @@ class Arrow extends Projectile{
/** @var bool */
protected $critical = false;
public function __construct(Location $location, ?Entity $shootingEntity, bool $critical, CompoundTag $nbt){
public function __construct(Location $location, ?Entity $shootingEntity, bool $critical, ?CompoundTag $nbt = null){
parent::__construct($location, $shootingEntity, $nbt);
$this->setCritical($critical);
}

View File

@@ -57,7 +57,7 @@ abstract class Projectile extends Entity{
/** @var Block|null */
protected $blockHit;
public function __construct(Location $location, ?Entity $shootingEntity, CompoundTag $nbt){
public function __construct(Location $location, ?Entity $shootingEntity, ?CompoundTag $nbt = null){
parent::__construct($location, $nbt);
if($shootingEntity !== null){
$this->setOwningEntity($shootingEntity);