22declare(strict_types=1);
29use
function spl_object_id;
37 protected array $enchantments = [];
39 public function hasEnchantments() :
bool{
40 return count($this->enchantments) > 0;
43 public function hasEnchantment(
Enchantment $enchantment,
int $level = -1) :
bool{
44 $id = spl_object_id($enchantment);
45 return isset($this->enchantments[$id]) && ($level === -1 || $this->enchantments[$id]->getLevel() === $level);
49 return $this->enchantments[spl_object_id($enchantment)] ??
null;
56 $instance = $this->getEnchantment($enchantment);
57 if($instance !==
null && ($level === -1 || $instance->getLevel() === $level)){
58 unset($this->enchantments[spl_object_id($enchantment)]);
68 $this->enchantments = [];
76 $this->enchantments[spl_object_id($enchantment->getType())] = $enchantment;
84 return $this->enchantments;
92 return ($instance = $this->getEnchantment($enchantment)) !== null ? $instance->getLevel() : 0;
getEnchantmentLevel(Enchantment $enchantment)
removeEnchantment(Enchantment $enchantment, int $level=-1)
addEnchantment(EnchantmentInstance $enchantment)
trait ItemEnchantmentHandlingTrait