    001    package net.minecraft.src;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import java.util.List;
    006
    007    public class EntityPigZombie extends EntityZombie
    008    {
    009        /** Above zero if this PigZombie is Angry. */
    010        private int angerLevel = 0;
    011
    012        /** A random delay until this PigZombie next makes a sound. */
    013        private int randomSoundDelay = 0;
    014
    015        public EntityPigZombie(World par1World)
    016        {
    017            super(par1World);
    018            this.texture = "/mob/pigzombie.png";
    019            this.moveSpeed = 0.5F;
    020            this.isImmuneToFire = true;
    021        }
    022
    023        /**
    024         * Returns true if the newer Entity AI code should be run
    025         */
    026        protected boolean isAIEnabled()
    027        {
    028            return false;
    029        }
    030
    031        /**
    032         * Called to update the entity's position/logic.
    033         */
    034        public void onUpdate()
    035        {
    036            this.moveSpeed = this.entityToAttack != null ? 0.95F : 0.5F;
    037
    038            if (this.randomSoundDelay > 0 && --this.randomSoundDelay == 0)
    039            {
    040                this.func_85030_a("mob.zombiepig.zpigangry", this.getSoundVolume() * 2.0F, ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F) * 1.8F);
    041            }
    042
    043            super.onUpdate();
    044        }
    045
    046        @SideOnly(Side.CLIENT)
    047
    048        /**
    049         * Returns the texture's file path as a String.
    050         */
    051        public String getTexture()
    052        {
    053            return "/mob/pigzombie.png";
    054        }
    055
    056        /**
    057         * Checks if the entity's current position is a valid location to spawn this entity.
    058         */
    059        public boolean getCanSpawnHere()
    060        {
    061            return this.worldObj.difficultySetting > 0 && this.worldObj.checkIfAABBIsClear(this.boundingBox) && this.worldObj.getCollidingBoundingBoxes(this, this.boundingBox).isEmpty() && !this.worldObj.isAnyLiquid(this.boundingBox);
    062        }
    063
    064        /**
    065         * (abstract) Protected helper method to write subclass entity data to NBT.
    066         */
    067        public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)
    068        {
    069            super.writeEntityToNBT(par1NBTTagCompound);
    070            par1NBTTagCompound.setShort("Anger", (short)this.angerLevel);
    071        }
    072
    073        /**
    074         * (abstract) Protected helper method to read subclass entity data from NBT.
    075         */
    076        public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound)
    077        {
    078            super.readEntityFromNBT(par1NBTTagCompound);
    079            this.angerLevel = par1NBTTagCompound.getShort("Anger");
    080        }
    081
    082        /**
    083         * Finds the closest player within 16 blocks to attack, or null if this Entity isn't interested in attacking
    084         * (Animals, Spiders at day, peaceful PigZombies).
    085         */
    086        protected Entity findPlayerToAttack()
    087        {
    088            return this.angerLevel == 0 ? null : super.findPlayerToAttack();
    089        }
    090
    091        /**
    092         * Called when the entity is attacked.
    093         */
    094        public boolean attackEntityFrom(DamageSource par1DamageSource, int par2)
    095        {
    096            if (this.func_85032_ar())
    097            {
    098                return false;
    099            }
    100            else
    101            {
    102                Entity var3 = par1DamageSource.getEntity();
    103
    104                if (var3 instanceof EntityPlayer)
    105                {
    106                    List var4 = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.expand(32.0D, 32.0D, 32.0D));
    107
    108                    for (int var5 = 0; var5 < var4.size(); ++var5)
    109                    {
    110                        Entity var6 = (Entity)var4.get(var5);
    111
    112                        if (var6 instanceof EntityPigZombie)
    113                        {
    114                            EntityPigZombie var7 = (EntityPigZombie)var6;
    115                            var7.becomeAngryAt(var3);
    116                        }
    117                    }
    118
    119                    this.becomeAngryAt(var3);
    120                }
    121
    122                return super.attackEntityFrom(par1DamageSource, par2);
    123            }
    124        }
    125
    126        /**
    127         * Causes this PigZombie to become angry at the supplied Entity (which will be a player).
    128         */
    129        private void becomeAngryAt(Entity par1Entity)
    130        {
    131            this.entityToAttack = par1Entity;
    132            this.angerLevel = 400 + this.rand.nextInt(400);
    133            this.randomSoundDelay = this.rand.nextInt(40);
    134        }
    135
    136        /**
    137         * Returns the sound this mob makes while it's alive.
    138         */
    139        protected String getLivingSound()
    140        {
    141            return "mob.zombiepig.zpig";
    142        }
    143
    144        /**
    145         * Returns the sound this mob makes when it is hurt.
    146         */
    147        protected String getHurtSound()
    148        {
    149            return "mob.zombiepig.zpighurt";
    150        }
    151
    152        /**
    153         * Returns the sound this mob makes on death.
    154         */
    155        protected String getDeathSound()
    156        {
    157            return "mob.zombiepig.zpigdeath";
    158        }
    159
    160        /**
    161         * Drop 0-2 items of this living's type
    162         */
    163        protected void dropFewItems(boolean par1, int par2)
    164        {
    165            int var3 = this.rand.nextInt(2 + par2);
    166            int var4;
    167
    168            for (var4 = 0; var4 < var3; ++var4)
    169            {
    170                this.dropItem(Item.rottenFlesh.shiftedIndex, 1);
    171            }
    172
    173            var3 = this.rand.nextInt(2 + par2);
    174
    175            for (var4 = 0; var4 < var3; ++var4)
    176            {
    177                this.dropItem(Item.goldNugget.shiftedIndex, 1);
    178            }
    179        }
    180
    181        /**
    182         * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
    183         */
    184        public boolean interact(EntityPlayer par1EntityPlayer)
    185        {
    186            return false;
    187        }
    188
    189        protected void dropRareDrop(int par1)
    190        {
    191            this.dropItem(Item.ingotGold.shiftedIndex, 1);
    192        }
    193
    194        /**
    195         * Returns the item ID for the item the mob drops on death.
    196         */
    197        protected int getDropItemId()
    198        {
    199            return Item.rottenFlesh.shiftedIndex;
    200        }
    201
    202        protected void func_82164_bB()
    203        {
    204            this.setCurrentItemOrArmor(0, new ItemStack(Item.swordGold));
    205        }
    206
    207        /**
    208         * Initialize this creature.
    209         */
    210        public void initCreature()
    211        {
    212            super.initCreature();
    213            this.setVillager(false);
    214        }
    215
    216        /**
    217         * Returns the amount of damage a mob should deal.
    218         */
    219        public int getAttackStrength(Entity par1Entity)
    220        {
    221            ItemStack var2 = this.getHeldItem();
    222            int var3 = 5;
    223
    224            if (var2 != null)
    225            {
    226                var3 += var2.getDamageVsEntity(this);
    227            }
    228
    229            return var3;
    230        }
    231    }