getId()] = clone $enchantment; } public static function get(int $id) : ?Enchantment{ return self::$enchantments[$id] ?? null; } public static function fromString(string $name) : ?Enchantment{ $const = Enchantment::class . "::" . strtoupper($name); if(defined($const)){ return self::get(constant($const)); } return null; } /** @var int */ private $id; /** @var string */ private $name; /** @var int */ private $rarity; /** @var int */ private $primaryItemFlags; /** @var int */ private $secondaryItemFlags; /** @var int */ private $maxLevel; public function __construct(int $id, string $name, int $rarity, int $primaryItemFlags, int $secondaryItemFlags, int $maxLevel){ $this->id = $id; $this->name = $name; $this->rarity = $rarity; $this->primaryItemFlags = $primaryItemFlags; $this->secondaryItemFlags = $secondaryItemFlags; $this->maxLevel = $maxLevel; } /** * Returns the ID of this enchantment as per Minecraft PE */ public function getId() : int{ return $this->id; } /** * Returns a translation key for this enchantment's name. */ public function getName() : string{ return $this->name; } /** * Returns an int constant indicating how rare this enchantment type is. */ public function getRarity() : int{ return $this->rarity; } /** * Returns a bitset indicating what item types can have this item applied from an enchanting table. */ public function getPrimaryItemFlags() : int{ return $this->primaryItemFlags; } /** * Returns a bitset indicating what item types cannot have this item applied from an enchanting table, but can from * an anvil. */ public function getSecondaryItemFlags() : int{ return $this->secondaryItemFlags; } /** * Returns whether this enchantment can apply to the item type from an enchanting table. */ public function hasPrimaryItemType(int $flag) : bool{ return ($this->primaryItemFlags & $flag) !== 0; } /** * Returns whether this enchantment can apply to the item type from an anvil, if it is not a primary item. */ public function hasSecondaryItemType(int $flag) : bool{ return ($this->secondaryItemFlags & $flag) !== 0; } /** * Returns the maximum level of this enchantment that can be found on an enchantment table. */ 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) }