mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-13 13:25:16 +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{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($ench->getCount() > 0){
|
||||||
$this->setNamedTagEntry($ench);
|
$this->setNamedTagEntry($ench);
|
||||||
|
}else{
|
||||||
|
$this->removeNamedTagEntry(self::TAG_ENCH);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeEnchantments() : void{
|
public function removeEnchantments() : void{
|
||||||
|
@ -1605,6 +1605,11 @@ parameters:
|
|||||||
count: 1
|
count: 1
|
||||||
path: ../../../src/pocketmine/utils/Utils.php
|
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\\.$#"
|
message: "#^Cannot call method cancel\\(\\) on pocketmine\\\\scheduler\\\\TaskHandler\\|null\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
|
@ -25,12 +25,15 @@ namespace pocketmine\item;
|
|||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use pocketmine\block\BlockFactory;
|
use pocketmine\block\BlockFactory;
|
||||||
|
use pocketmine\item\enchantment\Enchantment;
|
||||||
|
use pocketmine\item\enchantment\EnchantmentInstance;
|
||||||
|
|
||||||
class ItemTest extends TestCase{
|
class ItemTest extends TestCase{
|
||||||
|
|
||||||
public function setUp() : void{
|
public function setUp() : void{
|
||||||
BlockFactory::init();
|
BlockFactory::init();
|
||||||
ItemFactory::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[][]
|
* @return mixed[][]
|
||||||
* @phpstan-return list<array{string,int,int}>
|
* @phpstan-return list<array{string,int,int}>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user