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