001package net.minecraft.entity.monster;
002
003import net.minecraft.block.Block;
004import net.minecraft.entity.EntityLiving;
005import net.minecraft.entity.IRangedAttackMob;
006import net.minecraft.entity.ai.EntityAIArrowAttack;
007import net.minecraft.entity.ai.EntityAILookIdle;
008import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
009import net.minecraft.entity.ai.EntityAIWander;
010import net.minecraft.entity.ai.EntityAIWatchClosest;
011import net.minecraft.entity.player.EntityPlayer;
012import net.minecraft.entity.projectile.EntitySnowball;
013import net.minecraft.item.Item;
014import net.minecraft.util.DamageSource;
015import net.minecraft.util.MathHelper;
016import net.minecraft.world.World;
017
018public class EntitySnowman extends EntityGolem implements IRangedAttackMob
019{
020    public EntitySnowman(World par1World)
021    {
022        super(par1World);
023        this.texture = "/mob/snowman.png";
024        this.setSize(0.4F, 1.8F);
025        this.getNavigator().setAvoidsWater(true);
026        this.tasks.addTask(1, new EntityAIArrowAttack(this, 0.25F, 20, 10.0F));
027        this.tasks.addTask(2, new EntityAIWander(this, 0.2F));
028        this.tasks.addTask(3, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F));
029        this.tasks.addTask(4, new EntityAILookIdle(this));
030        this.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this, EntityLiving.class, 16.0F, 0, true, false, IMob.mobSelector));
031    }
032
033    /**
034     * Returns true if the newer Entity AI code should be run
035     */
036    public boolean isAIEnabled()
037    {
038        return true;
039    }
040
041    public int getMaxHealth()
042    {
043        return 4;
044    }
045
046    /**
047     * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
048     * use this to react to sunlight and start to burn.
049     */
050    public void onLivingUpdate()
051    {
052        super.onLivingUpdate();
053
054        if (this.isWet())
055        {
056            this.attackEntityFrom(DamageSource.drown, 1);
057        }
058
059        int i = MathHelper.floor_double(this.posX);
060        int j = MathHelper.floor_double(this.posZ);
061
062        if (this.worldObj.getBiomeGenForCoords(i, j).getFloatTemperature() > 1.0F)
063        {
064            this.attackEntityFrom(DamageSource.onFire, 1);
065        }
066
067        for (i = 0; i < 4; ++i)
068        {
069            j = MathHelper.floor_double(this.posX + (double)((float)(i % 2 * 2 - 1) * 0.25F));
070            int k = MathHelper.floor_double(this.posY);
071            int l = MathHelper.floor_double(this.posZ + (double)((float)(i / 2 % 2 * 2 - 1) * 0.25F));
072
073            if (this.worldObj.getBlockId(j, k, l) == 0 && this.worldObj.getBiomeGenForCoords(j, l).getFloatTemperature() < 0.8F && Block.snow.canPlaceBlockAt(this.worldObj, j, k, l))
074            {
075                this.worldObj.func_94575_c(j, k, l, Block.snow.blockID);
076            }
077        }
078    }
079
080    /**
081     * Returns the item ID for the item the mob drops on death.
082     */
083    protected int getDropItemId()
084    {
085        return Item.snowball.itemID;
086    }
087
088    /**
089     * Drop 0-2 items of this living's type. @param par1 - Whether this entity has recently been hit by a player. @param
090     * par2 - Level of Looting used to kill this mob.
091     */
092    protected void dropFewItems(boolean par1, int par2)
093    {
094        int j = this.rand.nextInt(16);
095
096        for (int k = 0; k < j; ++k)
097        {
098            this.dropItem(Item.snowball.itemID, 1);
099        }
100    }
101
102    /**
103     * Attack the specified entity using a ranged attack.
104     */
105    public void attackEntityWithRangedAttack(EntityLiving par1EntityLiving, float par2)
106    {
107        EntitySnowball entitysnowball = new EntitySnowball(this.worldObj, this);
108        double d0 = par1EntityLiving.posX - this.posX;
109        double d1 = par1EntityLiving.posY + (double)par1EntityLiving.getEyeHeight() - 1.100000023841858D - entitysnowball.posY;
110        double d2 = par1EntityLiving.posZ - this.posZ;
111        float f1 = MathHelper.sqrt_double(d0 * d0 + d2 * d2) * 0.2F;
112        entitysnowball.setThrowableHeading(d0, d1 + (double)f1, d2, 1.6F, 12.0F);
113        this.playSound("random.bow", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
114        this.worldObj.spawnEntityInWorld(entitysnowball);
115    }
116}