Item: make addEnchantment(), removeEnchantment() and removeEnchantments() fluent (#2523)

This commit is contained in:
Twisted 2018-11-13 16:48:13 +00:00 committed by Dylan T
parent 45caec874e
commit 3c86944a7c

View File

@ -286,11 +286,13 @@ class Item implements ItemIds, \JsonSerializable{
/** /**
* @param int $id * @param int $id
* @param int $level * @param int $level
*
* @return Item
*/ */
public function removeEnchantment(int $id, int $level = -1) : void{ public function removeEnchantment(int $id, int $level = -1) : Item{
$ench = $this->getNamedTagEntry(self::TAG_ENCH); $ench = $this->getNamedTagEntry(self::TAG_ENCH);
if(!($ench instanceof ListTag)){ if(!($ench instanceof ListTag)){
return; return $this;
} }
/** @var CompoundTag $entry */ /** @var CompoundTag $entry */
@ -302,16 +304,25 @@ class Item implements ItemIds, \JsonSerializable{
} }
$this->setNamedTagEntry($ench); $this->setNamedTagEntry($ench);
return $this;
} }
public function removeEnchantments() : void{ /**
* @return Item
*/
public function removeEnchantments() : Item{
$this->removeNamedTagEntry(self::TAG_ENCH); $this->removeNamedTagEntry(self::TAG_ENCH);
return $this;
} }
/** /**
* @param EnchantmentInstance $enchantment * @param EnchantmentInstance $enchantment
*
* @return Item
*/ */
public function addEnchantment(EnchantmentInstance $enchantment) : void{ public function addEnchantment(EnchantmentInstance $enchantment) : Item{
$found = false; $found = false;
$ench = $this->getNamedTagEntry(self::TAG_ENCH); $ench = $this->getNamedTagEntry(self::TAG_ENCH);
@ -339,6 +350,8 @@ class Item implements ItemIds, \JsonSerializable{
} }
$this->setNamedTagEntry($ench); $this->setNamedTagEntry($ench);
return $this;
} }
/** /**