package common.block;

import java.util.List;

import common.color.DyeColor;
import common.item.CheatTab;
import common.item.Item;
import common.item.ItemStack;
import common.material.Material;
import common.model.Model;
import common.model.ModelProvider;
import common.properties.IProperty;
import common.properties.PropertyEnum;
import common.world.State;

public class BlockColored extends Block
{
    public static final PropertyEnum<DyeColor> COLOR = PropertyEnum.<DyeColor>create("color", DyeColor.class);

    public BlockColored(Material materialIn)
    {
        super(materialIn);
        this.setDefaultState(this.getBaseState().withProperty(COLOR, DyeColor.WHITE));
        this.setTab(CheatTab.tabBlocks);
    }

    /**
     * Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
     * returns the metadata of the dropped item based on the old metadata of the block.
     */
    public int damageDropped(State state)
    {
        return ((DyeColor)state.getValue(COLOR)).getMetadata();
    }

    /**
     * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
     */
    public void getSubBlocks(Item itemIn, CheatTab tab, List<ItemStack> list)
    {
        for (DyeColor enumdyecolor : DyeColor.values())
        {
            list.add(new ItemStack(itemIn, 1, enumdyecolor.getMetadata()));
        }
    }

//    /**
//     * Get the MapColor for this Block and the given BlockState
//     */
//    public MapColor getMapColor(IBlockState state)
//    {
//        return ((EnumDyeColor)state.getValue(COLOR)).getMapColor();
//    }

    /**
     * Convert the given metadata into a BlockState for this Block
     */
    public State getStateFromMeta(int meta)
    {
        return this.getState().withProperty(COLOR, DyeColor.byMetadata(meta));
    }

    /**
     * Convert the BlockState into the correct metadata value
     */
    public int getMetaFromState(State state)
    {
        return ((DyeColor)state.getValue(COLOR)).getMetadata();
    }

    protected IProperty[] getProperties()
    {
        return new IProperty[] {COLOR};
    }

    public Model getModel(ModelProvider provider, String name, State state) {
    	return provider.getModel(state.getValue(COLOR).getName() + "_" + name).add().all();
    }
}
