mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-03 16:49:53 +00:00
Item: Added API method getEnchantmentLevel()
This commit is contained in:
parent
c4966404bb
commit
b04cee12ea
@ -412,6 +412,28 @@ class Item implements ItemIds, \JsonSerializable{
|
|||||||
return $enchantments;
|
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
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user