package common.block;

import common.entity.Entity;
import common.item.CheatTab;
import common.material.Material;
import common.model.BlockLayer;
import common.model.Model;
import common.model.ModelProvider;
import common.util.BlockPos;
import common.world.State;
import common.world.World;

public class BlockSlime extends BlockBreakable
{
	private static final Model slime = ModelProvider.getModelProvider().getModel("slime")
			.add(0, 0, 0, 16, 16, 16)
				.d().uv(0, 0, 16, 16).noCull()
				.u().uv(0, 0, 16, 16).noCull()
				.n().uv(0, 0, 16, 16).noCull()
				.s().uv(0, 0, 16, 16).noCull()
				.w().uv(0, 0, 16, 16).noCull()
				.e().uv(0, 0, 16, 16).noCull()
			.add(3, 3, 3, 13, 13, 13)
				.d().uv(3, 3, 13, 13).noCull()
				.u().uv(3, 3, 13, 13).noCull()
				.n().uv(3, 3, 13, 13).noCull()
				.s().uv(3, 3, 13, 13).noCull()
				.w().uv(3, 3, 13, 13).noCull()
				.e().uv(3, 3, 13, 13).noCull()
	;
	
    public BlockSlime()
    {
        super(Material.clay, false);
        this.setTab(CheatTab.tabTech);
        this.slipperiness = 0.8F;
    }

    public BlockLayer getBlockLayer()
    {
        return BlockLayer.TRANSLUCENT;
    }

    /**
     * Block's chance to react to a living entity falling on it.
     */
    public void onFallenUpon(World worldIn, BlockPos pos, Entity entityIn, float fallDistance)
    {
        if (entityIn.isSneaking())
        {
            super.onFallenUpon(worldIn, pos, entityIn, fallDistance);
        }
        else
        {
            entityIn.fall(fallDistance, 0.0F);
        }
    }

    /**
     * Called when an Entity lands on this Block. This method *must* update motionY because the entity will not do that
     * on its own
     */
    public void onLanded(World worldIn, Entity entityIn)
    {
        if (entityIn.isSneaking())
        {
            super.onLanded(worldIn, entityIn);
        }
        else if (entityIn.motionY < 0.0D)
        {
            entityIn.motionY = -entityIn.motionY;
        }
    }

    /**
     * Triggered whenever an entity collides with this block (enters into the block)
     */
    public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, Entity entityIn)
    {
        if (Math.abs(entityIn.motionY) < 0.1D && !entityIn.isSneaking())
        {
            double d0 = 0.4D + Math.abs(entityIn.motionY) * 0.2D;
            entityIn.motionX *= d0;
            entityIn.motionZ *= d0;
        }

        super.onEntityCollidedWithBlock(worldIn, pos, entityIn);
    }

    public Model getModel(ModelProvider provider, String name, State state) {
    	return slime;
    }
}
