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


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

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