| 1 | package net.minecraft.entity.monster;
|
| 2 |
|
| 3 | import java.util.Calendar;
|
| 4 | import net.minecraft.block.Block;
|
| 5 | import net.minecraft.enchantment.Enchantment;
|
| 6 | import net.minecraft.enchantment.EnchantmentHelper;
|
| 7 | import net.minecraft.entity.Entity;
|
| 8 | import net.minecraft.entity.EntityCreature;
|
| 9 | import net.minecraft.entity.EntityLivingBase;
|
| 10 | import net.minecraft.entity.EnumCreatureAttribute;
|
| 11 | import net.minecraft.entity.IEntityLivingData;
|
| 12 | import net.minecraft.entity.IRangedAttackMob;
|
| 13 | import net.minecraft.entity.SharedMonsterAttributes;
|
| 14 | import net.minecraft.entity.ai.EntityAIArrowAttack;
|
| 15 | import net.minecraft.entity.ai.EntityAIAttackOnCollide;
|
| 16 | import net.minecraft.entity.ai.EntityAIAvoidEntity;
|
| 17 | import net.minecraft.entity.ai.EntityAIFleeSun;
|
| 18 | import net.minecraft.entity.ai.EntityAIHurtByTarget;
|
| 19 | import net.minecraft.entity.ai.EntityAILookIdle;
|
| 20 | import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
|
| 21 | import net.minecraft.entity.ai.EntityAIRestrictSun;
|
| 22 | import net.minecraft.entity.ai.EntityAISwimming;
|
| 23 | import net.minecraft.entity.ai.EntityAIWander;
|
| 24 | import net.minecraft.entity.ai.EntityAIWatchClosest;
|
| 25 | import net.minecraft.entity.passive.EntityWolf;
|
| 26 | import net.minecraft.entity.player.EntityPlayer;
|
| 27 | import net.minecraft.entity.projectile.EntityArrow;
|
| 28 | import net.minecraft.init.Blocks;
|
| 29 | import net.minecraft.init.Items;
|
| 30 | import net.minecraft.item.Item;
|
| 31 | import net.minecraft.item.ItemStack;
|
| 32 | import net.minecraft.nbt.NBTTagCompound;
|
| 33 | import net.minecraft.potion.Potion;
|
| 34 | import net.minecraft.potion.PotionEffect;
|
| 35 | import net.minecraft.stats.AchievementList;
|
| 36 | import net.minecraft.util.BlockPos;
|
| 37 | import net.minecraft.util.DamageSource;
|
| 38 | import net.minecraft.world.DifficultyInstance;
|
| 39 | import net.minecraft.world.World;
|
| 40 | import net.minecraft.world.WorldProviderHell;
|
| 41 |
|
| 42 | public class EntitySkeleton extends EntityMob implements IRangedAttackMob
|
| 43 | {
|
| 44 | private EntityAIArrowAttack aiArrowAttack = new EntityAIArrowAttack(this, 1.0D, 20, 60, 15.0F);
|
| 45 | private EntityAIAttackOnCollide aiAttackOnCollide = new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.2D, false);
|
| 46 |
|
| 47 | public EntitySkeleton(World worldIn)
|
| 48 | {
|
| 49 | super(worldIn);
|
| 50 | this.tasks.addTask(1, new EntityAISwimming(this));
|
| 51 | this.tasks.addTask(2, new EntityAIRestrictSun(this));
|
| 52 | this.tasks.addTask(3, new EntityAIFleeSun(this, 1.0D));
|
| 53 | this.tasks.addTask(3, new EntityAIAvoidEntity(this, EntityWolf.class, 6.0F, 1.0D, 1.2D));
|
| 54 | this.tasks.addTask(4, new EntityAIWander(this, 1.0D));
|
| 55 | this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
|
| 56 | this.tasks.addTask(6, new EntityAILookIdle(this));
|
| 57 | this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false, new Class[0]));
|
| 58 | this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true));
|
| 59 | this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityIronGolem.class, true));
|
| 60 |
|
| 61 | if (worldIn != null && !worldIn.isRemote)
|
| 62 | {
|
| 63 | this.setCombatTask();
|
| 64 | }
|
| 65 | }
|
| 66 |
|
| 67 | protected void applyEntityAttributes()
|
| 68 | {
|
| 69 | super.applyEntityAttributes();
|
| 70 | this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.25D);
|
| 71 | }
|
| 72 |
|
| 73 | protected void entityInit()
|
| 74 | {
|
| 75 | super.entityInit();
|
| 76 | this.dataWatcher.addObject(13, new Byte((byte)0));
|
| 77 | }
|
| 78 |
|
| 79 | /**
|
| 80 | * Returns the sound this mob makes while it's alive.
|
| 81 | */
|
| 82 | protected String getLivingSound()
|
| 83 | {
|
| 84 | return "mob.skeleton.say";
|
| 85 | }
|
| 86 |
|
| 87 | /**
|
| 88 | * Returns the sound this mob makes when it is hurt.
|
| 89 | */
|
| 90 | protected String getHurtSound()
|
| 91 | {
|
| 92 | return "mob.skeleton.hurt";
|
| 93 | }
|
| 94 |
|
| 95 | /**
|
| 96 | * Returns the sound this mob makes on death.
|
| 97 | */
|
| 98 | protected String getDeathSound()
|
| 99 | {
|
| 100 | return "mob.skeleton.death";
|
| 101 | }
|
| 102 |
|
| 103 | protected void playStepSound(BlockPos pos, Block blockIn)
|
| 104 | {
|
| 105 | this.playSound("mob.skeleton.step", 0.15F, 1.0F);
|
| 106 | }
|
| 107 |
|
| 108 | public boolean attackEntityAsMob(Entity entityIn)
|
| 109 | {
|
| 110 | if (super.attackEntityAsMob(entityIn))
|
| 111 | {
|
| 112 | if (this.getSkeletonType() == 1 && entityIn instanceof EntityLivingBase)
|
| 113 | {
|
| 114 | ((EntityLivingBase)entityIn).addPotionEffect(new PotionEffect(Potion.wither.id, 200));
|
| 115 | }
|
| 116 |
|
| 117 | return true;
|
| 118 | }
|
| 119 | else
|
| 120 | {
|
| 121 | return false;
|
| 122 | }
|
| 123 | }
|
| 124 |
|
| 125 | /**
|
| 126 | * Get this Entity's EnumCreatureAttribute
|
| 127 | */
|
| 128 | public EnumCreatureAttribute getCreatureAttribute()
|
| 129 | {
|
| 130 | return EnumCreatureAttribute.UNDEAD;
|
| 131 | }
|
| 132 |
|
| 133 | /**
|
| 134 | * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
|
| 135 | * use this to react to sunlight and start to burn.
|
| 136 | */
|
| 137 | public void onLivingUpdate()
|
| 138 | {
|
| 139 | if (this.worldObj.isDaytime() && !this.worldObj.isRemote)
|
| 140 | {
|
| 141 | float f = this.getBrightness(1.0F);
|
| 142 | BlockPos blockpos = new BlockPos(this.posX, (double)Math.round(this.posY), this.posZ);
|
| 143 |
|
| 144 | if (f > 0.5F && this.rand.nextFloat() * 30.0F < (f - 0.4F) * 2.0F && this.worldObj.canSeeSky(blockpos))
|
| 145 | {
|
| 146 | boolean flag = true;
|
| 147 | ItemStack itemstack = this.getEquipmentInSlot(4);
|
| 148 |
|
| 149 | if (itemstack != null)
|
| 150 | {
|
| 151 | if (itemstack.isItemStackDamageable())
|
| 152 | {
|
| 153 | itemstack.setItemDamage(itemstack.getItemDamage() + this.rand.nextInt(2));
|
| 154 |
|
| 155 | if (itemstack.getItemDamage() >= itemstack.getMaxDamage())
|
| 156 | {
|
| 157 | this.renderBrokenItemStack(itemstack);
|
| 158 | this.setCurrentItemOrArmor(4, (ItemStack)null);
|
| 159 | }
|
| 160 | }
|
| 161 |
|
| 162 | flag = false;
|
| 163 | }
|
| 164 |
|
| 165 | if (flag)
|
| 166 | {
|
| 167 | this.setFire(8);
|
| 168 | }
|
| 169 | }
|
| 170 | }
|
| 171 |
|
| 172 | if (this.worldObj.isRemote && this.getSkeletonType() == 1)
|
| 173 | {
|
| 174 | this.setSize(0.72F, 2.535F);
|
| 175 | }
|
| 176 |
|
| 177 | super.onLivingUpdate();
|
| 178 | }
|
| 179 |
|
| 180 | /**
|
| 181 | * Handles updating while being ridden by an entity
|
| 182 | */
|
| 183 | public void updateRidden()
|
| 184 | {
|
| 185 | super.updateRidden();
|
| 186 |
|
| 187 | if (this.ridingEntity instanceof EntityCreature)
|
| 188 | {
|
| 189 | EntityCreature entitycreature = (EntityCreature)this.ridingEntity;
|
| 190 | this.renderYawOffset = entitycreature.renderYawOffset;
|
| 191 | }
|
| 192 | }
|
| 193 |
|
| 194 | /**
|
| 195 | * Called when the mob's health reaches 0.
|
| 196 | */
|
| 197 | public void onDeath(DamageSource cause)
|
| 198 | {
|
| 199 | super.onDeath(cause);
|
| 200 |
|
| 201 | if (cause.getSourceOfDamage() instanceof EntityArrow && cause.getEntity() instanceof EntityPlayer)
|
| 202 | {
|
| 203 | EntityPlayer entityplayer = (EntityPlayer)cause.getEntity();
|
| 204 | double d0 = entityplayer.posX - this.posX;
|
| 205 | double d1 = entityplayer.posZ - this.posZ;
|
| 206 |
|
| 207 | if (d0 * d0 + d1 * d1 >= 2500.0D)
|
| 208 | {
|
| 209 | entityplayer.triggerAchievement(AchievementList.snipeSkeleton);
|
| 210 | }
|
| 211 | }
|
| 212 | else if (cause.getEntity() instanceof EntityCreeper && ((EntityCreeper)cause.getEntity()).getPowered() && ((EntityCreeper)cause.getEntity()).isAIEnabled())
|
| 213 | {
|
| 214 | ((EntityCreeper)cause.getEntity()).func_175493_co();
|
| 215 | this.entityDropItem(new ItemStack(Items.skull, 1, this.getSkeletonType() == 1 ? 1 : 0), 0.0F);
|
| 216 | }
|
| 217 | }
|
| 218 |
|
| 219 | protected Item getDropItem()
|
| 220 | {
|
| 221 | return Items.arrow;
|
| 222 | }
|
| 223 |
|
| 224 | /**
|
| 225 | * Drop 0-2 items of this living's type
|
| 226 | *
|
| 227 | * @param wasRecentlyHit true if this this entity was recently hit by appropriate entity (generally only if player
|
| 228 | * or tameable)
|
| 229 | * @param lootingModifier level of enchanment to be applied to this drop
|
| 230 | */
|
| 231 | protected void dropFewItems(boolean wasRecentlyHit, int lootingModifier)
|
| 232 | {
|
| 233 | if (this.getSkeletonType() == 1)
|
| 234 | {
|
| 235 | int i = this.rand.nextInt(3 + lootingModifier) - 1;
|
| 236 |
|
| 237 | for (int j = 0; j < i; ++j)
|
| 238 | {
|
| 239 | this.dropItem(Items.coal, 1);
|
| 240 | }
|
| 241 | }
|
| 242 | else
|
| 243 | {
|
| 244 | int k = this.rand.nextInt(3 + lootingModifier);
|
| 245 |
|
| 246 | for (int i1 = 0; i1 < k; ++i1)
|
| 247 | {
|
| 248 | this.dropItem(Items.arrow, 1);
|
| 249 | }
|
| 250 | }
|
| 251 |
|
| 252 | int l = this.rand.nextInt(3 + lootingModifier);
|
| 253 |
|
| 254 | for (int j1 = 0; j1 < l; ++j1)
|
| 255 | {
|
| 256 | this.dropItem(Items.bone, 1);
|
| 257 | }
|
| 258 | }
|
| 259 |
|
| 260 | /**
|
| 261 | * Causes this Entity to drop a random item.
|
| 262 | */
|
| 263 | protected void addRandomDrop()
|
| 264 | {
|
| 265 | if (this.getSkeletonType() == 1)
|
| 266 | {
|
| 267 | this.entityDropItem(new ItemStack(Items.skull, 1, 1), 0.0F);
|
| 268 | }
|
| 269 | }
|
| 270 |
|
| 271 | /**
|
| 272 | * Gives armor or weapon for entity based on given DifficultyInstance
|
| 273 | */
|
| 274 | protected void setEquipmentBasedOnDifficulty(DifficultyInstance difficulty)
|
| 275 | {
|
| 276 | super.setEquipmentBasedOnDifficulty(difficulty);
|
| 277 | this.setCurrentItemOrArmor(0, new ItemStack(Items.bow));
|
| 278 | }
|
| 279 |
|
| 280 | /**
|
| 281 | * Called only once on an entity when first time spawned, via egg, mob spawner, natural spawning etc, but not called
|
| 282 | * when entity is reloaded from nbt. Mainly used for initializing attributes and inventory
|
| 283 | */
|
| 284 | public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata)
|
| 285 | {
|
| 286 | livingdata = super.onInitialSpawn(difficulty, livingdata);
|
| 287 |
|
| 288 | if (this.worldObj.provider instanceof WorldProviderHell && this.getRNG().nextInt(5) > 0)
|
| 289 | {
|
| 290 | this.tasks.addTask(4, this.aiAttackOnCollide);
|
| 291 | this.setSkeletonType(1);
|
| 292 | this.setCurrentItemOrArmor(0, new ItemStack(Items.stone_sword));
|
| 293 | this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(4.0D);
|
| 294 | }
|
| 295 | else
|
| 296 | {
|
| 297 | this.tasks.addTask(4, this.aiArrowAttack);
|
| 298 | this.setEquipmentBasedOnDifficulty(difficulty);
|
| 299 | this.setEnchantmentBasedOnDifficulty(difficulty);
|
| 300 | }
|
| 301 |
|
| 302 | this.setCanPickUpLoot(this.rand.nextFloat() < 0.55F * difficulty.getClampedAdditionalDifficulty());
|
| 303 |
|
| 304 | if (this.getEquipmentInSlot(4) == null)
|
| 305 | {
|
| 306 | Calendar calendar = this.worldObj.getCurrentDate();
|
| 307 |
|
| 308 | if (calendar.get(2) + 1 == 10 && calendar.get(5) == 31 && this.rand.nextFloat() < 0.25F)
|
| 309 | {
|
| 310 | this.setCurrentItemOrArmor(4, new ItemStack(this.rand.nextFloat() < 0.1F ? Blocks.lit_pumpkin : Blocks.pumpkin));
|
| 311 | this.equipmentDropChances[4] = 0.0F;
|
| 312 | }
|
| 313 | }
|
| 314 |
|
| 315 | return livingdata;
|
| 316 | }
|
| 317 |
|
| 318 | /**
|
| 319 | * sets this entity's combat AI.
|
| 320 | */
|
| 321 | public void setCombatTask()
|
| 322 | {
|
| 323 | this.tasks.removeTask(this.aiAttackOnCollide);
|
| 324 | this.tasks.removeTask(this.aiArrowAttack);
|
| 325 | ItemStack itemstack = this.getHeldItem();
|
| 326 |
|
| 327 | if (itemstack != null && itemstack.getItem() == Items.bow)
|
| 328 | {
|
| 329 | this.tasks.addTask(4, this.aiArrowAttack);
|
| 330 | }
|
| 331 | else
|
| 332 | {
|
| 333 | this.tasks.addTask(4, this.aiAttackOnCollide);
|
| 334 | }
|
| 335 | }
|
| 336 |
|
| 337 | /**
|
| 338 | * Attack the specified entity using a ranged attack.
|
| 339 | */
|
| 340 | public void attackEntityWithRangedAttack(EntityLivingBase target, float p_82196_2_)
|
| 341 | {
|
| 342 | EntityArrow entityarrow = new EntityArrow(this.worldObj, this, target, 1.6F, (float)(14 - this.worldObj.getDifficulty().getDifficultyId() * 4));
|
| 343 | int i = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, this.getHeldItem());
|
| 344 | int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, this.getHeldItem());
|
| 345 | entityarrow.setDamage((double)(p_82196_2_ * 2.0F) + this.rand.nextGaussian() * 0.25D + (double)((float)this.worldObj.getDifficulty().getDifficultyId() * 0.11F));
|
| 346 |
|
| 347 | if (i > 0)
|
| 348 | {
|
| 349 | entityarrow.setDamage(entityarrow.getDamage() + (double)i * 0.5D + 0.5D);
|
| 350 | }
|
| 351 |
|
| 352 | if (j > 0)
|
| 353 | {
|
| 354 | entityarrow.setKnockbackStrength(j);
|
| 355 | }
|
| 356 |
|
| 357 | if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, this.getHeldItem()) > 0 || this.getSkeletonType() == 1)
|
| 358 | {
|
| 359 | entityarrow.setFire(100);
|
| 360 | }
|
| 361 |
|
| 362 | this.playSound("random.bow", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
|
| 363 | this.worldObj.spawnEntityInWorld(entityarrow);
|
| 364 | }
|
| 365 |
|
| 366 | /**
|
| 367 | * Return this skeleton's type.
|
| 368 | */
|
| 369 | public int getSkeletonType()
|
| 370 | {
|
| 371 | return this.dataWatcher.getWatchableObjectByte(13);
|
| 372 | }
|
| 373 |
|
| 374 | /**
|
| 375 | * Set this skeleton's type.
|
| 376 | */
|
| 377 | public void setSkeletonType(int p_82201_1_)
|
| 378 | {
|
| 379 | this.dataWatcher.updateObject(13, Byte.valueOf((byte)p_82201_1_));
|
| 380 | this.isImmuneToFire = p_82201_1_ == 1;
|
| 381 |
|
| 382 | if (p_82201_1_ == 1)
|
| 383 | {
|
| 384 | this.setSize(0.72F, 2.535F);
|
| 385 | }
|
| 386 | else
|
| 387 | {
|
| 388 | this.setSize(0.6F, 1.95F);
|
| 389 | }
|
| 390 | }
|
| 391 |
|
| 392 | /**
|
| 393 | * (abstract) Protected helper method to read subclass entity data from NBT.
|
| 394 | */
|
| 395 | public void readEntityFromNBT(NBTTagCompound tagCompund)
|
| 396 | {
|
| 397 | super.readEntityFromNBT(tagCompund);
|
| 398 |
|
| 399 | if (tagCompund.hasKey("SkeletonType", 99))
|
| 400 | {
|
| 401 | int i = tagCompund.getByte("SkeletonType");
|
| 402 | this.setSkeletonType(i);
|
| 403 | }
|
| 404 |
|
| 405 | this.setCombatTask();
|
| 406 | }
|
| 407 |
|
| 408 | /**
|
| 409 | * (abstract) Protected helper method to write subclass entity data to NBT.
|
| 410 | */
|
| 411 | public void writeEntityToNBT(NBTTagCompound tagCompound)
|
| 412 | {
|
| 413 | super.writeEntityToNBT(tagCompound);
|
| 414 | tagCompound.setByte("SkeletonType", (byte)this.getSkeletonType());
|
| 415 | }
|
| 416 |
|
| 417 | /**
|
| 418 | * Sets the held item, or an armor slot. Slot 0 is held item. Slot 1-4 is armor. Params: Item, slot
|
| 419 | */
|
| 420 | public void setCurrentItemOrArmor(int slotIn, ItemStack stack)
|
| 421 | {
|
| 422 | super.setCurrentItemOrArmor(slotIn, stack);
|
| 423 |
|
| 424 | if (!this.worldObj.isRemote && slotIn == 0)
|
| 425 | {
|
| 426 | this.setCombatTask();
|
| 427 | }
|
| 428 | }
|
| 429 |
|
| 430 | public float getEyeHeight()
|
| 431 | {
|
| 432 | return this.getSkeletonType() == 1 ? super.getEyeHeight() : 1.74F;
|
| 433 | }
|
| 434 |
|
| 435 | /**
|
| 436 | * Returns the Y Offset of this entity.
|
| 437 | */
|
| 438 | public double getYOffset()
|
| 439 | {
|
| 440 | return this.isChild() ? 0.0D : -0.35D;
|
| 441 | }
|
| 442 | }
|
| 443 |
|