package common.block.natural;

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

public class BlockSlime extends BlockTranslucent {
	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.LOOSE);
		this.setTab(CheatTab.TECHNOLOGY);
		this.slipperiness = 0.8F;
	}

	public void onFallenUpon(World world, BlockPos pos, Entity entity, float distance) {
		if(entity.isSneaking())
			super.onFallenUpon(world, pos, entity, distance);
		else
			entity.fall(distance, 0.0F);
	}

	public void onLanded(World world, Entity entity) {
		if(entity.isSneaking())
			super.onLanded(world, entity);
		else if(entity.motionY < 0.0D)
			entity.motionY = -entity.motionY;
	}

	public void onEntityCollidedWithBlock(World world, BlockPos pos, Entity entity) {
		if(Math.abs(entity.motionY) < 0.1D && !entity.isSneaking()) {
			double friction = 0.4D + Math.abs(entity.motionY) * 0.2D;
			entity.motionX *= friction;
			entity.motionZ *= friction;
		}
		super.onEntityCollidedWithBlock(world, pos, entity);
	}

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