Item: Added API method getEnchantmentLevel()

This commit is contained in:
Dylan K. Taylor 2018-01-11 18:22:29 +00:00
parent c4966404bb
commit b04cee12ea

View File

@ -412,6 +412,28 @@ class Item implements ItemIds, \JsonSerializable{
return $enchantments;
}
/**
* Returns the level of the enchantment on this item with the specified ID, or 0 if the item does not have the
* enchantment.
*
* @param int $enchantmentId
*
* @return int
*/
public function getEnchantmentLevel(int $enchantmentId) : int{
$ench = $this->getNamedTag()->getListTag(self::TAG_ENCH);
if($ench !== null){
/** @var CompoundTag $entry */
foreach($ench as $entry){
if($entry->getShort("id") === $enchantmentId){
return $entry->getShort("lvl");
}
}
}
return 0;
}
/**
* @return bool
*/