package com.mingliqiye.minecraft.enchantment.conflict.mixin;


import com.mingliqiye.minecraft.enchantment.conflict.config.ModConfig;
import net.minecraft.enchantment.ProtectionEnchantment;
import net.minecraft.enchantment.Enchantment;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ProtectionEnchantment.class)
public abstract class ProtectionEnchantmentMixin {

    @Inject(method = "canAccept", at = @At("HEAD"), cancellable = true)

    private void onCheckCompatibility(
            @NotNull Enchantment enchantment,
            @NotNull CallbackInfoReturnable<Boolean> cir
    ) {
        if (enchantment instanceof ProtectionEnchantment) {
            cir.setReturnValue(ModConfig.getInstance().isAllowProtectionEnchantment());
        }
    }
}
