22declare(strict_types=1);
29use
function spl_object_id;
40 protected array $enchantments = [];
42 public function hasEnchantments() :
bool{
43 return count($this->enchantments) > 0;
46 public function hasEnchantment(
Enchantment $enchantment,
int $level = -1) :
bool{
47 $id = spl_object_id($enchantment);
48 return isset($this->enchantments[$id]) && ($level === -1 || $this->enchantments[$id]->getLevel() === $level);
52 return $this->enchantments[spl_object_id($enchantment)] ??
null;
59 $instance = $this->getEnchantment($enchantment);
60 if($instance !==
null && ($level === -1 || $instance->getLevel() === $level)){
61 unset($this->enchantments[spl_object_id($enchantment)]);
71 $this->enchantments = [];
79 $this->enchantments[spl_object_id($enchantment->getType())] = $enchantment;
88 return $this->enchantments;
96 return ($instance = $this->getEnchantment($enchantment)) !== null ? $instance->getLevel() : 0;
getEnchantmentLevel(Enchantment $enchantment)
removeEnchantment(Enchantment $enchantment, int $level=-1)
addEnchantment(EnchantmentInstance $enchantment)
trait ItemEnchantmentHandlingTrait