package com.zivilon.cinder_loe.mixins;

import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.init.Items;

import net.minecraftforge.oredict.OreDictionary;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Overwrite;

import lotr.common.tileentity.LOTRTileEntityDwarvenForge;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Field;

import com.zivilon.cinder_loe.CinderLoE;
import lotr.common.LOTRMod;
import org.spongepowered.asm.mixin.Unique;

@Mixin(LOTRTileEntityDwarvenForge.class)
public abstract class MixinLOTRTileEntityDwarvenForge {
    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 isIron(ItemStack itemstack) {
        return (LOTRMod.isOreNameEqual(itemstack, "oreIron") || LOTRMod.isOreNameEqual(itemstack, "ingotIron"));
    }

    protected boolean isCoal(ItemStack itemstack) {
        return (itemstack.getItem() == Items.coal);
    }

    protected boolean isMithril(ItemStack itemstack) {
        return itemstack.getItem() == Item.getItemFromBlock(LOTRMod.oreMithril) || itemstack.getItem() == LOTRMod.mithril;
    }

    protected boolean isCoalBlock(ItemStack itemstack) {
        return itemstack.getItem() == Item.getItemFromBlock(Blocks.coal_block);
    }

    protected boolean isGoldNugget(ItemStack itemstack) {
        return (itemstack.getItem() == Items.gold_nugget);
    }

    /**
    * @author Shinare
    * @reason Added recipe for CinderLoE.ingotAsh and CinderLoE.redDwarfSteel
    */
    @Overwrite(remap = false)
    protected ItemStack getAlloySmeltingResult(ItemStack itemstack, ItemStack alloyItem) {
        if (isIron(itemstack) && isCoal(alloyItem))
            return new ItemStack(LOTRMod.dwarfSteel);
        if (isIron(itemstack) && alloyItem.getItem() == LOTRMod.quenditeCrystal)
            return new ItemStack(LOTRMod.galvorn);
        if (isIron(itemstack) && alloyItem.getItem() == Item.getItemFromBlock(LOTRMod.rock) && alloyItem.getItemDamage() == 3)
            return new ItemStack(LOTRMod.blueDwarfSteel);
        if (isCopper(itemstack) && alloyItem.getItem() == Item.getItemById(371))
            return new ItemStack(CinderLoE.redDwarfSteel);
        if ((isCopper(itemstack) && isTin(alloyItem)) || (isTin(itemstack) && isCopper(alloyItem)))
            return new ItemStack(LOTRMod.bronze, 2);
        if (this.isMithril(itemstack) && this.isCoalBlock(alloyItem))
            return new ItemStack(CinderLoE.ingotAsh, 1);
        return null;
    }
}
