mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 16:59:44 +00:00
Item: make addEnchantment(), removeEnchantment() and removeEnchantments() fluent (#2523)
This commit is contained in:
parent
45caec874e
commit
3c86944a7c
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user