mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Item: Remove "ench" tag when all enchantments are removed from an item (#4184)
fixes #4144
This commit is contained in:
parent
6f80b8979d
commit
8d1a1628de
@ -339,7 +339,11 @@ class Item implements ItemIds, \JsonSerializable{
|
||||
}
|
||||
}
|
||||
|
||||
$this->setNamedTagEntry($ench);
|
||||
if($ench->getCount() > 0){
|
||||
$this->setNamedTagEntry($ench);
|
||||
}else{
|
||||
$this->removeNamedTagEntry(self::TAG_ENCH);
|
||||
}
|
||||
}
|
||||
|
||||
public function removeEnchantments() : void{
|
||||
|
@ -1605,6 +1605,11 @@ parameters:
|
||||
count: 1
|
||||
path: ../../../src/pocketmine/utils/Utils.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$enchantment of class pocketmine\\\\item\\\\enchantment\\\\EnchantmentInstance constructor expects pocketmine\\\\item\\\\enchantment\\\\Enchantment, pocketmine\\\\item\\\\enchantment\\\\Enchantment\\|null given\\.$#"
|
||||
count: 1
|
||||
path: ../../phpunit/item/ItemTest.php
|
||||
|
||||
-
|
||||
message: "#^Cannot call method cancel\\(\\) on pocketmine\\\\scheduler\\\\TaskHandler\\|null\\.$#"
|
||||
count: 1
|
||||
|
@ -25,12 +25,15 @@ namespace pocketmine\item;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\item\enchantment\Enchantment;
|
||||
use pocketmine\item\enchantment\EnchantmentInstance;
|
||||
|
||||
class ItemTest extends TestCase{
|
||||
|
||||
public function setUp() : void{
|
||||
BlockFactory::init();
|
||||
ItemFactory::init();
|
||||
Enchantment::init();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,6 +64,16 @@ class ItemTest extends TestCase{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that when all enchantments are removed from an item, the "ench" tag is removed as well
|
||||
*/
|
||||
public function testEnchantmentRemoval() : void{
|
||||
$item = ItemFactory::get(Item::DIAMOND_SWORD);
|
||||
$item->addEnchantment(new EnchantmentInstance(Enchantment::getEnchantment(Enchantment::SHARPNESS)));
|
||||
$item->removeEnchantment(Enchantment::SHARPNESS);
|
||||
self::assertNull($item->getNamedTag()->getTag(Item::TAG_ENCH));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed[][]
|
||||
* @phpstan-return list<array{string,int,int}>
|
||||
|
Loading…
x
Reference in New Issue
Block a user