package com.zivilon.cinder_loe.blocks;

import com.zivilon.cinder_loe.util.Utilities;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import lotr.common.LOTRCreativeTabs;
import lotr.common.block.LOTRBlockBrickBase;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;

import java.lang.reflect.Field;
import java.util.List;

public class CobbleBlock extends Block {
    protected IIcon[] brickIcons;
    protected String[] brickNames;


    public CobbleBlock() {
        super(Material.rock);
        this.setHardness(1.5f);
        this.setResistance(10.0f);
        this.setStepSound(Block.soundTypeStone);

        try {
            Field tabField = LOTRCreativeTabs.class.getDeclaredField("tabBlock"); // Stupid workaround because ForgeGradle tries to obfuscate field LOTRCreativeTabs.tabBlock when it's not supposed to
            LOTRCreativeTabs tab = (LOTRCreativeTabs)tabField.get(null);
            setCreativeTab((CreativeTabs)tab);
        } catch (NoSuchFieldException | IllegalAccessException e) {
            e.printStackTrace();
        }

        setBlockTextureName("lotr:cindercobble");
        setBlockName("lotr:cindercobble");
        this.setBrickNames("drystone", "mordor");
    }

    protected void setBrickNames(String ... names) {
        this.brickNames = names;
    }

    @SideOnly(Side.CLIENT)
    @Override
    public void registerBlockIcons(IIconRegister iconregister) {
        this.brickIcons = new IIcon[this.brickNames.length];
        for (int i = 0; i < this.brickNames.length; ++i) {
            String texturePath = this.getTextureName() + "_" + this.brickNames[i];
            System.out.println("Registering texture: " + texturePath); // Debug log
            this.brickIcons[i] = iconregister.registerIcon(texturePath);
        }
    }
    @Override
    public IIcon getIcon(int side, int meta) {
        return this.brickIcons[meta];
    }

    @Override
    public int damageDropped(int meta) {
        return meta;
    }
    @SideOnly(Side.CLIENT)
    @Override
    public void getSubBlocks(Item item, CreativeTabs tab, List list) {
        for (int i = 0; i < this.brickNames.length; ++i) {
            list.add(new ItemStack(item, 1, i));
        }
    }
}
