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