    001    package net.minecraft.src;
    002
    003    public class EntitySilverfish extends EntityMob
    004    {
    005        /**
    006         * A cooldown before this entity will search for another Silverfish to join them in battle.
    007         */
    008        private int allySummonCooldown;
    009
    010        public EntitySilverfish(World par1World)
    011        {
    012            super(par1World);
    013            this.texture = "/mob/silverfish.png";
    014            this.setSize(0.3F, 0.7F);
    015            this.moveSpeed = 0.6F;
    016        }
    017
    018        public int getMaxHealth()
    019        {
    020            return 8;
    021        }
    022
    023        /**
    024         * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
    025         * prevent them from trampling crops
    026         */
    027        protected boolean canTriggerWalking()
    028        {
    029            return false;
    030        }
    031
    032        /**
    033         * Finds the closest player within 16 blocks to attack, or null if this Entity isn't interested in attacking
    034         * (Animals, Spiders at day, peaceful PigZombies).
    035         */
    036        protected Entity findPlayerToAttack()
    037        {
    038            double var1 = 8.0D;
    039            return this.worldObj.getClosestVulnerablePlayerToEntity(this, var1);
    040        }
    041
    042        /**
    043         * Returns the sound this mob makes while it's alive.
    044         */
    045        protected String getLivingSound()
    046        {
    047            return "mob.silverfish.say";
    048        }
    049
    050        /**
    051         * Returns the sound this mob makes when it is hurt.
    052         */
    053        protected String getHurtSound()
    054        {
    055            return "mob.silverfish.hit";
    056        }
    057
    058        /**
    059         * Returns the sound this mob makes on death.
    060         */
    061        protected String getDeathSound()
    062        {
    063            return "mob.silverfish.kill";
    064        }
    065
    066        /**
    067         * Called when the entity is attacked.
    068         */
    069        public boolean attackEntityFrom(DamageSource par1DamageSource, int par2)
    070        {
    071            if (this.allySummonCooldown <= 0 && (par1DamageSource instanceof EntityDamageSource || par1DamageSource == DamageSource.magic))
    072            {
    073                this.allySummonCooldown = 20;
    074            }
    075
    076            return super.attackEntityFrom(par1DamageSource, par2);
    077        }
    078
    079        /**
    080         * Basic mob attack. Default to touch of death in EntityCreature. Overridden by each mob to define their attack.
    081         */
    082        protected void attackEntity(Entity par1Entity, float par2)
    083        {
    084            if (this.attackTime <= 0 && par2 < 1.2F && par1Entity.boundingBox.maxY > this.boundingBox.minY && par1Entity.boundingBox.minY < this.boundingBox.maxY)
    085            {
    086                this.attackTime = 20;
    087                par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this), this.func_82193_c(par1Entity));
    088            }
    089        }
    090
    091        /**
    092         * Plays step sound at given x, y, z for the entity
    093         */
    094        protected void playStepSound(int par1, int par2, int par3, int par4)
    095        {
    096            this.worldObj.playSoundAtEntity(this, "mob.silverfish.step", 0.15F, 1.0F);
    097        }
    098
    099        /**
    100         * Returns the item ID for the item the mob drops on death.
    101         */
    102        protected int getDropItemId()
    103        {
    104            return 0;
    105        }
    106
    107        /**
    108         * Called to update the entity's position/logic.
    109         */
    110        public void onUpdate()
    111        {
    112            this.renderYawOffset = this.rotationYaw;
    113            super.onUpdate();
    114        }
    115
    116        protected void updateEntityActionState()
    117        {
    118            super.updateEntityActionState();
    119
    120            if (!this.worldObj.isRemote)
    121            {
    122                int var1;
    123                int var2;
    124                int var3;
    125                int var5;
    126
    127                if (this.allySummonCooldown > 0)
    128                {
    129                    --this.allySummonCooldown;
    130
    131                    if (this.allySummonCooldown == 0)
    132                    {
    133                        var1 = MathHelper.floor_double(this.posX);
    134                        var2 = MathHelper.floor_double(this.posY);
    135                        var3 = MathHelper.floor_double(this.posZ);
    136                        boolean var4 = false;
    137
    138                        for (var5 = 0; !var4 && var5 <= 5 && var5 >= -5; var5 = var5 <= 0 ? 1 - var5 : 0 - var5)
    139                        {
    140                            for (int var6 = 0; !var4 && var6 <= 10 && var6 >= -10; var6 = var6 <= 0 ? 1 - var6 : 0 - var6)
    141                            {
    142                                for (int var7 = 0; !var4 && var7 <= 10 && var7 >= -10; var7 = var7 <= 0 ? 1 - var7 : 0 - var7)
    143                                {
    144                                    int var8 = this.worldObj.getBlockId(var1 + var6, var2 + var5, var3 + var7);
    145
    146                                    if (var8 == Block.silverfish.blockID)
    147                                    {
    148                                        this.worldObj.playAuxSFX(2001, var1 + var6, var2 + var5, var3 + var7, Block.silverfish.blockID + (this.worldObj.getBlockMetadata(var1 + var6, var2 + var5, var3 + var7) << 12));
    149                                        this.worldObj.setBlockWithNotify(var1 + var6, var2 + var5, var3 + var7, 0);
    150                                        Block.silverfish.onBlockDestroyedByPlayer(this.worldObj, var1 + var6, var2 + var5, var3 + var7, 0);
    151
    152                                        if (this.rand.nextBoolean())
    153                                        {
    154                                            var4 = true;
    155                                            break;
    156                                        }
    157                                    }
    158                                }
    159                            }
    160                        }
    161                    }
    162                }
    163
    164                if (this.entityToAttack == null && !this.hasPath())
    165                {
    166                    var1 = MathHelper.floor_double(this.posX);
    167                    var2 = MathHelper.floor_double(this.posY + 0.5D);
    168                    var3 = MathHelper.floor_double(this.posZ);
    169                    int var9 = this.rand.nextInt(6);
    170                    var5 = this.worldObj.getBlockId(var1 + Facing.offsetsXForSide[var9], var2 + Facing.offsetsYForSide[var9], var3 + Facing.offsetsZForSide[var9]);
    171
    172                    if (BlockSilverfish.getPosingIdByMetadata(var5))
    173                    {
    174                        this.worldObj.setBlockAndMetadataWithNotify(var1 + Facing.offsetsXForSide[var9], var2 + Facing.offsetsYForSide[var9], var3 + Facing.offsetsZForSide[var9], Block.silverfish.blockID, BlockSilverfish.getMetadataForBlockType(var5));
    175                        this.spawnExplosionParticle();
    176                        this.setDead();
    177                    }
    178                    else
    179                    {
    180                        this.updateWanderPath();
    181                    }
    182                }
    183                else if (this.entityToAttack != null && !this.hasPath())
    184                {
    185                    this.entityToAttack = null;
    186                }
    187            }
    188        }
    189
    190        /**
    191         * Takes a coordinate in and returns a weight to determine how likely this creature will try to path to the block.
    192         * Args: x, y, z
    193         */
    194        public float getBlockPathWeight(int par1, int par2, int par3)
    195        {
    196            return this.worldObj.getBlockId(par1, par2 - 1, par3) == Block.stone.blockID ? 10.0F : super.getBlockPathWeight(par1, par2, par3);
    197        }
    198
    199        /**
    200         * Checks to make sure the light is not too bright where the mob is spawning
    201         */
    202        protected boolean isValidLightLevel()
    203        {
    204            return true;
    205        }
    206
    207        /**
    208         * Checks if the entity's current position is a valid location to spawn this entity.
    209         */
    210        public boolean getCanSpawnHere()
    211        {
    212            if (super.getCanSpawnHere())
    213            {
    214                EntityPlayer var1 = this.worldObj.getClosestPlayerToEntity(this, 5.0D);
    215                return var1 == null;
    216            }
    217            else
    218            {
    219                return false;
    220            }
    221        }
    222
    223        public int func_82193_c(Entity par1Entity)
    224        {
    225            return 1;
    226        }
    227
    228        /**
    229         * Get this Entity's EnumCreatureAttribute
    230         */
    231        public EnumCreatureAttribute getCreatureAttribute()
    232        {
    233            return EnumCreatureAttribute.ARTHROPOD;
    234        }
    235    }