Item: make nbt field non-nullable

This commit is contained in:
Dylan K. Taylor 2020-06-27 13:34:08 +01:00
parent 7e331c590d
commit 0000783926
2 changed files with 4 additions and 13 deletions

View File

@ -68,8 +68,8 @@ class Item implements \JsonSerializable{
protected $id; protected $id;
/** @var int */ /** @var int */
protected $meta; protected $meta;
/** @var CompoundTag|null */ /** @var CompoundTag */
private $nbt = null; private $nbt;
/** @var int */ /** @var int */
protected $count = 1; protected $count = 1;
/** @var string */ /** @var string */
@ -115,6 +115,7 @@ class Item implements \JsonSerializable{
$this->canPlaceOn = new Set(); $this->canPlaceOn = new Set();
$this->canDestroy = new Set(); $this->canDestroy = new Set();
$this->nbt = new CompoundTag();
} }
public function hasCustomBlockData() : bool{ 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. * object is returned to allow the caller to manipulate and apply back to the item.
*/ */
public function getNamedTag() : CompoundTag{ public function getNamedTag() : CompoundTag{
if($this->nbt === null){
$this->nbt = new CompoundTag();
}
$this->serializeCompoundTag($this->nbt); $this->serializeCompoundTag($this->nbt);
return $this->nbt; return $this->nbt;
} }
@ -686,9 +684,7 @@ class Item implements \JsonSerializable{
} }
public function __clone(){ public function __clone(){
if($this->nbt !== null){
$this->nbt = clone $this->nbt; $this->nbt = clone $this->nbt;
}
if($this->blockEntityTag !== null){ if($this->blockEntityTag !== null){
$this->blockEntityTag = clone $this->blockEntityTag; $this->blockEntityTag = clone $this->blockEntityTag;
} }

View File

@ -145,11 +145,6 @@ parameters:
count: 1 count: 1
path: ../../../src/inventory/transaction/CraftingTransaction.php 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\\.$#" message: "#^Cannot clone pocketmine\\\\nbt\\\\tag\\\\CompoundTag\\|null\\.$#"
count: 1 count: 1