22declare(strict_types=1);
24namespace pocketmine\item\enchantment;
28use pocketmine\utils\SingletonTrait;
29use
function array_intersect_key;
31use
function spl_object_id;
44 private array $incompatibilityMap = [];
46 private function __construct(){
47 $this->
register(Groups::PROTECTION, [Enchantments::PROTECTION(), Enchantments::FIRE_PROTECTION(), Enchantments::BLAST_PROTECTION(), Enchantments::PROJECTILE_PROTECTION()]);
48 $this->
register(Groups::BOW_INFINITE, [Enchantments::INFINITY(), Enchantments::MENDING()]);
49 $this->
register(Groups::BLOCK_DROPS, [Enchantments::FORTUNE(), Enchantments::SILK_TOUCH()]);
60 public function register(
string $tag, array $enchantments) :
void{
61 foreach($enchantments as $enchantment){
62 $this->incompatibilityMap[spl_object_id($enchantment)][$tag] =
true;
71 public function unregister(
string $tag, array $enchantments) : void{
72 foreach($enchantments as $enchantment){
73 unset($this->incompatibilityMap[spl_object_id($enchantment)][$tag]);
81 foreach($this->incompatibilityMap as $id => $tags){
82 unset($this->incompatibilityMap[$id][$tag]);
90 $firstIncompatibilities = $this->incompatibilityMap[spl_object_id($first)] ?? [];
91 $secondIncompatibilities = $this->incompatibilityMap[spl_object_id($second)] ?? [];
92 return count(array_intersect_key($firstIncompatibilities, $secondIncompatibilities)) === 0;
areCompatible(Enchantment $first, Enchantment $second)
unregister(string $tag, array $enchantments)
unregisterAll(string $tag)