getId()] = clone $enchantment; } /** * @param int $id * * @return Enchantment|null */ public static function getEnchantment(int $id){ return self::$enchantments[$id] ?? null; } /** * @param string $name * * @return Enchantment|null */ public static function getEnchantmentByName(string $name){ $const = Enchantment::class . "::" . strtoupper($name); if(defined($const)){ return self::getEnchantment(constant($const)); } return null; } /** @var int */ private $id; /** @var string */ private $name; /** @var int */ private $rarity; /** @var int */ private $slot; /** @var int */ private $maxLevel; /** * @param int $id * @param string $name * @param int $rarity * @param int $slot * @param int $maxLevel */ public function __construct(int $id, string $name, int $rarity, int $slot, int $maxLevel){ $this->id = $id; $this->name = $name; $this->rarity = $rarity; $this->slot = $slot; $this->maxLevel = $maxLevel; } /** * Returns the ID of this enchantment as per Minecraft PE * @return int */ public function getId() : int{ return $this->id; } /** * Returns a translation key for this enchantment's name. * @return string */ public function getName() : string{ return $this->name; } /** * Returns an int constant indicating how rare this enchantment type is. * @return int */ public function getRarity() : int{ return $this->rarity; } /** * Returns an int with bitflags set to indicate what item types this enchantment can apply to. * @return int */ public function getSlot() : int{ return $this->slot; } /** * Returns whether this enchantment can apply to the specified item type. * @param int $slot * * @return bool */ public function hasSlot(int $slot) : bool{ return ($this->slot & $slot) > 0; } /** * Returns the maximum level of this enchantment that can be found on an enchantment table. * @return int */ public function getMaxLevel() : int{ return $this->maxLevel; } //TODO: methods for min/max XP cost bounds based on enchantment level (not needed yet - enchanting is client-side) }