43 private array $enchantments = [];
46 private array $primaryItemTags = [];
49 private array $secondaryItemTags = [];
51 private function __construct(){
52 $this->
register(Enchantments::PROTECTION(), [Tags::ARMOR], []);
53 $this->
register(Enchantments::FIRE_PROTECTION(), [Tags::ARMOR], []);
54 $this->
register(Enchantments::FEATHER_FALLING(), [Tags::BOOTS], []);
55 $this->
register(Enchantments::BLAST_PROTECTION(), [Tags::ARMOR], []);
56 $this->
register(Enchantments::PROJECTILE_PROTECTION(), [Tags::ARMOR], []);
57 $this->
register(Enchantments::THORNS(), [Tags::CHESTPLATE], [Tags::HELMET, Tags::LEGGINGS, Tags::BOOTS]);
58 $this->
register(Enchantments::RESPIRATION(), [Tags::HELMET], []);
59 $this->
register(Enchantments::AQUA_AFFINITY(), [Tags::HELMET], []);
60 $this->
register(Enchantments::FROST_WALKER(), [], [Tags::BOOTS]);
61 $this->
register(Enchantments::SHARPNESS(), [Tags::SWORD, Tags::AXE], []);
62 $this->
register(Enchantments::KNOCKBACK(), [Tags::SWORD], []);
63 $this->
register(Enchantments::FIRE_ASPECT(), [Tags::SWORD], []);
64 $this->
register(Enchantments::EFFICIENCY(), [Tags::BLOCK_TOOLS], [Tags::SHEARS]);
65 $this->
register(Enchantments::FORTUNE(), [Tags::BLOCK_TOOLS], []);
66 $this->
register(Enchantments::SILK_TOUCH(), [Tags::BLOCK_TOOLS], [Tags::SHEARS]);
68 Enchantments::UNBREAKING(),
69 [Tags::ARMOR, Tags::WEAPONS, Tags::FISHING_ROD],
70 [Tags::SHEARS, Tags::FLINT_AND_STEEL, Tags::SHIELD, Tags::CARROT_ON_STICK, Tags::ELYTRA, Tags::BRUSH]
72 $this->
register(Enchantments::POWER(), [Tags::BOW], []);
73 $this->
register(Enchantments::PUNCH(), [Tags::BOW], []);
74 $this->
register(Enchantments::FLAME(), [Tags::BOW], []);
75 $this->
register(Enchantments::INFINITY(), [Tags::BOW], []);
77 Enchantments::MENDING(),
79 [Tags::ARMOR, Tags::WEAPONS, Tags::FISHING_ROD,
80 Tags::SHEARS, Tags::FLINT_AND_STEEL, Tags::SHIELD, Tags::CARROT_ON_STICK, Tags::ELYTRA, Tags::BRUSH]
82 $this->
register(Enchantments::VANISHING(), [], [Tags::ALL]);
83 $this->
register(Enchantments::SWIFT_SNEAK(), [], [Tags::LEGGINGS]);
90 public function register(
Enchantment $enchantment, array $primaryItemTags, array $secondaryItemTags) : void{
91 $this->enchantments[spl_object_id($enchantment)] = $enchantment;
96 public function unregister(
Enchantment $enchantment) : void{
97 unset($this->enchantments[spl_object_id($enchantment)]);
98 unset($this->primaryItemTags[spl_object_id($enchantment)]);
99 unset($this->secondaryItemTags[spl_object_id($enchantment)]);
102 public function unregisterAll() : void{
103 $this->enchantments = [];
104 $this->primaryItemTags = [];
105 $this->secondaryItemTags = [];
108 public function isRegistered(Enchantment $enchantment) : bool{
109 return isset($this->enchantments[spl_object_id($enchantment)]);
122 return $this->primaryItemTags[spl_object_id($enchantment)] ?? [];
129 if(!$this->isRegistered($enchantment)){
130 throw new \LogicException(
"Cannot set primary item tags for non-registered enchantment");
132 $this->primaryItemTags[spl_object_id($enchantment)] = array_values($tags);
145 return $this->secondaryItemTags[spl_object_id($enchantment)] ?? [];
152 if(!$this->isRegistered($enchantment)){
153 throw new \LogicException(
"Cannot set secondary item tags for non-registered enchantment");
155 $this->secondaryItemTags[spl_object_id($enchantment)] = array_values($tags);
164 $itemTags = $item->getEnchantmentTags();
165 if(count($itemTags) === 0 || $item->hasEnchantments()){
171 fn(
Enchantment $e) => TagRegistry::getInstance()->isTagArrayIntersection($this->getPrimaryItemTags($e), $itemTags)
184 if(count($item->getEnchantmentTags()) === 0){
190 fn(
Enchantment $enchantment) => $this->isAvailableForItem($enchantment, $item)
200 $itemTags = $item->getEnchantmentTags();
201 $tagRegistry = TagRegistry::getInstance();
203 return $tagRegistry->isTagArrayIntersection($this->getPrimaryItemTags($enchantment), $itemTags) ||
204 $tagRegistry->isTagArrayIntersection($this->getSecondaryItemTags($enchantment), $itemTags);
211 return $this->enchantments;