package common.block.artificial;

import common.block.BlockRotatedPillar;
import common.block.Material;
import common.entity.types.EntityLiving;
import common.item.CheatTab;
import common.item.ItemStack;
import common.properties.Property;
import common.util.BlockPos;
import common.util.Facing;
import common.world.State;
import common.world.World;

public class BlockHay extends BlockRotatedPillar
{
    public BlockHay()
    {
        super(Material.LOOSE);
        this.setDefaultState(this.getBaseState().withProperty(AXIS, Facing.Axis.Y));
        this.setTab(CheatTab.BLOCKS);
        this.setFlammable(60, 20);
    }

    /**
     * Convert the given metadata into a BlockState for this Block
     */
    public State getStateFromMeta(int meta)
    {
        Facing.Axis enumfacing$axis = Facing.Axis.Y;
        int i = meta & 12;

        if (i == 4)
        {
            enumfacing$axis = Facing.Axis.X;
        }
        else if (i == 8)
        {
            enumfacing$axis = Facing.Axis.Z;
        }

        return this.getState().withProperty(AXIS, enumfacing$axis);
    }

    /**
     * Convert the BlockState into the correct metadata value
     */
    public int getMetaFromState(State state)
    {
        int i = 0;
        Facing.Axis enumfacing$axis = (Facing.Axis)state.getValue(AXIS);

        if (enumfacing$axis == Facing.Axis.X)
        {
            i |= 4;
        }
        else if (enumfacing$axis == Facing.Axis.Z)
        {
            i |= 8;
        }

        return i;
    }

    protected Property[] getProperties()
    {
        return new Property[] {AXIS};
    }

    public ItemStack createStackedBlock(State state)
    {
        return new ItemStack(this.getItem());
    }

    /**
     * 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, EntityLiving placer)
    {
        return super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, placer).withProperty(AXIS, facing.getAxis());
    }
}
