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 var1 = MathHelper.floor_double(this.posX);
060        int var2 = MathHelper.floor_double(this.posZ);
061
062        if (this.worldObj.getBiomeGenForCoords(var1, var2).getFloatTemperature() > 1.0F)
063        {
064            this.attackEntityFrom(DamageSource.onFire, 1);
065        }
066
067        for (var1 = 0; var1 < 4; ++var1)
068        {
069            var2 = MathHelper.floor_double(this.posX + (double)((float)(var1 % 2 * 2 - 1) * 0.25F));
070            int var3 = MathHelper.floor_double(this.posY);
071            int var4 = MathHelper.floor_double(this.posZ + (double)((float)(var1 / 2 % 2 * 2 - 1) * 0.25F));
072
073            if (this.worldObj.getBlockId(var2, var3, var4) == 0 && this.worldObj.getBiomeGenForCoords(var2, var4).getFloatTemperature() < 0.8F && Block.snow.canPlaceBlockAt(this.worldObj, var2, var3, var4))
074            {
075                this.worldObj.setBlockWithNotify(var2, var3, var4, 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 var3 = this.rand.nextInt(16);
095
096        for (int var4 = 0; var4 < var3; ++var4)
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)
106    {
107        EntitySnowball var2 = new EntitySnowball(this.worldObj, this);
108        double var3 = par1EntityLiving.posX - this.posX;
109        double var5 = par1EntityLiving.posY + (double)par1EntityLiving.getEyeHeight() - 1.100000023841858D - var2.posY;
110        double var7 = par1EntityLiving.posZ - this.posZ;
111        float var9 = MathHelper.sqrt_double(var3 * var3 + var7 * var7) * 0.2F;
112        var2.setThrowableHeading(var3, var5 + (double)var9, var7, 1.6F, 12.0F);
113        this.playSound("random.bow", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
114        this.worldObj.spawnEntityInWorld(var2);
115    }
116}