package com.zivilon.cinder_loe.mixins;

import com.zivilon.cinder_loe.CinderLoE;
import lotr.common.LOTRMod;
import lotr.common.tileentity.LOTRTileEntityAlloyForgeBase;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Unique;

@Mixin(LOTRTileEntityAlloyForgeBase.class)
public abstract class MixinLOTRTileEntityForgeBase {
    @Unique
    protected boolean cinderLoE_Git$isMithril(ItemStack itemstack) {
        return itemstack.getItem() == Item.getItemFromBlock(LOTRMod.oreMithril) || itemstack.getItem() == LOTRMod.mithril;
    }

    @Unique
    protected boolean cinderLoE_Git$isCoalBlock(ItemStack itemstack) {
        return itemstack.getItem() == Item.getItemFromBlock(Blocks.coal_block);
    }
    protected boolean isCopper(ItemStack itemstack) {
        return (LOTRMod.isOreNameEqual(itemstack, "oreCopper") || LOTRMod.isOreNameEqual(itemstack, "ingotCopper"));
    }
    protected boolean isTin(ItemStack itemstack) {
        return (LOTRMod.isOreNameEqual(itemstack, "oreTin") || LOTRMod.isOreNameEqual(itemstack, "ingotTin"));
    }
    protected boolean isGoldNugget(ItemStack itemstack) {
        return (itemstack.getItem() == Items.gold_nugget);
    }

    /**
     * @author Keylime
     * @reason IDE demands it
     */
    @Overwrite(remap = false)
    protected ItemStack getAlloySmeltingResult(ItemStack itemstack, ItemStack alloyItem) {
        if (this.cinderLoE_Git$isMithril(itemstack) && this.cinderLoE_Git$isCoalBlock(alloyItem))
            return new ItemStack(CinderLoE.ingotAsh, 1);
        if ((isCopper(itemstack) && isTin(alloyItem)) || (isTin(itemstack) && isCopper(alloyItem)))
            return new ItemStack(LOTRMod.bronze, 2);
        return null;
    }
}



