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


import com.mingliqiye.minecraft.enchantment.conflict.config.ModConfig;
import net.minecraft.enchantment.DamageEnchantment;
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(DamageEnchantment.class)
public abstract class DamageEnchantmentMixin {

    @Inject(method = "canAccept", at = @At("HEAD"), cancellable = true)
    private void canAccept(
            @NotNull Enchantment enchantment,
            @NotNull CallbackInfoReturnable<Boolean> cir
    ) {
        if (enchantment instanceof DamageEnchantment) {
            cir.setReturnValue(ModConfig.getInstance().isAllowDamageEnchantment());
        }
    }

}
