reddvilzz

Untitled

May 9th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.04 KB | None | 0 0
  1. package net.minecraft.entity.monster;
  2.  
  3. import cpw.mods.fml.relauncher.Side;
  4. import cpw.mods.fml.relauncher.SideOnly;
  5. import java.util.Calendar;
  6. import java.util.List;
  7. import java.util.UUID;
  8. import net.minecraft.block.Block;
  9. import net.minecraft.command.IEntitySelector;
  10. import net.minecraft.entity.Entity;
  11. import net.minecraft.entity.EntityLiving;
  12. import net.minecraft.entity.EntityLivingBase;
  13. import net.minecraft.entity.EnumCreatureAttribute;
  14. import net.minecraft.entity.IEntityLivingData;
  15. import net.minecraft.entity.SharedMonsterAttributes;
  16. import net.minecraft.entity.ai.EntityAIAttackOnCollide;
  17. import net.minecraft.entity.ai.EntityAIBreakDoor;
  18. import net.minecraft.entity.ai.EntityAIHurtByTarget;
  19. import net.minecraft.entity.ai.EntityAILookIdle;
  20. import net.minecraft.entity.ai.EntityAIMoveThroughVillage;
  21. import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction;
  22. import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
  23. import net.minecraft.entity.ai.EntityAISwimming;
  24. import net.minecraft.entity.ai.EntityAIWander;
  25. import net.minecraft.entity.ai.EntityAIWatchClosest;
  26. import net.minecraft.entity.ai.attributes.AttributeModifier;
  27. import net.minecraft.entity.ai.attributes.IAttribute;
  28. import net.minecraft.entity.ai.attributes.IAttributeInstance;
  29. import net.minecraft.entity.ai.attributes.RangedAttribute;
  30. import net.minecraft.entity.passive.EntityChicken;
  31. import net.minecraft.entity.passive.EntityVillager;
  32. import net.minecraft.entity.player.EntityPlayer;
  33. import net.minecraft.init.Blocks;
  34. import net.minecraft.init.Items;
  35. import net.minecraft.item.Item;
  36. import net.minecraft.item.ItemStack;
  37. import net.minecraft.nbt.NBTTagCompound;
  38. import net.minecraft.potion.Potion;
  39. import net.minecraft.potion.PotionEffect;
  40. import net.minecraft.util.DamageSource;
  41. import net.minecraft.util.MathHelper;
  42. import net.minecraft.world.EnumDifficulty;
  43. import net.minecraft.world.World;
  44. import net.minecraftforge.common.ForgeModContainer;
  45. import cpw.mods.fml.common.eventhandler.Event.Result;
  46. import net.minecraftforge.event.ForgeEventFactory;
  47. import net.minecraftforge.event.entity.living.ZombieEvent.SummonAidEvent;
  48.  
  49. public class EntityZombie extends EntityMob
  50. {
  51. protected static final IAttribute field_110186_bp = (new RangedAttribute("zombie.spawnReinforcements", 0.0D, 0.0D, 1.0D)).setDescription("Spawn Reinforcements Chance");
  52. private static final UUID babySpeedBoostUUID = UUID.fromString("B9766B59-9566-4402-BC1F-2EE2A276D836");
  53. private static final AttributeModifier babySpeedBoostModifier = new AttributeModifier(babySpeedBoostUUID, "Baby speed boost", 0.5D, 1);
  54. private final EntityAIBreakDoor field_146075_bs = new EntityAIBreakDoor(this);
  55. /** Ticker used to determine the time remaining for this zombie to convert into a villager when cured. */
  56. private int conversionTime;
  57. private boolean field_146076_bu = false;
  58. private float field_146074_bv = -1.0F;
  59. private float field_146073_bw;
  60. private static final String __OBFID = "CL_00001702";
  61.  
  62. public EntityZombie(World p_i1745_1_)
  63. {
  64. super(p_i1745_1_);
  65. this.getNavigator().setBreakDoors(true);
  66. this.tasks.addTask(0, new EntityAISwimming(this));
  67. this.tasks.addTask(2, new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.0D, false));
  68. this.tasks.addTask(4, new EntityAIAttackOnCollide(this, EntityVillager.class, 1.0D, true));
  69. this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 1.0D));
  70. this.tasks.addTask(6, new EntityAIMoveThroughVillage(this, 1.0D, false));
  71. this.tasks.addTask(7, new EntityAIWander(this, 1.0D));
  72. this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
  73. this.tasks.addTask(8, new EntityAILookIdle(this));
  74. this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true));
  75. this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true));
  76. this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityVillager.class, 0, false));
  77. this.setSize(0.6F, 1.8F);
  78. }
  79.  
  80. protected void applyEntityAttributes()
  81. {
  82. super.applyEntityAttributes();
  83. this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(40.0D);
  84. this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.23000000417232513D);
  85. this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(3.0D);
  86. this.getAttributeMap().registerAttribute(field_110186_bp).setBaseValue(this.rand.nextDouble() * ForgeModContainer.zombieSummonBaseChance);
  87. }
  88.  
  89. protected void entityInit()
  90. {
  91. super.entityInit();
  92. this.getDataWatcher().addObject(12, Byte.valueOf((byte)0));
  93. this.getDataWatcher().addObject(13, Byte.valueOf((byte)0));
  94. this.getDataWatcher().addObject(14, Byte.valueOf((byte)0));
  95. }
  96.  
  97. /**
  98. * Returns the current armor value as determined by a call to InventoryPlayer.getTotalArmorValue
  99. */
  100. public int getTotalArmorValue()
  101. {
  102. int i = super.getTotalArmorValue() + 2;
  103.  
  104. if (i > 20)
  105. {
  106. i = 20;
  107. }
  108.  
  109. return i;
  110. }
  111.  
  112. /**
  113. * Returns true if the newer Entity AI code should be run
  114. */
  115. protected boolean isAIEnabled()
  116. {
  117. return true;
  118. }
  119.  
  120. public boolean func_146072_bX()
  121. {
  122. return this.field_146076_bu;
  123. }
  124.  
  125. public void func_146070_a(boolean p_146070_1_)
  126. {
  127. if (this.field_146076_bu != p_146070_1_)
  128. {
  129. this.field_146076_bu = p_146070_1_;
  130.  
  131. if (p_146070_1_)
  132. {
  133. this.tasks.addTask(1, this.field_146075_bs);
  134. }
  135. else
  136. {
  137. this.tasks.removeTask(this.field_146075_bs);
  138. }
  139. }
  140. }
  141.  
  142. /**
  143. * If Animal, checks if the age timer is negative
  144. */
  145. public boolean isChild()
  146. {
  147. return this.getDataWatcher().getWatchableObjectByte(12) == 1;
  148. }
  149.  
  150. /**
  151. * Get the experience points the entity currently has.
  152. */
  153. protected int getExperiencePoints(EntityPlayer p_70693_1_)
  154. {
  155. if (this.isChild())
  156. {
  157. this.experienceValue = (int)((float)this.experienceValue * 2.5F);
  158. }
  159.  
  160. return super.getExperiencePoints(p_70693_1_);
  161. }
  162.  
  163. /**
  164. * Set whether this zombie is a child.
  165. */
  166. public void setChild(boolean p_82227_1_)
  167. {
  168. this.getDataWatcher().updateObject(12, Byte.valueOf((byte)(p_82227_1_ ? 1 : 0)));
  169.  
  170. if (this.worldObj != null && !this.worldObj.isRemote)
  171. {
  172. IAttributeInstance iattributeinstance = this.getEntityAttribute(SharedMonsterAttributes.movementSpeed);
  173. iattributeinstance.removeModifier(babySpeedBoostModifier);
  174.  
  175. if (p_82227_1_)
  176. {
  177. iattributeinstance.applyModifier(babySpeedBoostModifier);
  178. }
  179. }
  180.  
  181. this.func_146071_k(p_82227_1_);
  182. }
  183.  
  184. /**
  185. * Return whether this zombie is a villager.
  186. */
  187. public boolean isVillager()
  188. {
  189. return this.getDataWatcher().getWatchableObjectByte(13) == 1;
  190. }
  191.  
  192. /**
  193. * Set whether this zombie is a villager.
  194. */
  195. public void setVillager(boolean p_82229_1_)
  196. {
  197. this.getDataWatcher().updateObject(13, Byte.valueOf((byte)(p_82229_1_ ? 1 : 0)));
  198. }
  199.  
  200. /**
  201. * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
  202. * use this to react to sunlight and start to burn.
  203. */
  204. public void onLivingUpdate()
  205. {
  206. if (this.worldObj.isDaytime() && !this.worldObj.isRemote && !this.isChild())
  207. {
  208. float f = this.getBrightness(1.0F);
  209.  
  210. if (f > 0.5F && this.rand.nextFloat() * 30.0F < (f - 0.4F) * 2.0F && this.worldObj.canBlockSeeTheSky(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY), MathHelper.floor_double(this.posZ)))
  211. {
  212. boolean flag = true;
  213. ItemStack itemstack = this.getEquipmentInSlot(4);
  214.  
  215. if (itemstack != null)
  216. {
  217. if (itemstack.isItemStackDamageable())
  218. {
  219. itemstack.setItemDamage(itemstack.getItemDamageForDisplay() + this.rand.nextInt(2));
  220.  
  221. if (itemstack.getItemDamageForDisplay() >= itemstack.getMaxDamage())
  222. {
  223. this.renderBrokenItemStack(itemstack);
  224. this.setCurrentItemOrArmor(4, (ItemStack)null);
  225. }
  226. }
  227.  
  228. flag = false;
  229. }
  230.  
  231. if (flag)
  232. {
  233. this.setFire(8);
  234. }
  235. }
  236. }
  237.  
  238. if (this.isRiding() && this.getAttackTarget() != null && this.ridingEntity instanceof EntityChicken)
  239. {
  240. ((EntityLiving)this.ridingEntity).getNavigator().setPath(this.getNavigator().getPath(), 1.5D);
  241. }
  242.  
  243. super.onLivingUpdate();
  244. }
  245.  
  246. /**
  247. * Called when the entity is attacked.
  248. */
  249. public boolean attackEntityFrom(DamageSource p_70097_1_, float p_70097_2_)
  250. {
  251. if (!super.attackEntityFrom(p_70097_1_, p_70097_2_))
  252. {
  253. return false;
  254. }
  255. else
  256. {
  257. EntityLivingBase entitylivingbase = this.getAttackTarget();
  258.  
  259. if (entitylivingbase == null && this.getEntityToAttack() instanceof EntityLivingBase)
  260. {
  261. entitylivingbase = (EntityLivingBase)this.getEntityToAttack();
  262. }
  263.  
  264. if (entitylivingbase == null && p_70097_1_.getEntity() instanceof EntityLivingBase)
  265. {
  266. entitylivingbase = (EntityLivingBase)p_70097_1_.getEntity();
  267. }
  268.  
  269.  
  270. int i = MathHelper.floor_double(this.posX);
  271. int j = MathHelper.floor_double(this.posY);
  272. int k = MathHelper.floor_double(this.posZ);
  273.  
  274. SummonAidEvent summonAid = ForgeEventFactory.fireZombieSummonAid(this, worldObj, i, j, k, entitylivingbase, this.getEntityAttribute(field_110186_bp).getAttributeValue());
  275.  
  276. if (summonAid.getResult() == Result.DENY)
  277. {
  278. return true;
  279. }
  280. else if (summonAid.getResult() == Result.ALLOW || entitylivingbase != null && this.worldObj.difficultySetting == EnumDifficulty.HARD && (double)this.rand.nextFloat() < this.getEntityAttribute(field_110186_bp).getAttributeValue())
  281. {
  282. EntityZombie entityzombie;
  283. if (summonAid.customSummonedAid != null && summonAid.getResult() == Result.ALLOW)
  284. {
  285. entityzombie = summonAid.customSummonedAid;
  286. }
  287. else
  288. {
  289. entityzombie = new EntityZombie(this.worldObj);
  290. }
  291.  
  292. for (int l = 0; l < 50; ++l)
  293. {
  294. int i1 = i + MathHelper.getRandomIntegerInRange(this.rand, 7, 40) * MathHelper.getRandomIntegerInRange(this.rand, -1, 1);
  295. int j1 = j + MathHelper.getRandomIntegerInRange(this.rand, 7, 40) * MathHelper.getRandomIntegerInRange(this.rand, -1, 1);
  296. int k1 = k + MathHelper.getRandomIntegerInRange(this.rand, 7, 40) * MathHelper.getRandomIntegerInRange(this.rand, -1, 1);
  297.  
  298. if (World.doesBlockHaveSolidTopSurface(this.worldObj, i1, j1 - 1, k1) && this.worldObj.getBlockLightValue(i1, j1, k1) < 10)
  299. {
  300. entityzombie.setPosition((double)i1, (double)j1, (double)k1);
  301.  
  302. if (this.worldObj.checkNoEntityCollision(entityzombie.boundingBox) && this.worldObj.getCollidingBoundingBoxes(entityzombie, entityzombie.boundingBox).isEmpty() && !this.worldObj.isAnyLiquid(entityzombie.boundingBox))
  303. {
  304. this.worldObj.spawnEntityInWorld(entityzombie);
  305. if (entitylivingbase != null) entityzombie.setAttackTarget(entitylivingbase);
  306. entityzombie.onSpawnWithEgg((IEntityLivingData)null);
  307. this.getEntityAttribute(field_110186_bp).applyModifier(new AttributeModifier("Zombie reinforcement caller charge", -0.05000000074505806D, 0));
  308. entityzombie.getEntityAttribute(field_110186_bp).applyModifier(new AttributeModifier("Zombie reinforcement callee charge", -0.05000000074505806D, 0));
  309. break;
  310. }
  311. }
  312. }
  313. }
  314.  
  315. return true;
  316. }
  317. }
  318.  
  319. /**
  320. * Called to update the entity's position/logic.
  321. */
  322. public void onUpdate()
  323. {
  324. if (!this.worldObj.isRemote && this.isConverting())
  325. {
  326. int i = this.getConversionTimeBoost();
  327. this.conversionTime -= i;
  328.  
  329. if (this.conversionTime <= 0)
  330. {
  331. this.convertToVillager();
  332. }
  333. }
  334.  
  335. super.onUpdate();
  336. }
  337.  
  338. public boolean attackEntityAsMob(Entity p_70652_1_)
  339. {
  340. boolean flag = super.attackEntityAsMob(p_70652_1_);
  341.  
  342. if (flag)
  343. {
  344. int i = this.worldObj.difficultySetting.getDifficultyId();
  345.  
  346. if (this.getHeldItem() == null && this.isBurning() && this.rand.nextFloat() < (float)i * 0.3F)
  347. {
  348. p_70652_1_.setFire(2 * i);
  349. }
  350. }
  351.  
  352. return flag;
  353. }
  354.  
  355. /**
  356. * Returns the sound this mob makes while it's alive.
  357. */
  358. protected String getLivingSound()
  359. {
  360. return "mob.zombie.say";
  361. }
  362.  
  363. /**
  364. * Returns the sound this mob makes when it is hurt.
  365. */
  366. protected String getHurtSound()
  367. {
  368. return "mob.zombie.hurt";
  369. }
  370.  
  371. /**
  372. * Returns the sound this mob makes on death.
  373. */
  374. protected String getDeathSound()
  375. {
  376. return "mob.zombie.death";
  377. }
  378.  
  379. protected void func_145780_a(int p_145780_1_, int p_145780_2_, int p_145780_3_, Block p_145780_4_)
  380. {
  381. this.playSound("mob.zombie.step", 0.15F, 1.0F);
  382. }
  383.  
  384. protected Item getDropItem()
  385. {
  386. return Items.rotten_flesh;
  387. }
  388.  
  389. /**
  390. * Get this Entity's EnumCreatureAttribute
  391. */
  392. public EnumCreatureAttribute getCreatureAttribute()
  393. {
  394. return EnumCreatureAttribute.UNDEAD;
  395. }
  396.  
  397. protected void dropRareDrop(int p_70600_1_)
  398. {
  399. switch (this.rand.nextInt(3))
  400. {
  401. case 0:
  402. this.dropItem(Items.iron_ingot, 1);
  403. break;
  404. case 1:
  405. this.dropItem(Items.carrot, 1);
  406. break;
  407. case 2:
  408. this.dropItem(Items.potato, 1);
  409. }
  410. }
  411.  
  412. /**
  413. * Makes entity wear random armor based on difficulty
  414. */
  415. protected void addRandomArmor()
  416. {
  417. super.addRandomArmor();
  418.  
  419. if (this.rand.nextFloat() < (this.worldObj.difficultySetting == EnumDifficulty.HARD ? 0.05F : 0.01F))
  420. {
  421. int i = this.rand.nextInt(3);
  422.  
  423. if (i == 0)
  424. {
  425. this.setCurrentItemOrArmor(0, new ItemStack(Items.iron_sword));
  426. }
  427. else
  428. {
  429. this.setCurrentItemOrArmor(0, new ItemStack(Items.iron_shovel));
  430. }
  431. }
  432. }
  433.  
  434. /**
  435. * (abstract) Protected helper method to write subclass entity data to NBT.
  436. */
  437. public void writeEntityToNBT(NBTTagCompound p_70014_1_)
  438. {
  439. super.writeEntityToNBT(p_70014_1_);
  440.  
  441. if (this.isChild())
  442. {
  443. p_70014_1_.setBoolean("IsBaby", true);
  444. }
  445.  
  446. if (this.isVillager())
  447. {
  448. p_70014_1_.setBoolean("IsVillager", true);
  449. }
  450.  
  451. p_70014_1_.setInteger("ConversionTime", this.isConverting() ? this.conversionTime : -1);
  452. p_70014_1_.setBoolean("CanBreakDoors", this.func_146072_bX());
  453. }
  454.  
  455. /**
  456. * (abstract) Protected helper method to read subclass entity data from NBT.
  457. */
  458. public void readEntityFromNBT(NBTTagCompound p_70037_1_)
  459. {
  460. super.readEntityFromNBT(p_70037_1_);
  461.  
  462. if (p_70037_1_.getBoolean("IsBaby"))
  463. {
  464. this.setChild(true);
  465. }
  466.  
  467. if (p_70037_1_.getBoolean("IsVillager"))
  468. {
  469. this.setVillager(true);
  470. }
  471.  
  472. if (p_70037_1_.hasKey("ConversionTime", 99) && p_70037_1_.getInteger("ConversionTime") > -1)
  473. {
  474. this.startConversion(p_70037_1_.getInteger("ConversionTime"));
  475. }
  476.  
  477. this.func_146070_a(p_70037_1_.getBoolean("CanBreakDoors"));
  478. }
  479.  
  480. /**
  481. * This method gets called when the entity kills another one.
  482. */
  483. public void onKillEntity(EntityLivingBase p_70074_1_)
  484. {
  485. super.onKillEntity(p_70074_1_);
  486.  
  487. if ((this.worldObj.difficultySetting == EnumDifficulty.NORMAL || this.worldObj.difficultySetting == EnumDifficulty.HARD) && p_70074_1_ instanceof EntityVillager)
  488. {
  489. if (this.worldObj.difficultySetting != EnumDifficulty.HARD && this.rand.nextBoolean())
  490. {
  491. return;
  492. }
  493.  
  494. EntityZombie entityzombie = new EntityZombie(this.worldObj);
  495. entityzombie.copyLocationAndAnglesFrom(p_70074_1_);
  496. this.worldObj.removeEntity(p_70074_1_);
  497. entityzombie.onSpawnWithEgg((IEntityLivingData)null);
  498. entityzombie.setVillager(true);
  499.  
  500. if (p_70074_1_.isChild())
  501. {
  502. entityzombie.setChild(true);
  503. }
  504.  
  505. this.worldObj.spawnEntityInWorld(entityzombie);
  506. this.worldObj.playAuxSFXAtEntity((EntityPlayer)null, 1016, (int)this.posX, (int)this.posY, (int)this.posZ, 0);
  507. }
  508. }
  509.  
  510. public IEntityLivingData onSpawnWithEgg(IEntityLivingData p_110161_1_)
  511. {
  512. Object p_110161_1_1 = super.onSpawnWithEgg(p_110161_1_);
  513. float f = this.worldObj.func_147462_b(this.posX, this.posY, this.posZ);
  514. this.setCanPickUpLoot(this.rand.nextFloat() < 0.55F * f);
  515.  
  516. if (p_110161_1_1 == null)
  517. {
  518. p_110161_1_1 = new EntityZombie.GroupData(this.worldObj.rand.nextFloat() < ForgeModContainer.zombieBabyChance, this.worldObj.rand.nextFloat() < 0.05F, null);
  519. }
  520.  
  521. if (p_110161_1_1 instanceof EntityZombie.GroupData)
  522. {
  523. EntityZombie.GroupData groupdata = (EntityZombie.GroupData)p_110161_1_1;
  524.  
  525. if (groupdata.field_142046_b)
  526. {
  527. this.setVillager(true);
  528. }
  529.  
  530. if (groupdata.field_142048_a)
  531. {
  532. this.setChild(true);
  533.  
  534. if ((double)this.worldObj.rand.nextFloat() < 0.05D)
  535. {
  536. List list = this.worldObj.selectEntitiesWithinAABB(EntityChicken.class, this.boundingBox.expand(5.0D, 3.0D, 5.0D), IEntitySelector.field_152785_b);
  537.  
  538. if (!list.isEmpty())
  539. {
  540. EntityChicken entitychicken = (EntityChicken)list.get(0);
  541. entitychicken.func_152117_i(true);
  542. this.mountEntity(entitychicken);
  543. }
  544. }
  545. else if ((double)this.worldObj.rand.nextFloat() < 0.05D)
  546. {
  547. EntityChicken entitychicken1 = new EntityChicken(this.worldObj);
  548. entitychicken1.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, 0.0F);
  549. entitychicken1.onSpawnWithEgg((IEntityLivingData)null);
  550. entitychicken1.func_152117_i(true);
  551. this.worldObj.spawnEntityInWorld(entitychicken1);
  552. this.mountEntity(entitychicken1);
  553. }
  554. }
  555. }
  556.  
  557. this.func_146070_a(this.rand.nextFloat() < f * 0.1F);
  558. this.addRandomArmor();
  559. this.enchantEquipment();
  560.  
  561. if (this.getEquipmentInSlot(4) == null)
  562. {
  563. Calendar calendar = this.worldObj.getCurrentDate();
  564.  
  565. if (calendar.get(2) + 1 == 10 && calendar.get(5) == 31 && this.rand.nextFloat() < 0.25F)
  566. {
  567. this.setCurrentItemOrArmor(4, new ItemStack(this.rand.nextFloat() < 0.1F ? Blocks.lit_pumpkin : Blocks.pumpkin));
  568. this.equipmentDropChances[4] = 0.0F;
  569. }
  570. }
  571.  
  572. this.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).applyModifier(new AttributeModifier("Random spawn bonus", this.rand.nextDouble() * 0.05000000074505806D, 0));
  573. double d0 = this.rand.nextDouble() * 1.5D * (double)this.worldObj.func_147462_b(this.posX, this.posY, this.posZ);
  574.  
  575. if (d0 > 1.0D)
  576. {
  577. this.getEntityAttribute(SharedMonsterAttributes.followRange).applyModifier(new AttributeModifier("Random zombie-spawn bonus", d0, 2));
  578. }
  579.  
  580. if (this.rand.nextFloat() < f * 0.05F)
  581. {
  582. this.getEntityAttribute(field_110186_bp).applyModifier(new AttributeModifier("Leader zombie bonus", this.rand.nextDouble() * 0.25D + 0.5D, 0));
  583. this.getEntityAttribute(SharedMonsterAttributes.maxHealth).applyModifier(new AttributeModifier("Leader zombie bonus", this.rand.nextDouble() * 3.0D + 1.0D, 2));
  584. this.func_146070_a(true);
  585. }
  586.  
  587. return (IEntityLivingData)p_110161_1_1;
  588. }
  589.  
  590. /**
  591. * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
  592. */
  593. public boolean interact(EntityPlayer p_70085_1_)
  594. {
  595. ItemStack itemstack = p_70085_1_.getCurrentEquippedItem();
  596.  
  597. if (itemstack != null && itemstack.getItem() == Items.golden_apple && itemstack.getItemDamage() == 0 && this.isVillager() && this.isPotionActive(Potion.weakness))
  598. {
  599. if (!p_70085_1_.capabilities.isCreativeMode)
  600. {
  601. --itemstack.stackSize;
  602. }
  603.  
  604. if (itemstack.stackSize <= 0)
  605. {
  606. p_70085_1_.inventory.setInventorySlotContents(p_70085_1_.inventory.currentItem, (ItemStack)null);
  607. }
  608.  
  609. if (!this.worldObj.isRemote)
  610. {
  611. this.startConversion(this.rand.nextInt(2401) + 3600);
  612. }
  613.  
  614. return true;
  615. }
  616. else
  617. {
  618. return false;
  619. }
  620. }
  621.  
  622. /**
  623. * Starts converting this zombie into a villager. The zombie converts into a villager after the specified time in
  624. * ticks.
  625. */
  626. protected void startConversion(int p_82228_1_)
  627. {
  628. this.conversionTime = p_82228_1_;
  629. this.getDataWatcher().updateObject(14, Byte.valueOf((byte)1));
  630. this.removePotionEffect(Potion.weakness.id);
  631. this.addPotionEffect(new PotionEffect(Potion.damageBoost.id, p_82228_1_, Math.min(this.worldObj.difficultySetting.getDifficultyId() - 1, 0)));
  632. this.worldObj.setEntityState(this, (byte)16);
  633. }
  634.  
  635. @SideOnly(Side.CLIENT)
  636. public void handleHealthUpdate(byte p_70103_1_)
  637. {
  638. if (p_70103_1_ == 16)
  639. {
  640. this.worldObj.playSound(this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D, "mob.zombie.remedy", 1.0F + this.rand.nextFloat(), this.rand.nextFloat() * 0.7F + 0.3F, false);
  641. }
  642. else
  643. {
  644. super.handleHealthUpdate(p_70103_1_);
  645. }
  646. }
  647.  
  648. /**
  649. * Determines if an entity can be despawned, used on idle far away entities
  650. */
  651. protected boolean canDespawn()
  652. {
  653. return !this.isConverting();
  654. }
  655.  
  656. /**
  657. * Returns whether this zombie is in the process of converting to a villager
  658. */
  659. public boolean isConverting()
  660. {
  661. return this.getDataWatcher().getWatchableObjectByte(14) == 1;
  662. }
  663.  
  664. /**
  665. * Convert this zombie into a villager.
  666. */
  667. protected void convertToVillager()
  668. {
  669. EntityVillager entityvillager = new EntityVillager(this.worldObj);
  670. entityvillager.copyLocationAndAnglesFrom(this);
  671. entityvillager.onSpawnWithEgg((IEntityLivingData)null);
  672. entityvillager.setLookingForHome();
  673.  
  674. if (this.isChild())
  675. {
  676. entityvillager.setGrowingAge(-24000);
  677. }
  678.  
  679. this.worldObj.removeEntity(this);
  680. this.worldObj.spawnEntityInWorld(entityvillager);
  681. entityvillager.addPotionEffect(new PotionEffect(Potion.confusion.id, 200, 0));
  682. this.worldObj.playAuxSFXAtEntity((EntityPlayer)null, 1017, (int)this.posX, (int)this.posY, (int)this.posZ, 0);
  683. }
  684.  
  685. /**
  686. * Return the amount of time decremented from conversionTime every tick.
  687. */
  688. protected int getConversionTimeBoost()
  689. {
  690. int i = 1;
  691.  
  692. if (this.rand.nextFloat() < 0.01F)
  693. {
  694. int j = 0;
  695.  
  696. for (int k = (int)this.posX - 4; k < (int)this.posX + 4 && j < 14; ++k)
  697. {
  698. for (int l = (int)this.posY - 4; l < (int)this.posY + 4 && j < 14; ++l)
  699. {
  700. for (int i1 = (int)this.posZ - 4; i1 < (int)this.posZ + 4 && j < 14; ++i1)
  701. {
  702. Block block = this.worldObj.getBlock(k, l, i1);
  703.  
  704. if (block == Blocks.iron_bars || block == Blocks.bed)
  705. {
  706. if (this.rand.nextFloat() < 0.3F)
  707. {
  708. ++i;
  709. }
  710.  
  711. ++j;
  712. }
  713. }
  714. }
  715. }
  716. }
  717.  
  718. return i;
  719. }
  720.  
  721. public void func_146071_k(boolean p_146071_1_)
  722. {
  723. this.func_146069_a(p_146071_1_ ? 0.5F : 1.0F);
  724. }
  725.  
  726. /**
  727. * Sets the width and height of the entity. Args: width, height
  728. */
  729. protected final void setSize(float p_70105_1_, float p_70105_2_)
  730. {
  731. boolean flag = this.field_146074_bv > 0.0F && this.field_146073_bw > 0.0F;
  732. this.field_146074_bv = p_70105_1_;
  733. this.field_146073_bw = p_70105_2_;
  734.  
  735. if (!flag)
  736. {
  737. this.func_146069_a(1.0F);
  738. }
  739. }
  740.  
  741. protected final void func_146069_a(float p_146069_1_)
  742. {
  743. super.setSize(this.field_146074_bv * p_146069_1_, this.field_146073_bw * p_146069_1_);
  744. }
  745.  
  746. class GroupData implements IEntityLivingData
  747. {
  748. public boolean field_142048_a;
  749. public boolean field_142046_b;
  750. private static final String __OBFID = "CL_00001704";
  751.  
  752. private GroupData(boolean p_i2348_2_, boolean p_i2348_3_)
  753. {
  754. this.field_142048_a = false;
  755. this.field_142046_b = false;
  756. this.field_142048_a = p_i2348_2_;
  757. this.field_142046_b = p_i2348_3_;
  758. }
  759.  
  760. GroupData(boolean p_i2349_2_, boolean p_i2349_3_, Object p_i2349_4_)
  761. {
  762. this(p_i2349_2_, p_i2349_3_);
  763. }
  764. }
  765. }
Add Comment
Please, Sign In to add comment