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

import com.mojang.logging.LogUtils;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.registry.entry.RegistryEntry;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(Enchantment.class)
public abstract class EnchantmentMixin {
    @Unique
    private static final Logger LOGGER = LogUtils.getLogger();


    @Inject(method = "canBeCombined", at = @At("HEAD"), cancellable = true)
    private static void canBeCombined(
            RegistryEntry<Enchantment> first, RegistryEntry<Enchantment> second,
            CallbackInfoReturnable<Boolean> cir
    ) {
        com.mingliqiye.minecraft.enchantment.conflict.enchantment.Enchantment firste =
                com.mingliqiye.minecraft.enchantment.conflict.enchantment.Enchantment.ofId(first.getIdAsString());
        com.mingliqiye.minecraft.enchantment.conflict.enchantment.Enchantment seconde =
                com.mingliqiye.minecraft.enchantment.conflict.enchantment.Enchantment.ofId(second.getIdAsString());
        if (firste == null || seconde == null) {
            return;
        }
        cir.setReturnValue(firste.canBeCombined(seconde));
    }
}
