| 1 | package net.minecraft.entity.monster;
|
| 2 |
|
| 3 | import java.util.Random;
|
| 4 | import net.minecraft.block.Block;
|
| 5 | import net.minecraft.block.BlockSilverfish;
|
| 6 | import net.minecraft.block.state.IBlockState;
|
| 7 | import net.minecraft.entity.EnumCreatureAttribute;
|
| 8 | import net.minecraft.entity.SharedMonsterAttributes;
|
| 9 | import net.minecraft.entity.ai.EntityAIAttackOnCollide;
|
| 10 | import net.minecraft.entity.ai.EntityAIBase;
|
| 11 | import net.minecraft.entity.ai.EntityAIHurtByTarget;
|
| 12 | import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
|
| 13 | import net.minecraft.entity.ai.EntityAISwimming;
|
| 14 | import net.minecraft.entity.ai.EntityAIWander;
|
| 15 | import net.minecraft.entity.player.EntityPlayer;
|
| 16 | import net.minecraft.init.Blocks;
|
| 17 | import net.minecraft.item.Item;
|
| 18 | import net.minecraft.util.BlockPos;
|
| 19 | import net.minecraft.util.DamageSource;
|
| 20 | import net.minecraft.util.EntityDamageSource;
|
| 21 | import net.minecraft.util.EnumFacing;
|
| 22 | import net.minecraft.world.World;
|
| 23 |
|
| 24 | public class EntitySilverfish extends EntityMob
|
| 25 | {
|
| 26 | private EntitySilverfish.AISummonSilverfish summonSilverfish;
|
| 27 |
|
| 28 | public EntitySilverfish(World worldIn)
|
| 29 | {
|
| 30 | super(worldIn);
|
| 31 | this.setSize(0.4F, 0.3F);
|
| 32 | this.tasks.addTask(1, new EntityAISwimming(this));
|
| 33 | this.tasks.addTask(3, this.summonSilverfish = new EntitySilverfish.AISummonSilverfish(this));
|
| 34 | this.tasks.addTask(4, new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.0D, false));
|
| 35 | this.tasks.addTask(5, new EntitySilverfish.AIHideInStone(this));
|
| 36 | this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true, new Class[0]));
|
| 37 | this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true));
|
| 38 | }
|
| 39 |
|
| 40 | /**
|
| 41 | * Returns the Y Offset of this entity.
|
| 42 | */
|
| 43 | public double getYOffset()
|
| 44 | {
|
| 45 | return 0.2D;
|
| 46 | }
|
| 47 |
|
| 48 | public float getEyeHeight()
|
| 49 | {
|
| 50 | return 0.1F;
|
| 51 | }
|
| 52 |
|
| 53 | protected void applyEntityAttributes()
|
| 54 | {
|
| 55 | super.applyEntityAttributes();
|
| 56 | this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(8.0D);
|
| 57 | this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.25D);
|
| 58 | this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(1.0D);
|
| 59 | }
|
| 60 |
|
| 61 | /**
|
| 62 | * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
|
| 63 | * prevent them from trampling crops
|
| 64 | */
|
| 65 | protected boolean canTriggerWalking()
|
| 66 | {
|
| 67 | return false;
|
| 68 | }
|
| 69 |
|
| 70 | /**
|
| 71 | * Returns the sound this mob makes while it's alive.
|
| 72 | */
|
| 73 | protected String getLivingSound()
|
| 74 | {
|
| 75 | return "mob.silverfish.say";
|
| 76 | }
|
| 77 |
|
| 78 | /**
|
| 79 | * Returns the sound this mob makes when it is hurt.
|
| 80 | */
|
| 81 | protected String getHurtSound()
|
| 82 | {
|
| 83 | return "mob.silverfish.hit";
|
| 84 | }
|
| 85 |
|
| 86 | /**
|
| 87 | * Returns the sound this mob makes on death.
|
| 88 | */
|
| 89 | protected String getDeathSound()
|
| 90 | {
|
| 91 | return "mob.silverfish.kill";
|
| 92 | }
|
| 93 |
|
| 94 | /**
|
| 95 | * Called when the entity is attacked.
|
| 96 | */
|
| 97 | public boolean attackEntityFrom(DamageSource source, float amount)
|
| 98 | {
|
| 99 | if (this.isEntityInvulnerable(source))
|
| 100 | {
|
| 101 | return false;
|
| 102 | }
|
| 103 | else
|
| 104 | {
|
| 105 | if (source instanceof EntityDamageSource || source == DamageSource.magic)
|
| 106 | {
|
| 107 | this.summonSilverfish.func_179462_f();
|
| 108 | }
|
| 109 |
|
| 110 | return super.attackEntityFrom(source, amount);
|
| 111 | }
|
| 112 | }
|
| 113 |
|
| 114 | protected void playStepSound(BlockPos pos, Block blockIn)
|
| 115 | {
|
| 116 | this.playSound("mob.silverfish.step", 0.15F, 1.0F);
|
| 117 | }
|
| 118 |
|
| 119 | protected Item getDropItem()
|
| 120 | {
|
| 121 | return null;
|
| 122 | }
|
| 123 |
|
| 124 | /**
|
| 125 | * Called to update the entity's position/logic.
|
| 126 | */
|
| 127 | public void onUpdate()
|
| 128 | {
|
| 129 | this.renderYawOffset = this.rotationYaw;
|
| 130 | super.onUpdate();
|
| 131 | }
|
| 132 |
|
| 133 | public float getBlockPathWeight(BlockPos pos)
|
| 134 | {
|
| 135 | return this.worldObj.getBlockState(pos.down()).getBlock() == Blocks.stone ? 10.0F : super.getBlockPathWeight(pos);
|
| 136 | }
|
| 137 |
|
| 138 | /**
|
| 139 | * Checks to make sure the light is not too bright where the mob is spawning
|
| 140 | */
|
| 141 | protected boolean isValidLightLevel()
|
| 142 | {
|
| 143 | return true;
|
| 144 | }
|
| 145 |
|
| 146 | /**
|
| 147 | * Checks if the entity's current position is a valid location to spawn this entity.
|
| 148 | */
|
| 149 | public boolean getCanSpawnHere()
|
| 150 | {
|
| 151 | if (super.getCanSpawnHere())
|
| 152 | {
|
| 153 | EntityPlayer entityplayer = this.worldObj.getClosestPlayerToEntity(this, 5.0D);
|
| 154 | return entityplayer == null;
|
| 155 | }
|
| 156 | else
|
| 157 | {
|
| 158 | return false;
|
| 159 | }
|
| 160 | }
|
| 161 |
|
| 162 | /**
|
| 163 | * Get this Entity's EnumCreatureAttribute
|
| 164 | */
|
| 165 | public EnumCreatureAttribute getCreatureAttribute()
|
| 166 | {
|
| 167 | return EnumCreatureAttribute.ARTHROPOD;
|
| 168 | }
|
| 169 |
|
| 170 | static class AIHideInStone extends EntityAIWander
|
| 171 | {
|
| 172 | private final EntitySilverfish silverfish;
|
| 173 | private EnumFacing facing;
|
| 174 | private boolean field_179484_c;
|
| 175 |
|
| 176 | public AIHideInStone(EntitySilverfish silverfishIn)
|
| 177 | {
|
| 178 | super(silverfishIn, 1.0D, 10);
|
| 179 | this.silverfish = silverfishIn;
|
| 180 | this.setMutexBits(1);
|
| 181 | }
|
| 182 |
|
| 183 | public boolean shouldExecute()
|
| 184 | {
|
| 185 | if (this.silverfish.getAttackTarget() != null)
|
| 186 | {
|
| 187 | return false;
|
| 188 | }
|
| 189 | else if (!this.silverfish.getNavigator().noPath())
|
| 190 | {
|
| 191 | return false;
|
| 192 | }
|
| 193 | else
|
| 194 | {
|
| 195 | Random random = this.silverfish.getRNG();
|
| 196 |
|
| 197 | if (random.nextInt(10) == 0)
|
| 198 | {
|
| 199 | this.facing = EnumFacing.random(random);
|
| 200 | BlockPos blockpos = (new BlockPos(this.silverfish.posX, this.silverfish.posY + 0.5D, this.silverfish.posZ)).offset(this.facing);
|
| 201 | IBlockState iblockstate = this.silverfish.worldObj.getBlockState(blockpos);
|
| 202 |
|
| 203 | if (BlockSilverfish.canContainSilverfish(iblockstate))
|
| 204 | {
|
| 205 | this.field_179484_c = true;
|
| 206 | return true;
|
| 207 | }
|
| 208 | }
|
| 209 |
|
| 210 | this.field_179484_c = false;
|
| 211 | return super.shouldExecute();
|
| 212 | }
|
| 213 | }
|
| 214 |
|
| 215 | public boolean continueExecuting()
|
| 216 | {
|
| 217 | return this.field_179484_c ? false : super.continueExecuting();
|
| 218 | }
|
| 219 |
|
| 220 | public void startExecuting()
|
| 221 | {
|
| 222 | if (!this.field_179484_c)
|
| 223 | {
|
| 224 | super.startExecuting();
|
| 225 | }
|
| 226 | else
|
| 227 | {
|
| 228 | World world = this.silverfish.worldObj;
|
| 229 | BlockPos blockpos = (new BlockPos(this.silverfish.posX, this.silverfish.posY + 0.5D, this.silverfish.posZ)).offset(this.facing);
|
| 230 | IBlockState iblockstate = world.getBlockState(blockpos);
|
| 231 |
|
| 232 | if (BlockSilverfish.canContainSilverfish(iblockstate))
|
| 233 | {
|
| 234 | world.setBlockState(blockpos, Blocks.monster_egg.getDefaultState().withProperty(BlockSilverfish.VARIANT, BlockSilverfish.EnumType.forModelBlock(iblockstate)), 3);
|
| 235 | this.silverfish.spawnExplosionParticle();
|
| 236 | this.silverfish.setDead();
|
| 237 | }
|
| 238 | }
|
| 239 | }
|
| 240 | }
|
| 241 |
|
| 242 | static class AISummonSilverfish extends EntityAIBase
|
| 243 | {
|
| 244 | private EntitySilverfish silverfish;
|
| 245 | private int field_179463_b;
|
| 246 |
|
| 247 | public AISummonSilverfish(EntitySilverfish silverfishIn)
|
| 248 | {
|
| 249 | this.silverfish = silverfishIn;
|
| 250 | }
|
| 251 |
|
| 252 | public void func_179462_f()
|
| 253 | {
|
| 254 | if (this.field_179463_b == 0)
|
| 255 | {
|
| 256 | this.field_179463_b = 20;
|
| 257 | }
|
| 258 | }
|
| 259 |
|
| 260 | public boolean shouldExecute()
|
| 261 | {
|
| 262 | return this.field_179463_b > 0;
|
| 263 | }
|
| 264 |
|
| 265 | public void updateTask()
|
| 266 | {
|
| 267 | --this.field_179463_b;
|
| 268 |
|
| 269 | if (this.field_179463_b <= 0)
|
| 270 | {
|
| 271 | World world = this.silverfish.worldObj;
|
| 272 | Random random = this.silverfish.getRNG();
|
| 273 | BlockPos blockpos = new BlockPos(this.silverfish);
|
| 274 |
|
| 275 | for (int i = 0; i <= 5 && i >= -5; i = i <= 0 ? 1 - i : 0 - i)
|
| 276 | {
|
| 277 | for (int j = 0; j <= 10 && j >= -10; j = j <= 0 ? 1 - j : 0 - j)
|
| 278 | {
|
| 279 | for (int k = 0; k <= 10 && k >= -10; k = k <= 0 ? 1 - k : 0 - k)
|
| 280 | {
|
| 281 | BlockPos blockpos1 = blockpos.add(j, i, k);
|
| 282 | IBlockState iblockstate = world.getBlockState(blockpos1);
|
| 283 |
|
| 284 | if (iblockstate.getBlock() == Blocks.monster_egg)
|
| 285 | {
|
| 286 | if (world.getGameRules().getBoolean("mobGriefing"))
|
| 287 | {
|
| 288 | world.destroyBlock(blockpos1, true);
|
| 289 | }
|
| 290 | else
|
| 291 | {
|
| 292 | world.setBlockState(blockpos1, ((BlockSilverfish.EnumType)iblockstate.getValue(BlockSilverfish.VARIANT)).getModelBlock(), 3);
|
| 293 | }
|
| 294 |
|
| 295 | if (random.nextBoolean())
|
| 296 | {
|
| 297 | return;
|
| 298 | }
|
| 299 | }
|
| 300 | }
|
| 301 | }
|
| 302 | }
|
| 303 | }
|
| 304 | }
|
| 305 | }
|
| 306 | }
|
| 307 |
|