Document that Item::setNamedTag() may cause NbtException to be thrown

if the NBT is bogus for some reason
in PM3, these kinds of bugs wouldn't show up until/unless the item NBT was actually used, but on PM4, we decode it ahead of time, so the errors always show up immediately.
This commit is contained in:
Dylan K. Taylor 2021-10-05 19:09:22 +01:00
parent 2db79cf58d
commit dbeaf27cb7
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 8 additions and 0 deletions

View File

@ -37,6 +37,7 @@ use pocketmine\math\Vector3;
use pocketmine\nbt\LittleEndianNbtSerializer;
use pocketmine\nbt\NBT;
use pocketmine\nbt\NbtDataException;
use pocketmine\nbt\NbtException;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\ShortTag;
@ -240,6 +241,7 @@ class Item implements \JsonSerializable{
* Sets the Item's NBT from the supplied CompoundTag object.
*
* @return $this
* @throws NbtException
*/
public function setNamedTag(CompoundTag $tag) : Item{
if($tag->getCount() === 0){
@ -255,6 +257,7 @@ class Item implements \JsonSerializable{
/**
* Removes the Item's NBT.
* @return $this
* @throws NbtException
*/
public function clearNamedTag() : Item{
$this->nbt = new CompoundTag();
@ -262,6 +265,9 @@ class Item implements \JsonSerializable{
return $this;
}
/**
* @throws NbtException
*/
protected function deserializeCompoundTag(CompoundTag $tag) : void{
$this->customName = "";
$this->lore = [];

View File

@ -41,6 +41,7 @@ use pocketmine\entity\Villager;
use pocketmine\entity\Zombie;
use pocketmine\inventory\ArmorInventory;
use pocketmine\math\Vector3;
use pocketmine\nbt\NbtException;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\utils\SingletonTrait;
use pocketmine\world\World;
@ -444,6 +445,7 @@ class ItemFactory{
* Deserializes an item from the provided legacy ID, legacy meta, count and NBT.
*
* @throws \InvalidArgumentException
* @throws NbtException
*/
public function get(int $id, int $meta = 0, int $count = 1, ?CompoundTag $tags = null) : Item{
/** @var Item|null $item */