package common.block;

import common.entity.types.EntityLiving;
import common.init.ItemRegistry;
import common.item.Item;
import common.material.Material;
import common.model.Model;
import common.model.ModelProvider;
import common.properties.IProperty;
import common.properties.PropertyEnum;
import common.rng.Random;
import common.util.BlockPos;
import common.util.Facing;
import common.util.Identifyable;
import common.world.State;
import common.world.World;

public class BlockHugeMushroom extends Block
{
    public static final PropertyEnum<BlockHugeMushroom.EnumType> VARIANT = PropertyEnum.<BlockHugeMushroom.EnumType>create("variant", BlockHugeMushroom.EnumType.class);
    private final Block smallBlock;

    public BlockHugeMushroom(Material p_i46392_1_, Block p_i46392_3_)
    {
        super(p_i46392_1_);
        this.setDefaultState(this.getBaseState().withProperty(VARIANT, BlockHugeMushroom.EnumType.ALL_OUTSIDE));
        this.smallBlock = p_i46392_3_;
    }

    /**
     * Returns the quantity of items to drop on block destruction.
     */
    public int quantityDropped(Random random)
    {
        return Math.max(0, random.range(-7, 2));
    }

//    /**
//     * Get the MapColor for this Block and the given BlockState
//     */
//    public MapColor getMapColor(IBlockState state)
//    {
//        switch ((BlockHugeMushroom.EnumType)state.getValue(VARIANT))
//        {
//            case ALL_STEM:
//                return MapColor.clothColor;
//
//            case ALL_INSIDE:
//                return MapColor.sandColor;
//
//            case STEM:
//                return MapColor.sandColor;
//
//            default:
//                return super.getMapColor(state);
//        }
//    }

    /**
     * Get the Item that this Block should drop when harvested.
     */
    public Item getItemDropped(State state, Random rand, int fortune)
    {
        return ItemRegistry.getItemFromBlock(this.smallBlock);
    }

    public Item getItem(World worldIn, BlockPos pos)
    {
        return ItemRegistry.getItemFromBlock(this.smallBlock);
    }

    /**
     * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
     * IBlockstate
     */
    public State onBlockPlaced(World worldIn, BlockPos pos, Facing facing, float hitX, float hitY, float hitZ, int meta, EntityLiving placer)
    {
        return this.getState();
    }

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

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

    protected IProperty[] getProperties()
    {
        return new IProperty[] {VARIANT};
    }
    
    public Model getModel(ModelProvider provider, String name, State state) {
    	switch(state.getValue(VARIANT)) {
	    	case ALL_INSIDE:
	        	return provider.getModel(name + "_inside").add().all();
	    	case ALL_OUTSIDE:
	    	default:
	        	return provider.getModel(name + "_cap").add().all();
	    	case ALL_STEM:
	        	return provider.getModel(name + "_stem").add().all();
	    	case STEM:
	        	return provider.getModel(name + "_stem").add().nswe().du(name + "_inside");
	    	case CENTER: 
	    		return provider.getModel(name + "_inside").add().d(name + "_inside").u(name + "_cap").n(name + "_inside").s(name + "_inside")
	    				.w(name + "_inside").e(name + "_inside");
	    	case EAST: 
	    		return provider.getModel(name + "_inside").add().d(name + "_inside").u(name + "_cap").n(name + "_inside").s(name + "_inside")
	    				.w(name + "_inside").e(name + "_cap");
	    	case NORTH_EAST: 
	    		return provider.getModel(name + "_inside").add().d(name + "_inside").u(name + "_cap").n(name + "_cap").s(name + "_inside")
	    				.w(name + "_inside").e(name + "_cap");
	    	case NORTH: 
	    		return provider.getModel(name + "_inside").add().d(name + "_inside").u(name + "_cap").n(name + "_cap").s(name + "_inside")
	    				.w(name + "_inside").e(name + "_inside");
	    	case NORTH_WEST: 
	    		return provider.getModel(name + "_inside").add().d(name + "_inside").u(name + "_cap").n(name + "_cap").s(name + "_inside")
	    				.w(name + "_cap").e(name + "_inside");
	    	case SOUTH_EAST: 
	    		return provider.getModel(name + "_inside").add().d(name + "_inside").u(name + "_cap").n(name + "_inside").s(name + "_cap")
	    				.w(name + "_inside").e(name + "_cap");
	    	case SOUTH: 
	    		return provider.getModel(name + "_inside").add().d(name + "_inside").u(name + "_cap").n(name + "_inside").s(name + "_cap")
	    				.w(name + "_inside").e(name + "_inside");
	    	case SOUTH_WEST: 
	    		return provider.getModel(name + "_inside").add().d(name + "_inside").u(name + "_cap").n(name + "_inside").s(name + "_cap")
	    				.w(name + "_cap").e(name + "_inside");
	    	case WEST: 
	    		return provider.getModel(name + "_inside").add().d(name + "_inside").u(name + "_cap").n(name + "_inside").s(name + "_inside")
	    				.w(name + "_cap").e(name + "_inside");
    	}
    }

    public static enum EnumType implements Identifyable
    {
        NORTH_WEST(1, "north_west"),
        NORTH(2, "north"),
        NORTH_EAST(3, "north_east"),
        WEST(4, "west"),
        CENTER(5, "center"),
        EAST(6, "east"),
        SOUTH_WEST(7, "south_west"),
        SOUTH(8, "south"),
        SOUTH_EAST(9, "south_east"),
        STEM(10, "stem"),
        ALL_INSIDE(0, "all_inside"),
        ALL_OUTSIDE(14, "all_outside"),
        ALL_STEM(15, "all_stem");

        private static final BlockHugeMushroom.EnumType[] META_LOOKUP = new BlockHugeMushroom.EnumType[16];
        private final int meta;
        private final String name;

        private EnumType(int meta, String name)
        {
            this.meta = meta;
            this.name = name;
        }

        public int getMetadata()
        {
            return this.meta;
        }

        public String toString()
        {
            return this.name;
        }

        public static BlockHugeMushroom.EnumType byMetadata(int meta)
        {
            if (meta < 0 || meta >= META_LOOKUP.length)
            {
                meta = 0;
            }

            BlockHugeMushroom.EnumType blockhugemushroom$enumtype = META_LOOKUP[meta];
            return blockhugemushroom$enumtype == null ? META_LOOKUP[0] : blockhugemushroom$enumtype;
        }

        public String getName()
        {
            return this.name;
        }

        static {
            for (BlockHugeMushroom.EnumType blockhugemushroom$enumtype : values())
            {
                META_LOOKUP[blockhugemushroom$enumtype.getMetadata()] = blockhugemushroom$enumtype;
            }
        }
    }
}
