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