diff --git a/src/item/Item.php b/src/item/Item.php index b8f186479..e3c73ef86 100644 --- a/src/item/Item.php +++ b/src/item/Item.php @@ -68,8 +68,8 @@ class Item implements \JsonSerializable{ protected $id; /** @var int */ protected $meta; - /** @var CompoundTag|null */ - private $nbt = null; + /** @var CompoundTag */ + private $nbt; /** @var int */ protected $count = 1; /** @var string */ @@ -115,6 +115,7 @@ class Item implements \JsonSerializable{ $this->canPlaceOn = new Set(); $this->canDestroy = new Set(); + $this->nbt = new CompoundTag(); } public function hasCustomBlockData() : bool{ @@ -234,9 +235,6 @@ class Item implements \JsonSerializable{ * object is returned to allow the caller to manipulate and apply back to the item. */ public function getNamedTag() : CompoundTag{ - if($this->nbt === null){ - $this->nbt = new CompoundTag(); - } $this->serializeCompoundTag($this->nbt); return $this->nbt; } @@ -686,9 +684,7 @@ class Item implements \JsonSerializable{ } public function __clone(){ - if($this->nbt !== null){ - $this->nbt = clone $this->nbt; - } + $this->nbt = clone $this->nbt; if($this->blockEntityTag !== null){ $this->blockEntityTag = clone $this->blockEntityTag; } diff --git a/tests/phpstan/configs/l8-baseline.neon b/tests/phpstan/configs/l8-baseline.neon index 2ee317c4f..9d9e600da 100644 --- a/tests/phpstan/configs/l8-baseline.neon +++ b/tests/phpstan/configs/l8-baseline.neon @@ -145,11 +145,6 @@ parameters: count: 1 path: ../../../src/inventory/transaction/CraftingTransaction.php - - - message: "#^Method pocketmine\\\\item\\\\Item\\:\\:getNamedTag\\(\\) should return pocketmine\\\\nbt\\\\tag\\\\CompoundTag but returns pocketmine\\\\nbt\\\\tag\\\\CompoundTag\\|null\\.$#" - count: 1 - path: ../../../src/item/Item.php - - message: "#^Cannot clone pocketmine\\\\nbt\\\\tag\\\\CompoundTag\\|null\\.$#" count: 1