mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-30 23:29:54 +00:00
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:
parent
2db79cf58d
commit
dbeaf27cb7
@ -37,6 +37,7 @@ use pocketmine\math\Vector3;
|
|||||||
use pocketmine\nbt\LittleEndianNbtSerializer;
|
use pocketmine\nbt\LittleEndianNbtSerializer;
|
||||||
use pocketmine\nbt\NBT;
|
use pocketmine\nbt\NBT;
|
||||||
use pocketmine\nbt\NbtDataException;
|
use pocketmine\nbt\NbtDataException;
|
||||||
|
use pocketmine\nbt\NbtException;
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\nbt\tag\ListTag;
|
use pocketmine\nbt\tag\ListTag;
|
||||||
use pocketmine\nbt\tag\ShortTag;
|
use pocketmine\nbt\tag\ShortTag;
|
||||||
@ -240,6 +241,7 @@ class Item implements \JsonSerializable{
|
|||||||
* Sets the Item's NBT from the supplied CompoundTag object.
|
* Sets the Item's NBT from the supplied CompoundTag object.
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
|
* @throws NbtException
|
||||||
*/
|
*/
|
||||||
public function setNamedTag(CompoundTag $tag) : Item{
|
public function setNamedTag(CompoundTag $tag) : Item{
|
||||||
if($tag->getCount() === 0){
|
if($tag->getCount() === 0){
|
||||||
@ -255,6 +257,7 @@ class Item implements \JsonSerializable{
|
|||||||
/**
|
/**
|
||||||
* Removes the Item's NBT.
|
* Removes the Item's NBT.
|
||||||
* @return $this
|
* @return $this
|
||||||
|
* @throws NbtException
|
||||||
*/
|
*/
|
||||||
public function clearNamedTag() : Item{
|
public function clearNamedTag() : Item{
|
||||||
$this->nbt = new CompoundTag();
|
$this->nbt = new CompoundTag();
|
||||||
@ -262,6 +265,9 @@ class Item implements \JsonSerializable{
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws NbtException
|
||||||
|
*/
|
||||||
protected function deserializeCompoundTag(CompoundTag $tag) : void{
|
protected function deserializeCompoundTag(CompoundTag $tag) : void{
|
||||||
$this->customName = "";
|
$this->customName = "";
|
||||||
$this->lore = [];
|
$this->lore = [];
|
||||||
|
@ -41,6 +41,7 @@ use pocketmine\entity\Villager;
|
|||||||
use pocketmine\entity\Zombie;
|
use pocketmine\entity\Zombie;
|
||||||
use pocketmine\inventory\ArmorInventory;
|
use pocketmine\inventory\ArmorInventory;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
|
use pocketmine\nbt\NbtException;
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\utils\SingletonTrait;
|
use pocketmine\utils\SingletonTrait;
|
||||||
use pocketmine\world\World;
|
use pocketmine\world\World;
|
||||||
@ -444,6 +445,7 @@ class ItemFactory{
|
|||||||
* Deserializes an item from the provided legacy ID, legacy meta, count and NBT.
|
* Deserializes an item from the provided legacy ID, legacy meta, count and NBT.
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
|
* @throws NbtException
|
||||||
*/
|
*/
|
||||||
public function get(int $id, int $meta = 0, int $count = 1, ?CompoundTag $tags = null) : Item{
|
public function get(int $id, int $meta = 0, int $count = 1, ?CompoundTag $tags = null) : Item{
|
||||||
/** @var Item|null $item */
|
/** @var Item|null $item */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user