package common.entity.animal;

import java.util.Collections;

import common.ai.EntityAIFollowParent;
import common.ai.EntityAILookIdle;
import common.ai.EntityAIMate;
import common.ai.EntityAIPanic;
import common.ai.EntityAISwimming;
import common.ai.EntityAITempt;
import common.ai.EntityAIWander;
import common.ai.EntityAIWatchClosest;
import common.block.Block;
import common.entity.npc.EntityNPC;
import common.entity.types.EntityAnimal;
import common.entity.types.EntityLiving;
import common.init.Blocks;
import common.init.Items;
import common.init.SoundEvent;
import common.item.ItemStack;
import common.util.BlockPos;
import common.world.World;

public class EntityMouse extends EntityAnimal {
	public EntityMouse(World world) {
		super(world);
		this.setSize(0.3F, 0.2F);
		this.tasks.addTask(0, new EntityAISwimming(this));
		this.tasks.addTask(1, new EntityAIPanic(this, 1.4D));
		this.tasks.addTask(2, new EntityAIMate(this, 1.0D));
		this.tasks.addTask(3, new EntityAITempt(this, 1.0D, Items.sugar, false));
		this.tasks.addTask(4, new EntityAIFollowParent(this, 1.1D));
		this.tasks.addTask(5, new EntityAIWander(this, 1.0D));
		this.tasks.addTask(6, new EntityAIWatchClosest(this, null, 6.0F));
		this.tasks.addTask(7, new EntityAILookIdle(this));
		this.spawnableBlocks.clear();
		Collections.addAll(this.spawnableBlocks, Blocks.stone, Blocks.tian);
	}

	public float getEyeHeight() {
		return this.height;
	}

	protected void applyEntityAttributes() {
		super.applyEntityAttributes();
		this.setMaxHealth(1);
		this.setSpeedBase(0.25f);
	}

//	protected String getLivingSound() {
//		return "mob.mouse.idle";
//	}

	protected SoundEvent getHurtSound() {
		return SoundEvent.RABBIT_HIT;
	}

	protected SoundEvent getDeathSound() {
		return SoundEvent.RABBIT_HIT;
	}

	protected void playStepSound(BlockPos pos, Block block) {
	}

	protected float getSoundVolume() {
		return 0.3F;
	}
    
//    protected float getSoundPitch() {
//        return (this.rand.floatv() - this.rand.floatv()) * 0.2F + (this.isChild() ? 1.8F : 1.6F);
//    }

	protected void dropFewItems(boolean hit, int looting) {
		int amt = this.rand.zrange(2);
		if(looting > 0) {
			amt += this.rand.zrange(looting + 1);
		}
		for(int z = 0; z < amt; z++) {
			this.dropItem(Items.string, 1);
		}
	}

	public EntityMouse createChild(EntityLiving parent) {
		return new EntityMouse(this.worldObj);
	}

	public boolean isBreedingItem(ItemStack stack) {
		return stack != null && stack.getItem() == Items.sugar;
	}

	protected int getExperiencePoints(EntityNPC player) {
		return this.worldObj.rand.range(0, 1);
	}
	
	public boolean getCanSpawnHere()
    {
        if (((int)this.getEntityBoundingBox().minY) >= this.worldObj.getSeaLevel())
        {
            return false;
        }
        else
        {
            return super.getCanSpawnHere();
        }
    }
    
    protected boolean isValidLightLevel(int level)
    {
    	return level < 6;
    }
    
    public float getBlockPathWeight(BlockPos pos)
    {
        return 0.5F - this.worldObj.getLightBrightness(pos);
    }
	
    public void setCustomNameTag(String name) {
    	super.setCustomNameTag(name);
    	if(this.worldObj != null && !this.worldObj.client)
    		this.setSpeedBase(name.equals("Gonzales") || name.equals("Gonzalez") ? 0.5f : 0.25f);
    }
    
	public int getColor() {
		return 0x888888;
	}
}
