package common.block;

import java.util.List;

import common.entity.Entity;
import common.entity.item.EntityBoat;
import common.entity.types.EntityLiving;
import common.init.Blocks;
import common.item.CheatTab;
import common.model.Model;
import common.model.ModelProvider;
import common.model.ModelRotation;
import common.properties.IProperty;
import common.util.BlockPos;
import common.util.BoundingBox;
import common.util.Facing;
import common.world.IWorldAccess;
import common.world.State;
import common.world.World;

public class BlockLilyPad extends BlockBush
{
	public BlockLilyPad()
    {
        float f = 0.5F;
        float f1 = 0.015625F;
        this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f1, 0.5F + f);
        this.setDefaultState(this.getBaseState().withProperty(BlockDirectional.FACING, Facing.NORTH));
        this.setTab(CheatTab.tabPlants);
    }
	
    public void addCollisionBoxesToList(World worldIn, BlockPos pos, State state, BoundingBox mask, List<BoundingBox> list, Entity collidingEntity)
    {
        if (collidingEntity == null || !(collidingEntity instanceof EntityBoat))
        {
            super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
        }
    }

    public BoundingBox getCollisionBoundingBox(World worldIn, BlockPos pos, State state)
    {
        return new BoundingBox((double)pos.getX() + this.minX, (double)pos.getY() + this.minY, (double)pos.getZ() + this.minZ, (double)pos.getX() + this.maxX, (double)pos.getY() + this.maxY, (double)pos.getZ() + this.maxZ);
    }

//    public int getBlockColor()
//    {
//        return 7455580;
//    }

    public int getRenderColor(State state)
    {
        return 7455580;
    }

    public int colorMultiplier(IWorldAccess worldIn, BlockPos pos, int renderPass)
    {
        return 2129968;
    }
    
    protected boolean canPlaceBlockOn(Block ground)
    {
        return ground.getMaterial().isColdLiquid() && ground instanceof BlockStaticLiquid;
    }

    public boolean canBlockStay(World worldIn, BlockPos pos, State state)
    {
        if (pos.getY() >= 0 && pos.getY() < 512)
        {
            State iblockstate = worldIn.getState(pos.down());
            return (iblockstate.getBlock().getMaterial().isColdLiquid() && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0)
            		|| iblockstate.getBlock() == Blocks.ice || iblockstate.getBlock() == Blocks.packed_ice;
        }
        else
        {
            return false;
        }
    }
    
//    public int getMetaFromState(IBlockState state)
//    {
//        return 0;
//    }
    
    public State getStateFromMeta(int meta)
    {
        return this.getState().withProperty(BlockDirectional.FACING, Facing.getHorizontal(meta));
    }
    
    public int getMetaFromState(State state)
    {
        return ((Facing)state.getValue(BlockDirectional.FACING)).getHorizontalIndex();
    }

    protected IProperty[] getProperties()
    {
        return new IProperty[] {BlockDirectional.FACING};
    }
    
    public State onBlockPlaced(World worldIn, BlockPos pos, Facing facing, float hitX, float hitY, float hitZ, int meta, EntityLiving placer)
    {
        return this.getState().withProperty(BlockDirectional.FACING, placer.getHorizontalFacing().getOpposite());
    }

    public Model getModel(ModelProvider provider, String name, State state) {
    	return provider.getModel("waterlily").noOcclude()
			.add(0, 0.25f, 0, 16, 0.25f, 16)
				.d().uv(16, 16, 0, 0).tint().noCull()
				.u().uv(16, 0, 0, 16).tint().noCull()
				.rotate(ModelRotation.getNorthRot(state.getValue(BlockDirectional.FACING)));
    }
}
