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::SHARPNESS(), [Tags::SWORD, Tags::AXE], []);
61 $this->
register(Enchantments::KNOCKBACK(), [Tags::SWORD], []);
62 $this->
register(Enchantments::FIRE_ASPECT(), [Tags::SWORD], []);
63 $this->
register(Enchantments::EFFICIENCY(), [Tags::BLOCK_TOOLS], [Tags::SHEARS]);
64 $this->
register(Enchantments::FORTUNE(), [Tags::BLOCK_TOOLS], []);
65 $this->
register(Enchantments::SILK_TOUCH(), [Tags::BLOCK_TOOLS], [Tags::SHEARS]);
67 Enchantments::UNBREAKING(),
68 [Tags::ARMOR, Tags::WEAPONS, Tags::FISHING_ROD],
69 [Tags::SHEARS, Tags::FLINT_AND_STEEL, Tags::SHIELD, Tags::CARROT_ON_STICK, Tags::ELYTRA, Tags::BRUSH]
71 $this->
register(Enchantments::POWER(), [Tags::BOW], []);
72 $this->
register(Enchantments::PUNCH(), [Tags::BOW], []);
73 $this->
register(Enchantments::FLAME(), [Tags::BOW], []);
74 $this->
register(Enchantments::INFINITY(), [Tags::BOW], []);
76 Enchantments::MENDING(),
78 [Tags::ARMOR, Tags::WEAPONS, Tags::FISHING_ROD,
79 Tags::SHEARS, Tags::FLINT_AND_STEEL, Tags::SHIELD, Tags::CARROT_ON_STICK, Tags::ELYTRA, Tags::BRUSH]
81 $this->
register(Enchantments::VANISHING(), [], [Tags::ALL]);
82 $this->
register(Enchantments::SWIFT_SNEAK(), [], [Tags::LEGGINGS]);
89 public function register(
Enchantment $enchantment, array $primaryItemTags, array $secondaryItemTags) : void{
90 $this->enchantments[spl_object_id($enchantment)] = $enchantment;
95 public function unregister(
Enchantment $enchantment) : void{
96 unset($this->enchantments[spl_object_id($enchantment)]);
97 unset($this->primaryItemTags[spl_object_id($enchantment)]);
98 unset($this->secondaryItemTags[spl_object_id($enchantment)]);
101 public function unregisterAll() : void{
102 $this->enchantments = [];
103 $this->primaryItemTags = [];
104 $this->secondaryItemTags = [];
107 public function isRegistered(Enchantment $enchantment) : bool{
108 return isset($this->enchantments[spl_object_id($enchantment)]);
121 return $this->primaryItemTags[spl_object_id($enchantment)] ?? [];
128 if(!$this->isRegistered($enchantment)){
129 throw new \LogicException(
"Cannot set primary item tags for non-registered enchantment");
131 $this->primaryItemTags[spl_object_id($enchantment)] = array_values($tags);
144 return $this->secondaryItemTags[spl_object_id($enchantment)] ?? [];
151 if(!$this->isRegistered($enchantment)){
152 throw new \LogicException(
"Cannot set secondary item tags for non-registered enchantment");
154 $this->secondaryItemTags[spl_object_id($enchantment)] = array_values($tags);
163 $itemTags = $item->getEnchantmentTags();
164 if(count($itemTags) === 0 || $item->hasEnchantments()){
170 fn(
Enchantment $e) => TagRegistry::getInstance()->isTagArrayIntersection($this->getPrimaryItemTags($e), $itemTags)
183 if(count($item->getEnchantmentTags()) === 0){
189 fn(
Enchantment $enchantment) => $this->isAvailableForItem($enchantment, $item)
199 $itemTags = $item->getEnchantmentTags();
200 $tagRegistry = TagRegistry::getInstance();
202 return $tagRegistry->isTagArrayIntersection($this->getPrimaryItemTags($enchantment), $itemTags) ||
203 $tagRegistry->isTagArrayIntersection($this->getSecondaryItemTags($enchantment), $itemTags);
210 return $this->enchantments;