Advertisement
Guest User

Untitled

a guest
May 24th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 59.50 KB | None | 0 0
  1. package net.minecraft.server;
  2.  
  3. import java.util.Collection;
  4. import java.util.HashMap;
  5. import java.util.Iterator;
  6. import java.util.List;
  7. import java.util.Random;
  8. import java.util.UUID;
  9.  
  10. // CraftBukkit start
  11. import java.util.ArrayList;
  12. import com.google.common.base.Function;
  13. import org.bukkit.craftbukkit.event.CraftEventFactory;
  14. import org.bukkit.event.entity.EntityDamageEvent;
  15. import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
  16. import org.bukkit.event.entity.EntityRegainHealthEvent;
  17. // CraftBukkit end
  18.  
  19. import org.bukkit.craftbukkit.SpigotTimings; // Spigot
  20.  
  21. public abstract class EntityLiving extends Entity {
  22.  
  23. private static final UUID b = UUID.fromString("662A6B8D-DA3E-4C1C-8813-96EA6097278D");
  24. private static final AttributeModifier c = (new AttributeModifier(b, "Sprinting speed boost", 0.30000001192092896D, 2)).a(false);
  25. private AttributeMapBase d;
  26. public CombatTracker combatTracker = new CombatTracker(this); // CraftBukkit - private -> public, remove final
  27. public final HashMap effects = new HashMap(); // CraftBukkit - protected -> public
  28. private final ItemStack[] g = new ItemStack[5];
  29. public boolean at;
  30. public int au;
  31. public int av;
  32. public float aw;
  33. public int hurtTicks;
  34. public int ay;
  35. public float az;
  36. public int deathTicks;
  37. public int attackTicks;
  38. public float aC;
  39. public float aD;
  40. public float aE;
  41. public float aF;
  42. public float aG;
  43. public int maxNoDamageTicks = 20;
  44. public float aI;
  45. public float aJ;
  46. public float aK;
  47. public float aL;
  48. public float aM;
  49. public float aN;
  50. public float aO;
  51. public float aP;
  52. public float aQ = 0.02F;
  53. public EntityHuman killer; // CraftBukkit - protected -> public
  54. protected int lastDamageByPlayerTime;
  55. protected boolean aT;
  56. protected int aU;
  57. protected float aV;
  58. protected float aW;
  59. protected float aX;
  60. protected float aY;
  61. protected float aZ;
  62. protected int ba;
  63. public float lastDamage; // CraftBukkit - protected -> public
  64. protected boolean bc;
  65. public float bd;
  66. public float be;
  67. protected float bf;
  68. protected int bg;
  69. protected double bh;
  70. protected double bi;
  71. protected double bj;
  72. protected double bk;
  73. protected double bl;
  74. public boolean updateEffects = true; // CraftBukkit - private -> public
  75. public EntityLiving lastDamager; // CraftBukkit - private -> public
  76. private int bm;
  77. private EntityLiving bn;
  78. private int bo;
  79. private float bp;
  80. private int bq;
  81. private float br;
  82. // CraftBukkit start
  83. public int expToDrop;
  84. public int maxAirTicks = 300;
  85. ArrayList<org.bukkit.inventory.ItemStack> drops = null;
  86. // CraftBukkit end
  87. // Spigot start
  88. public void inactiveTick()
  89. {
  90. super.inactiveTick();
  91. ++this.aU; // Above all the floats
  92. }
  93. // Spigot end
  94.  
  95. public EntityLiving(World world) {
  96. super(world);
  97. this.aD();
  98. // CraftBukkit - setHealth(getMaxHealth()) inlined and simplified to skip the instanceof check for EntityPlayer, as getBukkitEntity() is not initialized in constructor
  99. this.datawatcher.watch(6, (float) this.getAttributeInstance(GenericAttributes.maxHealth).getValue());
  100. this.k = true;
  101. this.aL = (float) (Math.random() + 1.0D) * 0.01F;
  102. this.setPosition(this.locX, this.locY, this.locZ);
  103. this.aK = (float) Math.random() * 12398.0F;
  104. this.yaw = (float) (Math.random() * 3.1415927410125732D * 2.0D);
  105. this.aO = this.yaw;
  106. this.W = 0.5F;
  107. }
  108.  
  109. protected void c() {
  110. this.datawatcher.a(7, Integer.valueOf(0));
  111. this.datawatcher.a(8, Byte.valueOf((byte) 0));
  112. this.datawatcher.a(9, Byte.valueOf((byte) 0));
  113. this.datawatcher.a(6, Float.valueOf(1.0F));
  114. }
  115.  
  116. protected void aD() {
  117. this.getAttributeMap().b(GenericAttributes.maxHealth);
  118. this.getAttributeMap().b(GenericAttributes.c);
  119. this.getAttributeMap().b(GenericAttributes.d);
  120. if (!this.bk()) {
  121. this.getAttributeInstance(GenericAttributes.d).setValue(0.10000000149011612D);
  122. }
  123. }
  124.  
  125. protected void a(double d0, boolean flag) {
  126. if (!this.M()) {
  127. this.N();
  128. }
  129.  
  130. if (flag && this.fallDistance > 0.0F) {
  131. int i = MathHelper.floor(this.locX);
  132. int j = MathHelper.floor(this.locY - 0.20000000298023224D - (double) this.height);
  133. int k = MathHelper.floor(this.locZ);
  134. Block block = this.world.getType(i, j, k);
  135.  
  136. if (block.getMaterial() == Material.AIR) {
  137. int l = this.world.getType(i, j - 1, k).b();
  138.  
  139. if (l == 11 || l == 32 || l == 21) {
  140. block = this.world.getType(i, j - 1, k);
  141. }
  142. } else if (!this.world.isStatic && this.fallDistance > 3.0F) {
  143. // CraftBukkit start - supply player as argument in particles for visibility API to work
  144. if (this instanceof EntityPlayer) {
  145. this.world.a((EntityHuman) this, 2006, i, j, k, MathHelper.f(this.fallDistance - 3.0F));
  146. ((EntityPlayer) this).playerConnection.sendPacket(new PacketPlayOutWorldEvent(2006, i, j, k, MathHelper.f(this.fallDistance - 3.0F), false));
  147. } else {
  148. this.world.triggerEffect(2006, i, j, k, MathHelper.f(this.fallDistance - 3.0F));
  149. }
  150. // CraftBukkit end
  151. }
  152.  
  153. block.a(this.world, i, j, k, this, this.fallDistance);
  154. }
  155.  
  156. super.a(d0, flag);
  157. }
  158.  
  159. public boolean aE() {
  160. return false;
  161. }
  162.  
  163. public void C() {
  164. this.aC = this.aD;
  165. super.C();
  166. this.world.methodProfiler.a("livingEntityBaseTick");
  167. if (this.isAlive() && this.inBlock()) {
  168. this.damageEntity(DamageSource.STUCK, 1.0F);
  169. }
  170.  
  171. if (this.isFireproof() || this.world.isStatic) {
  172. this.extinguish();
  173. }
  174.  
  175. boolean flag = this instanceof EntityHuman && ((EntityHuman) this).abilities.isInvulnerable;
  176.  
  177. if (this.isAlive() && this.a(Material.WATER)) {
  178. if (!this.aE() && !this.hasEffect(MobEffectList.WATER_BREATHING.id) && !flag) {
  179. this.setAirTicks(this.j(this.getAirTicks()));
  180. if (this.getAirTicks() == -20) {
  181. this.setAirTicks(0);
  182.  
  183. for (int i = 0; i < 8; ++i) {
  184. float f = this.random.nextFloat() - this.random.nextFloat();
  185. float f1 = this.random.nextFloat() - this.random.nextFloat();
  186. float f2 = this.random.nextFloat() - this.random.nextFloat();
  187.  
  188. this.world.addParticle("bubble", this.locX + (double) f, this.locY + (double) f1, this.locZ + (double) f2, this.motX, this.motY, this.motZ);
  189. }
  190.  
  191. this.damageEntity(DamageSource.DROWN, 2.0F);
  192. }
  193. }
  194.  
  195. if (!this.world.isStatic && this.am() && this.vehicle instanceof EntityLiving) {
  196. this.mount((Entity) null);
  197. }
  198. } else {
  199. // CraftBukkit start - Only set if needed to work around a DataWatcher inefficiency
  200. if (this.getAirTicks() != 300) {
  201. this.setAirTicks(maxAirTicks);
  202. }
  203. // CraftBukkit end
  204. }
  205.  
  206. if (this.isAlive() && this.L()) {
  207. this.extinguish();
  208. }
  209.  
  210. this.aI = this.aJ;
  211. if (this.attackTicks > 0) {
  212. --this.attackTicks;
  213. }
  214.  
  215. if (this.hurtTicks > 0) {
  216. --this.hurtTicks;
  217. }
  218.  
  219. if (this.noDamageTicks > 0 && !(this instanceof EntityPlayer)) {
  220. --this.noDamageTicks;
  221. }
  222.  
  223. if (this.getHealth() <= 0.0F) {
  224. this.aF();
  225. }
  226.  
  227. if (this.lastDamageByPlayerTime > 0) {
  228. --this.lastDamageByPlayerTime;
  229. } else {
  230. this.killer = null;
  231. }
  232.  
  233. if (this.bn != null && !this.bn.isAlive()) {
  234. this.bn = null;
  235. }
  236.  
  237. if (this.lastDamager != null) {
  238. if (!this.lastDamager.isAlive()) {
  239. this.b((EntityLiving) null);
  240. } else if (this.ticksLived - this.bm > 100) {
  241. this.b((EntityLiving) null);
  242. }
  243. }
  244.  
  245. this.aO();
  246. this.aY = this.aX;
  247. this.aN = this.aM;
  248. this.aP = this.aO;
  249. this.lastYaw = this.yaw;
  250. this.lastPitch = this.pitch;
  251. this.world.methodProfiler.b();
  252. }
  253.  
  254. // CraftBukkit start
  255. public int getExpReward() {
  256. int exp = this.getExpValue(this.killer);
  257.  
  258. if (!this.world.isStatic && (this.lastDamageByPlayerTime > 0 || this.alwaysGivesExp()) && this.aG() && this.world.getGameRules().getBoolean("doMobLoot")) {
  259. return exp;
  260. } else {
  261. return 0;
  262. }
  263. }
  264. // CraftBukkit end
  265.  
  266. public boolean isBaby() {
  267. return false;
  268. }
  269.  
  270. protected void aF() {
  271. ++this.deathTicks;
  272. if (this.deathTicks >= 20 && !this.dead) { // CraftBukkit - (this.deathTicks == 20) -> (this.deathTicks >= 20 && !this.dead)
  273. int i;
  274.  
  275. // CraftBukkit start - Update getExpReward() above if the removed if() changes!
  276. i = this.expToDrop;
  277. while (i > 0) {
  278. int j = EntityExperienceOrb.getOrbValue(i);
  279.  
  280. i -= j;
  281. this.world.addEntity(new EntityExperienceOrb(this.world, this.locX, this.locY, this.locZ, j));
  282. }
  283. this.expToDrop = 0;
  284. // CraftBukkit end
  285.  
  286. this.die();
  287.  
  288. for (i = 0; i < 20; ++i) {
  289. double d0 = this.random.nextGaussian() * 0.02D;
  290. double d1 = this.random.nextGaussian() * 0.02D;
  291. double d2 = this.random.nextGaussian() * 0.02D;
  292.  
  293. this.world.addParticle("explode", this.locX + (double) (this.random.nextFloat() * this.width * 2.0F) - (double) this.width, this.locY + (double) (this.random.nextFloat() * this.length), this.locZ + (double) (this.random.nextFloat() * this.width * 2.0F) - (double) this.width, d0, d1, d2);
  294. }
  295. }
  296. }
  297.  
  298. protected boolean aG() {
  299. return !this.isBaby();
  300. }
  301.  
  302. protected int j(int i) {
  303. int j = EnchantmentManager.getOxygenEnchantmentLevel(this);
  304.  
  305. return j > 0 && this.random.nextInt(j + 1) > 0 ? i : i - 1;
  306. }
  307.  
  308. protected int getExpValue(EntityHuman entityhuman) {
  309. return 0;
  310. }
  311.  
  312. protected boolean alwaysGivesExp() {
  313. return false;
  314. }
  315.  
  316. public Random aI() {
  317. return this.random;
  318. }
  319.  
  320. public EntityLiving getLastDamager() {
  321. return this.lastDamager;
  322. }
  323.  
  324. public int aK() {
  325. return this.bm;
  326. }
  327.  
  328. public void b(EntityLiving entityliving) {
  329. this.lastDamager = entityliving;
  330. this.bm = this.ticksLived;
  331. }
  332.  
  333. public EntityLiving aL() {
  334. return this.bn;
  335. }
  336.  
  337. public int aM() {
  338. return this.bo;
  339. }
  340.  
  341. public void l(Entity entity) {
  342. if (entity instanceof EntityLiving) {
  343. this.bn = (EntityLiving) entity;
  344. } else {
  345. this.bn = null;
  346. }
  347.  
  348. this.bo = this.ticksLived;
  349. }
  350.  
  351. public int aN() {
  352. return this.aU;
  353. }
  354.  
  355. public void b(NBTTagCompound nbttagcompound) {
  356. nbttagcompound.setFloat("HealF", this.getHealth());
  357. nbttagcompound.setShort("Health", (short) ((int) Math.ceil((double) this.getHealth())));
  358. nbttagcompound.setShort("HurtTime", (short) this.hurtTicks);
  359. nbttagcompound.setShort("DeathTime", (short) this.deathTicks);
  360. nbttagcompound.setShort("AttackTime", (short) this.attackTicks);
  361. nbttagcompound.setFloat("AbsorptionAmount", this.getAbsorptionHearts());
  362. ItemStack[] aitemstack = this.getEquipment();
  363. int i = aitemstack.length;
  364.  
  365. int j;
  366. ItemStack itemstack;
  367.  
  368. for (j = 0; j < i; ++j) {
  369. itemstack = aitemstack[j];
  370. if (itemstack != null) {
  371. this.d.a(itemstack.D());
  372. }
  373. }
  374.  
  375. nbttagcompound.set("Attributes", GenericAttributes.a(this.getAttributeMap()));
  376. aitemstack = this.getEquipment();
  377. i = aitemstack.length;
  378.  
  379. for (j = 0; j < i; ++j) {
  380. itemstack = aitemstack[j];
  381. if (itemstack != null) {
  382. this.d.b(itemstack.D());
  383. }
  384. }
  385.  
  386. if (!this.effects.isEmpty()) {
  387. NBTTagList nbttaglist = new NBTTagList();
  388. Iterator iterator = this.effects.values().iterator();
  389.  
  390. while (iterator.hasNext()) {
  391. MobEffect mobeffect = (MobEffect) iterator.next();
  392.  
  393. nbttaglist.add(mobeffect.a(new NBTTagCompound()));
  394. }
  395.  
  396. nbttagcompound.set("ActiveEffects", nbttaglist);
  397. }
  398. }
  399.  
  400. public void a(NBTTagCompound nbttagcompound) {
  401. this.setAbsorptionHearts(nbttagcompound.getFloat("AbsorptionAmount"));
  402. if (nbttagcompound.hasKeyOfType("Attributes", 9) && this.world != null && !this.world.isStatic) {
  403. GenericAttributes.a(this.getAttributeMap(), nbttagcompound.getList("Attributes", 10));
  404. }
  405.  
  406. if (nbttagcompound.hasKeyOfType("ActiveEffects", 9)) {
  407. NBTTagList nbttaglist = nbttagcompound.getList("ActiveEffects", 10);
  408.  
  409. for (int i = 0; i < nbttaglist.size(); ++i) {
  410. NBTTagCompound nbttagcompound1 = nbttaglist.get(i);
  411. MobEffect mobeffect = MobEffect.b(nbttagcompound1);
  412.  
  413. if (mobeffect != null) {
  414. this.effects.put(Integer.valueOf(mobeffect.getEffectId()), mobeffect);
  415. }
  416. }
  417. }
  418.  
  419. // CraftBukkit start
  420. if (nbttagcompound.hasKey("Bukkit.MaxHealth")) {
  421. NBTBase nbtbase = nbttagcompound.get("Bukkit.MaxHealth");
  422. if (nbtbase.getTypeId() == 5) {
  423. this.getAttributeInstance(GenericAttributes.maxHealth).setValue((double) ((NBTTagFloat) nbtbase).c());
  424. } else if (nbtbase.getTypeId() == 3) {
  425. this.getAttributeInstance(GenericAttributes.maxHealth).setValue((double) ((NBTTagInt) nbtbase).d());
  426. }
  427. }
  428. // CraftBukkit end
  429.  
  430. if (nbttagcompound.hasKeyOfType("HealF", 99)) {
  431. this.setHealth(nbttagcompound.getFloat("HealF"));
  432. } else {
  433. NBTBase nbtbase = nbttagcompound.get("Health");
  434.  
  435. if (nbtbase == null) {
  436. this.setHealth(this.getMaxHealth());
  437. } else if (nbtbase.getTypeId() == 5) {
  438. this.setHealth(((NBTTagFloat) nbtbase).h());
  439. } else if (nbtbase.getTypeId() == 2) {
  440. this.setHealth((float) ((NBTTagShort) nbtbase).e());
  441. }
  442. }
  443.  
  444. this.hurtTicks = nbttagcompound.getShort("HurtTime");
  445. this.deathTicks = nbttagcompound.getShort("DeathTime");
  446. this.attackTicks = nbttagcompound.getShort("AttackTime");
  447. }
  448.  
  449. protected void aO() {
  450. Iterator iterator = this.effects.keySet().iterator();
  451.  
  452. while (iterator.hasNext()) {
  453. Integer integer = (Integer) iterator.next();
  454. MobEffect mobeffect = (MobEffect) this.effects.get(integer);
  455.  
  456. if (!mobeffect.tick(this)) {
  457. if (!this.world.isStatic) {
  458. iterator.remove();
  459. this.b(mobeffect);
  460. }
  461. } else if (mobeffect.getDuration() % 600 == 0) {
  462. this.a(mobeffect, false);
  463. }
  464. }
  465.  
  466. int i;
  467.  
  468. if (this.updateEffects) {
  469. if (!this.world.isStatic) {
  470. if (this.effects.isEmpty()) {
  471. this.datawatcher.watch(8, Byte.valueOf((byte) 0));
  472. this.datawatcher.watch(7, Integer.valueOf(0));
  473. this.setInvisible(false);
  474. } else {
  475. i = PotionBrewer.a(this.effects.values());
  476. this.datawatcher.watch(8, Byte.valueOf((byte) (PotionBrewer.b(this.effects.values()) ? 1 : 0)));
  477. this.datawatcher.watch(7, Integer.valueOf(i));
  478. this.setInvisible(this.hasEffect(MobEffectList.INVISIBILITY.id));
  479. }
  480. }
  481.  
  482. this.updateEffects = false;
  483. }
  484.  
  485. i = this.datawatcher.getInt(7);
  486. boolean flag = this.datawatcher.getByte(8) > 0;
  487.  
  488. if (i > 0) {
  489. boolean flag1 = false;
  490.  
  491. if (!this.isInvisible()) {
  492. flag1 = this.random.nextBoolean();
  493. } else {
  494. flag1 = this.random.nextInt(15) == 0;
  495. }
  496.  
  497. if (flag) {
  498. flag1 &= this.random.nextInt(5) == 0;
  499. }
  500.  
  501. if (flag1 && i > 0) {
  502. double d0 = (double) (i >> 16 & 255) / 255.0D;
  503. double d1 = (double) (i >> 8 & 255) / 255.0D;
  504. double d2 = (double) (i >> 0 & 255) / 255.0D;
  505.  
  506. this.world.addParticle(flag ? "mobSpellAmbient" : "mobSpell", this.locX + (this.random.nextDouble() - 0.5D) * (double) this.width, this.locY + this.random.nextDouble() * (double) this.length - (double) this.height, this.locZ + (this.random.nextDouble() - 0.5D) * (double) this.width, d0, d1, d2);
  507. }
  508. }
  509. }
  510.  
  511. public void removeAllEffects() {
  512. Iterator iterator = this.effects.keySet().iterator();
  513.  
  514. while (iterator.hasNext()) {
  515. Integer integer = (Integer) iterator.next();
  516. MobEffect mobeffect = (MobEffect) this.effects.get(integer);
  517.  
  518. if (!this.world.isStatic) {
  519. iterator.remove();
  520. this.b(mobeffect);
  521. }
  522. }
  523. }
  524.  
  525. public Collection getEffects() {
  526. return this.effects.values();
  527. }
  528.  
  529. public boolean hasEffect(int i) {
  530. // CraftBukkit - Add size check for efficiency
  531. return this.effects.size() != 0 && this.effects.containsKey(Integer.valueOf(i));
  532. }
  533.  
  534. public boolean hasEffect(MobEffectList mobeffectlist) {
  535. // CraftBukkit - Add size check for efficiency
  536. return this.effects.size() != 0 && this.effects.containsKey(Integer.valueOf(mobeffectlist.id));
  537. }
  538.  
  539. public MobEffect getEffect(MobEffectList mobeffectlist) {
  540. return (MobEffect) this.effects.get(Integer.valueOf(mobeffectlist.id));
  541. }
  542.  
  543. public void addEffect(MobEffect mobeffect) {
  544. if (this.d(mobeffect)) {
  545. if (this.effects.containsKey(Integer.valueOf(mobeffect.getEffectId()))) {
  546. ((MobEffect) this.effects.get(Integer.valueOf(mobeffect.getEffectId()))).a(mobeffect);
  547. this.a((MobEffect) this.effects.get(Integer.valueOf(mobeffect.getEffectId())), true);
  548. } else {
  549. this.effects.put(Integer.valueOf(mobeffect.getEffectId()), mobeffect);
  550. this.a(mobeffect);
  551. }
  552. }
  553. }
  554.  
  555. public boolean d(MobEffect mobeffect) {
  556. if (this.getMonsterType() == EnumMonsterType.UNDEAD) {
  557. int i = mobeffect.getEffectId();
  558.  
  559. if (i == MobEffectList.REGENERATION.id || i == MobEffectList.POISON.id) {
  560. return false;
  561. }
  562. }
  563.  
  564. return true;
  565. }
  566.  
  567. public boolean aR() {
  568. return this.getMonsterType() == EnumMonsterType.UNDEAD;
  569. }
  570.  
  571. public void removeEffect(int i) {
  572. MobEffect mobeffect = (MobEffect) this.effects.remove(Integer.valueOf(i));
  573.  
  574. if (mobeffect != null) {
  575. this.b(mobeffect);
  576. }
  577. }
  578.  
  579. protected void a(MobEffect mobeffect) {
  580. this.updateEffects = true;
  581. if (!this.world.isStatic) {
  582. MobEffectList.byId[mobeffect.getEffectId()].b(this, this.getAttributeMap(), mobeffect.getAmplifier());
  583. }
  584. }
  585.  
  586. protected void a(MobEffect mobeffect, boolean flag) {
  587. this.updateEffects = true;
  588. if (flag && !this.world.isStatic) {
  589. MobEffectList.byId[mobeffect.getEffectId()].a(this, this.getAttributeMap(), mobeffect.getAmplifier());
  590. MobEffectList.byId[mobeffect.getEffectId()].b(this, this.getAttributeMap(), mobeffect.getAmplifier());
  591. }
  592. }
  593.  
  594. protected void b(MobEffect mobeffect) {
  595. this.updateEffects = true;
  596. if (!this.world.isStatic) {
  597. MobEffectList.byId[mobeffect.getEffectId()].a(this, this.getAttributeMap(), mobeffect.getAmplifier());
  598. }
  599. }
  600.  
  601. // CraftBukkit start - Delegate so we can handle providing a reason for health being regained
  602. public void heal(float f) {
  603. heal(f, EntityRegainHealthEvent.RegainReason.CUSTOM);
  604. }
  605.  
  606. public void heal(float f, EntityRegainHealthEvent.RegainReason regainReason) {
  607. float f1 = this.getHealth();
  608.  
  609. if (f1 > 0.0F) {
  610. EntityRegainHealthEvent event = new EntityRegainHealthEvent(this.getBukkitEntity(), f, regainReason);
  611. this.world.getServer().getPluginManager().callEvent(event);
  612.  
  613. if (!event.isCancelled()) {
  614. this.setHealth((float) (this.getHealth() + event.getAmount()));
  615. }
  616. }
  617. }
  618.  
  619. public final float getHealth() {
  620. // CraftBukkit start - Use unscaled health
  621. if (this instanceof EntityPlayer) {
  622. return (float) ((EntityPlayer) this).getBukkitEntity().getHealth();
  623. }
  624. // CraftBukkit end
  625. return this.datawatcher.getFloat(6);
  626. }
  627.  
  628. public void setHealth(float f) {
  629. // CraftBukkit start - Handle scaled health
  630. if (this instanceof EntityPlayer) {
  631. org.bukkit.craftbukkit.entity.CraftPlayer player = ((EntityPlayer) this).getBukkitEntity();
  632. // Squeeze
  633. if (f < 0.0F) {
  634. player.setRealHealth(0.0D);
  635. } else if (f > player.getMaxHealth()) {
  636. player.setRealHealth(player.getMaxHealth());
  637. } else {
  638. player.setRealHealth(f);
  639. }
  640.  
  641. this.datawatcher.watch(6, Float.valueOf(player.getScaledHealth()));
  642. return;
  643. }
  644. // CraftBukkit end
  645. this.datawatcher.watch(6, Float.valueOf(MathHelper.a(f, 0.0F, this.getMaxHealth())));
  646. }
  647.  
  648. public boolean damageEntity(DamageSource damagesource, float f) {
  649. if (this.isInvulnerable()) {
  650. return false;
  651. } else if (this.world.isStatic) {
  652. return false;
  653. } else {
  654. this.aU = 0;
  655. if (this.getHealth() <= 0.0F) {
  656. return false;
  657. } else if (damagesource.o() && this.hasEffect(MobEffectList.FIRE_RESISTANCE)) {
  658. return false;
  659. } else {
  660. // CraftBukkit - Moved into d(DamageSource, float)
  661. if (false && (damagesource == DamageSource.ANVIL || damagesource == DamageSource.FALLING_BLOCK) && this.getEquipment(4) != null) {
  662. this.getEquipment(4).damage((int) (f * 4.0F + this.random.nextFloat() * f * 2.0F), this);
  663. f *= 0.75F;
  664. }
  665.  
  666. this.aF = 1.5F;
  667. boolean flag = true;
  668.  
  669. if ((float) this.noDamageTicks > (float) this.maxNoDamageTicks / 2.0F) {
  670. if (f <= this.lastDamage) {
  671. return false;
  672. }
  673.  
  674. // CraftBukkit start
  675. if (!this.d(damagesource, f - this.lastDamage)) {
  676. return false;
  677. }
  678. // CraftBukkit end
  679. this.lastDamage = f;
  680. flag = false;
  681. } else {
  682. // CraftBukkit start
  683. float previousHealth = this.getHealth();
  684. if (!this.d(damagesource, f)) {
  685. return false;
  686. }
  687. this.lastDamage = f;
  688. this.aw = previousHealth;
  689. this.noDamageTicks = this.maxNoDamageTicks;
  690. // CraftBukkit end
  691. this.hurtTicks = this.ay = 10;
  692. }
  693.  
  694. this.az = 0.0F;
  695. Entity entity = damagesource.getEntity();
  696.  
  697. if (entity != null) {
  698. if (entity instanceof EntityLiving) {
  699. this.b((EntityLiving) entity);
  700. }
  701.  
  702. if (entity instanceof EntityHuman) {
  703. this.lastDamageByPlayerTime = 100;
  704. this.killer = (EntityHuman) entity;
  705. } else if (entity instanceof EntityWolf) {
  706. EntityWolf entitywolf = (EntityWolf) entity;
  707.  
  708. if (entitywolf.isTamed()) {
  709. this.lastDamageByPlayerTime = 100;
  710. this.killer = null;
  711. }
  712. }
  713. }
  714.  
  715. if (flag) {
  716. this.world.broadcastEntityEffect(this, (byte) 2);
  717. if (damagesource != DamageSource.DROWN) {
  718. this.Q();
  719. }
  720.  
  721. if (entity != null) {
  722. double d0 = entity.locX - this.locX;
  723.  
  724. double d1;
  725.  
  726. for (d1 = entity.locZ - this.locZ; d0 * d0 + d1 * d1 < 1.0E-4D; d1 = (Math.random() - Math.random()) * 0.01D) {
  727. d0 = (Math.random() - Math.random()) * 0.01D;
  728. }
  729.  
  730. this.az = (float) (Math.atan2(d1, d0) * 180.0D / 3.1415927410125732D) - this.yaw;
  731. this.a(entity, f, d0, d1);
  732. } else {
  733. this.az = (float) ((int) (Math.random() * 2.0D) * 180);
  734. }
  735. }
  736.  
  737. String s;
  738.  
  739. if (this.getHealth() <= 0.0F) {
  740. s = this.aU();
  741. if (flag && s != null) {
  742. this.makeSound(s, this.bf(), this.bg());
  743. }
  744.  
  745. this.die(damagesource);
  746. } else {
  747. s = this.aT();
  748. if (flag && s != null) {
  749. this.makeSound(s, this.bf(), this.bg());
  750. }
  751. }
  752.  
  753. return true;
  754. }
  755. }
  756. }
  757.  
  758. public void a(ItemStack itemstack) {
  759. this.makeSound("random.break", 0.8F, 0.8F + this.world.random.nextFloat() * 0.4F);
  760.  
  761. for (int i = 0; i < 5; ++i) {
  762. Vec3D vec3d = Vec3D.a(((double) this.random.nextFloat() - 0.5D) * 0.1D, Math.random() * 0.1D + 0.1D, 0.0D);
  763.  
  764. vec3d.a(-this.pitch * 3.1415927F / 180.0F);
  765. vec3d.b(-this.yaw * 3.1415927F / 180.0F);
  766. Vec3D vec3d1 = Vec3D.a(((double) this.random.nextFloat() - 0.5D) * 0.3D, (double) (-this.random.nextFloat()) * 0.6D - 0.3D, 0.6D);
  767.  
  768. vec3d1.a(-this.pitch * 3.1415927F / 180.0F);
  769. vec3d1.b(-this.yaw * 3.1415927F / 180.0F);
  770. vec3d1 = vec3d1.add(this.locX, this.locY + (double) this.getHeadHeight(), this.locZ);
  771. this.world.addParticle("iconcrack_" + Item.getId(itemstack.getItem()), vec3d1.a, vec3d1.b, vec3d1.c, vec3d.a, vec3d.b + 0.05D, vec3d.c);
  772. }
  773. }
  774.  
  775. public void die(DamageSource damagesource) {
  776. Entity entity = damagesource.getEntity();
  777. EntityLiving entityliving = this.aX();
  778.  
  779. if (this.ba >= 0 && entityliving != null) {
  780. entityliving.b(this, this.ba);
  781. }
  782.  
  783. if (entity != null) {
  784. entity.a(this);
  785. }
  786.  
  787. this.aT = true;
  788. this.aW().g();
  789. if (!this.world.isStatic) {
  790. int i = 0;
  791.  
  792. if (entity instanceof EntityHuman) {
  793. i = EnchantmentManager.getBonusMonsterLootEnchantmentLevel((EntityLiving) entity);
  794. }
  795.  
  796. if (this.aG() && this.world.getGameRules().getBoolean("doMobLoot")) {
  797. this.drops = new ArrayList<org.bukkit.inventory.ItemStack>(); // CraftBukkit - Setup drop capture
  798.  
  799. this.dropDeathLoot(this.lastDamageByPlayerTime > 0, i);
  800. this.dropEquipment(this.lastDamageByPlayerTime > 0, i);
  801. if (this.lastDamageByPlayerTime > 0) {
  802. int j = this.random.nextInt(200) - i;
  803.  
  804. if (j < 5) {
  805. this.getRareDrop(j <= 0 ? 1 : 0);
  806. }
  807. }
  808.  
  809. // CraftBukkit start - Call death event
  810. CraftEventFactory.callEntityDeathEvent(this, this.drops);
  811. this.drops = null;
  812. } else {
  813. CraftEventFactory.callEntityDeathEvent(this);
  814. // CraftBukkit end
  815. }
  816. }
  817.  
  818. this.world.broadcastEntityEffect(this, (byte) 3);
  819. }
  820.  
  821. protected void dropEquipment(boolean flag, int i) {}
  822.  
  823. public void a(Entity entity, float f, double d0, double d1) {
  824. if (this.random.nextDouble() >= this.getAttributeInstance(GenericAttributes.c).getValue()) {
  825. this.al = true;
  826. float f1 = MathHelper.sqrt(d0 * d0 + d1 * d1);
  827. float f2 = 0.4F;
  828.  
  829. this.motX /= 2.0D;
  830. this.motY /= 2.0D;
  831. this.motZ /= 2.0D;
  832. this.motX -= d0 / (double) f1 * (double) f2;
  833. this.motY += (double) f2;
  834. this.motZ -= d1 / (double) f1 * (double) f2;
  835. if (this.motY > 0.4000000059604645D) {
  836. this.motY = 0.4000000059604645D;
  837. }
  838. }
  839. }
  840.  
  841. protected String aT() {
  842. return "game.neutral.hurt";
  843. }
  844.  
  845. protected String aU() {
  846. return "game.neutral.die";
  847. }
  848.  
  849. protected void getRareDrop(int i) {}
  850.  
  851. protected void dropDeathLoot(boolean flag, int i) {}
  852.  
  853. public boolean h_() {
  854. int i = MathHelper.floor(this.locX);
  855. int j = MathHelper.floor(this.boundingBox.b);
  856. int k = MathHelper.floor(this.locZ);
  857. Block block = this.world.getType(i, j, k);
  858.  
  859. return block == Blocks.LADDER || block == Blocks.VINE;
  860. }
  861.  
  862. public boolean isAlive() {
  863. return !this.dead && this.getHealth() > 0.0F;
  864. }
  865.  
  866. protected void b(float f) {
  867. super.b(f);
  868. MobEffect mobeffect1 = this.getEffect(MobEffectList.JUMP);
  869. float f11 = mobeffect1 != null ? (float) (mobeffect1.getAmplifier() + 1) : 0.0F;
  870. int i1 = MathHelper.f(f - 3.0F - f11);
  871.  
  872. MobEffect mobeffect = this.getEffect(MobEffectList.fall);
  873. float f1 = mobeffect != null ? (float) (mobeffect.getAmplifier() + 256) : 0.0F;
  874. int i = MathHelper.f(f - 3.0F - f1);
  875.  
  876. if (i > 0) {
  877. // CraftBukkit start
  878. if (!this.damageEntity(DamageSource.FALL, (float) i)) {
  879. return;
  880. }
  881. // CraftBukkit end
  882. this.makeSound(this.o(i), 1.0F, 1.0F);
  883. // this.damageEntity(DamageSource.FALL, (float) i); // CraftBukkit - moved up
  884. int j = MathHelper.floor(this.locX);
  885. int k = MathHelper.floor(this.locY - 0.20000000298023224D - (double) this.height);
  886. int l = MathHelper.floor(this.locZ);
  887. Block block = this.world.getType(j, k, l);
  888.  
  889. if (block.getMaterial() != Material.AIR) {
  890. StepSound stepsound = block.stepSound;
  891.  
  892. this.makeSound(stepsound.getStepSound(), stepsound.getVolume1() * 0.5F, stepsound.getVolume2() * 0.75F);
  893. }
  894. }
  895. }
  896.  
  897. protected String o(int i) {
  898. return i > 4 ? "game.neutral.hurt.fall.big" : "game.neutral.hurt.fall.small";
  899. }
  900.  
  901. public int aV() {
  902. int i = 0;
  903. ItemStack[] aitemstack = this.getEquipment();
  904. int j = aitemstack.length;
  905.  
  906. for (int k = 0; k < j; ++k) {
  907. ItemStack itemstack = aitemstack[k];
  908.  
  909. if (itemstack != null && itemstack.getItem() instanceof ItemArmor) {
  910. int l = ((ItemArmor) itemstack.getItem()).c;
  911.  
  912. i += l;
  913. }
  914. }
  915.  
  916. return i;
  917. }
  918.  
  919. protected void damageArmor(float f) {}
  920.  
  921. protected float applyArmorModifier(DamageSource damagesource, float f) {
  922. if (!damagesource.ignoresArmor()) {
  923. int i = 25 - this.aV();
  924. float f1 = f * (float) i;
  925.  
  926. // this.damageArmor(f); // CraftBukkit - Moved into d(DamageSource, float)
  927. f = f1 / 25.0F;
  928. }
  929.  
  930. return f;
  931. }
  932.  
  933. protected float applyMagicModifier(DamageSource damagesource, float f) {
  934. if (damagesource.isStarvation()) {
  935. return f;
  936. } else {
  937. if (this instanceof EntityZombie) {
  938. f = f;
  939. }
  940.  
  941. int i;
  942. int j;
  943. float f1;
  944.  
  945. // CraftBukkit - Moved to d(DamageSource, float)
  946. if (false && this.hasEffect(MobEffectList.RESISTANCE) && damagesource != DamageSource.OUT_OF_WORLD) {
  947. i = (this.getEffect(MobEffectList.RESISTANCE).getAmplifier() + 1) * 5;
  948. j = 25 - i;
  949. f1 = f * (float) j;
  950. f = f1 / 25.0F;
  951. }
  952.  
  953. if (f <= 0.0F) {
  954. return 0.0F;
  955. } else {
  956. i = EnchantmentManager.a(this.getEquipment(), damagesource);
  957. if (i > 20) {
  958. i = 20;
  959. }
  960.  
  961. if (i > 0 && i <= 20) {
  962. j = 25 - i;
  963. f1 = f * (float) j;
  964. f = f1 / 25.0F;
  965. }
  966.  
  967. return f;
  968. }
  969. }
  970. }
  971.  
  972. // CraftBukkit start
  973. protected boolean d(final DamageSource damagesource, float f) { // void -> boolean, add final
  974. if (!this.isInvulnerable()) {
  975. final boolean human = this instanceof EntityHuman;
  976. float originalDamage = f;
  977. Function<Double, Double> hardHat = new Function<Double, Double>() {
  978. @Override
  979. public Double apply(Double f) {
  980. if ((damagesource == DamageSource.ANVIL || damagesource == DamageSource.FALLING_BLOCK) && EntityLiving.this.getEquipment(4) != null) {
  981. return -(f - (f * 0.75F));
  982. }
  983. return -0.0;
  984. }
  985. };
  986. float hardHatModifier = hardHat.apply((double) f).floatValue();
  987. f += hardHatModifier;
  988.  
  989. Function<Double, Double> blocking = new Function<Double, Double>() {
  990. @Override
  991. public Double apply(Double f) {
  992. if (human) {
  993. if (!damagesource.ignoresArmor() && ((EntityHuman) EntityLiving.this).isBlocking() && f > 0.0F) {
  994. return -(f - ((1.0F + f) * 0.5F));
  995. }
  996. }
  997. return -0.0;
  998. }
  999. };
  1000. float blockingModifier = blocking.apply((double) f).floatValue();
  1001. f += blockingModifier;
  1002.  
  1003. Function<Double, Double> armor = new Function<Double, Double>() {
  1004. @Override
  1005. public Double apply(Double f) {
  1006. return -(f - EntityLiving.this.applyArmorModifier(damagesource, f.floatValue()));
  1007. }
  1008. };
  1009. float armorModifier = armor.apply((double) f).floatValue();
  1010. f += armorModifier;
  1011.  
  1012. Function<Double, Double> resistance = new Function<Double, Double>() {
  1013. @Override
  1014. public Double apply(Double f) {
  1015. if (!damagesource.isStarvation() && EntityLiving.this.hasEffect(MobEffectList.RESISTANCE) && damagesource != DamageSource.OUT_OF_WORLD) {
  1016. int i = (EntityLiving.this.getEffect(MobEffectList.RESISTANCE).getAmplifier() + 1) * 5;
  1017. int j = 25 - i;
  1018. float f1 = f.floatValue() * (float) j;
  1019. return -(f - (f1 / 25.0F));
  1020. }
  1021. return -0.0;
  1022. }
  1023. };
  1024. float resistanceModifier = resistance.apply((double) f).floatValue();
  1025. f += resistanceModifier;
  1026.  
  1027. Function<Double, Double> magic = new Function<Double, Double>() {
  1028. @Override
  1029. public Double apply(Double f) {
  1030. return -(f - EntityLiving.this.applyMagicModifier(damagesource, f.floatValue()));
  1031. }
  1032. };
  1033. float magicModifier = magic.apply((double) f).floatValue();
  1034. f += magicModifier;
  1035.  
  1036. Function<Double, Double> absorption = new Function<Double, Double>() {
  1037. @Override
  1038. public Double apply(Double f) {
  1039. return -(Math.max(f - Math.max(f - EntityLiving.this.getAbsorptionHearts(), 0.0F), 0.0F));
  1040. }
  1041. };
  1042. float absorptionModifier = absorption.apply((double) f).floatValue();
  1043.  
  1044. EntityDamageEvent event = CraftEventFactory.handleLivingEntityDamageEvent(this, damagesource, originalDamage, hardHatModifier, blockingModifier, armorModifier, resistanceModifier, magicModifier, absorptionModifier, hardHat, blocking, armor, resistance, magic, absorption);
  1045. if (event.isCancelled()) {
  1046. return false;
  1047. }
  1048.  
  1049. f = (float) event.getFinalDamage();
  1050.  
  1051. // Apply damage to helmet
  1052. if ((damagesource == DamageSource.ANVIL || damagesource == DamageSource.FALLING_BLOCK) && this.getEquipment(4) != null) {
  1053. this.getEquipment(4).damage((int) (event.getDamage() * 4.0F + this.random.nextFloat() * event.getDamage() * 2.0F), this);
  1054. }
  1055.  
  1056. // Apply damage to armor
  1057. if (!damagesource.ignoresArmor()) {
  1058. float armorDamage = (float) (event.getDamage() + event.getDamage(DamageModifier.BLOCKING) + event.getDamage(DamageModifier.HARD_HAT));
  1059. this.damageArmor(armorDamage);
  1060. }
  1061.  
  1062. absorptionModifier = (float) -event.getDamage(DamageModifier.ABSORPTION);
  1063. this.setAbsorptionHearts(Math.max(this.getAbsorptionHearts() - absorptionModifier, 0.0F));
  1064. if (f != 0.0F) {
  1065. if (human) {
  1066. ((EntityHuman) this).applyExhaustion(damagesource.getExhaustionCost());
  1067. }
  1068. // CraftBukkit end
  1069. float f2 = this.getHealth();
  1070.  
  1071. this.setHealth(f2 - f);
  1072. this.aW().a(damagesource, f2, f);
  1073. // CraftBukkit start
  1074. if (human) {
  1075. return true;
  1076. }
  1077. // CraftBukkit end
  1078. this.setAbsorptionHearts(this.getAbsorptionHearts() - f);
  1079. }
  1080. return true; // CraftBukkit
  1081. }
  1082. return false; // CraftBukkit
  1083. }
  1084.  
  1085. public CombatTracker aW() {
  1086. return this.combatTracker;
  1087. }
  1088.  
  1089. public EntityLiving aX() {
  1090. return (EntityLiving) (this.combatTracker.c() != null ? this.combatTracker.c() : (this.killer != null ? this.killer : (this.lastDamager != null ? this.lastDamager : null)));
  1091. }
  1092.  
  1093. public final float getMaxHealth() {
  1094. return (float) this.getAttributeInstance(GenericAttributes.maxHealth).getValue();
  1095. }
  1096.  
  1097. public final int aZ() {
  1098. return this.datawatcher.getByte(9);
  1099. }
  1100.  
  1101. public final void p(int i) {
  1102. this.datawatcher.watch(9, Byte.valueOf((byte) i));
  1103. }
  1104.  
  1105. private int j() {
  1106. return this.hasEffect(MobEffectList.FASTER_DIG) ? 6 - (1 + this.getEffect(MobEffectList.FASTER_DIG).getAmplifier()) * 1 : (this.hasEffect(MobEffectList.SLOWER_DIG) ? 6 + (1 + this.getEffect(MobEffectList.SLOWER_DIG).getAmplifier()) * 2 : 6);
  1107. }
  1108.  
  1109. public void ba() {
  1110. if (!this.at || this.au >= this.j() / 2 || this.au < 0) {
  1111. this.au = -1;
  1112. this.at = true;
  1113. if (this.world instanceof WorldServer) {
  1114. ((WorldServer) this.world).getTracker().a((Entity) this, (Packet) (new PacketPlayOutAnimation(this, 0)));
  1115. }
  1116. }
  1117. }
  1118.  
  1119. protected void G() {
  1120. this.damageEntity(DamageSource.OUT_OF_WORLD, 4.0F);
  1121. }
  1122.  
  1123. protected void bb() {
  1124. int i = this.j();
  1125.  
  1126. if (this.at) {
  1127. ++this.au;
  1128. if (this.au >= i) {
  1129. this.au = 0;
  1130. this.at = false;
  1131. }
  1132. } else {
  1133. this.au = 0;
  1134. }
  1135.  
  1136. this.aD = (float) this.au / (float) i;
  1137. }
  1138.  
  1139. public AttributeInstance getAttributeInstance(IAttribute iattribute) {
  1140. return this.getAttributeMap().a(iattribute);
  1141. }
  1142.  
  1143. public AttributeMapBase getAttributeMap() {
  1144. if (this.d == null) {
  1145. this.d = new AttributeMapServer();
  1146. }
  1147.  
  1148. return this.d;
  1149. }
  1150.  
  1151. public EnumMonsterType getMonsterType() {
  1152. return EnumMonsterType.UNDEFINED;
  1153. }
  1154.  
  1155. public abstract ItemStack be();
  1156.  
  1157. public abstract ItemStack getEquipment(int i);
  1158.  
  1159. public abstract void setEquipment(int i, ItemStack itemstack);
  1160.  
  1161. public void setSprinting(boolean flag) {
  1162. super.setSprinting(flag);
  1163. AttributeInstance attributeinstance = this.getAttributeInstance(GenericAttributes.d);
  1164.  
  1165. if (attributeinstance.a(b) != null) {
  1166. attributeinstance.b(c);
  1167. }
  1168.  
  1169. if (flag) {
  1170. attributeinstance.a(c);
  1171. }
  1172. }
  1173.  
  1174. public abstract ItemStack[] getEquipment();
  1175.  
  1176. protected float bf() {
  1177. return 1.0F;
  1178. }
  1179.  
  1180. protected float bg() {
  1181. return this.isBaby() ? (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.5F : (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F;
  1182. }
  1183.  
  1184. protected boolean bh() {
  1185. return this.getHealth() <= 0.0F;
  1186. }
  1187.  
  1188. public void enderTeleportTo(double d0, double d1, double d2) {
  1189. this.setPositionRotation(d0, d1, d2, this.yaw, this.pitch);
  1190. }
  1191.  
  1192. public void m(Entity entity) {
  1193. double d0 = entity.locX;
  1194. double d1 = entity.boundingBox.b + (double) entity.length;
  1195. double d2 = entity.locZ;
  1196. byte b0 = 1;
  1197.  
  1198. for (int i = -b0; i <= b0; ++i) {
  1199. for (int j = -b0; j < b0; ++j) {
  1200. if (i != 0 || j != 0) {
  1201. int k = (int) (this.locX + (double) i);
  1202. int l = (int) (this.locZ + (double) j);
  1203. AxisAlignedBB axisalignedbb = this.boundingBox.c((double) i, 1.0D, (double) j);
  1204.  
  1205. if (this.world.a(axisalignedbb).isEmpty()) {
  1206. if (World.a((IBlockAccess) this.world, k, (int) this.locY, l)) {
  1207. this.enderTeleportTo(this.locX + (double) i, this.locY + 1.0D, this.locZ + (double) j);
  1208. return;
  1209. }
  1210.  
  1211. if (World.a((IBlockAccess) this.world, k, (int) this.locY - 1, l) || this.world.getType(k, (int) this.locY - 1, l).getMaterial() == Material.WATER) {
  1212. d0 = this.locX + (double) i;
  1213. d1 = this.locY + 1.0D;
  1214. d2 = this.locZ + (double) j;
  1215. }
  1216. }
  1217. }
  1218. }
  1219. }
  1220.  
  1221. this.enderTeleportTo(d0, d1, d2);
  1222. }
  1223.  
  1224. protected void bj() {
  1225. this.motY = 0.41999998688697815D;
  1226. if (this.hasEffect(MobEffectList.JUMP)) {
  1227. this.motY += (double) ((float) (this.getEffect(MobEffectList.JUMP).getAmplifier() + 1) * 0.1F);
  1228. }
  1229.  
  1230. if (this.isSprinting()) {
  1231. float f = this.yaw * 0.017453292F;
  1232.  
  1233. this.motX -= (double) (MathHelper.sin(f) * 0.2F);
  1234. this.motZ += (double) (MathHelper.cos(f) * 0.2F);
  1235. }
  1236.  
  1237. this.al = true;
  1238. }
  1239.  
  1240. public void e(float f, float f1) {
  1241. double d0;
  1242.  
  1243. if (this.M() && (!(this instanceof EntityHuman) || !((EntityHuman) this).abilities.isFlying)) {
  1244. d0 = this.locY;
  1245. this.a(f, f1, this.bk() ? 0.04F : 0.02F);
  1246. this.move(this.motX, this.motY, this.motZ);
  1247. this.motX *= 0.800000011920929D;
  1248. this.motY *= 0.800000011920929D;
  1249. this.motZ *= 0.800000011920929D;
  1250. this.motY -= 0.02D;
  1251. if (this.positionChanged && this.c(this.motX, this.motY + 0.6000000238418579D - this.locY + d0, this.motZ)) {
  1252. this.motY = 0.30000001192092896D;
  1253. }
  1254. } else if (this.P() && (!(this instanceof EntityHuman) || !((EntityHuman) this).abilities.isFlying)) {
  1255. d0 = this.locY;
  1256. this.a(f, f1, 0.02F);
  1257. this.move(this.motX, this.motY, this.motZ);
  1258. this.motX *= 0.5D;
  1259. this.motY *= 0.5D;
  1260. this.motZ *= 0.5D;
  1261. this.motY -= 0.02D;
  1262. if (this.positionChanged && this.c(this.motX, this.motY + 0.6000000238418579D - this.locY + d0, this.motZ)) {
  1263. this.motY = 0.30000001192092896D;
  1264. }
  1265. } else {
  1266. float f2 = 0.91F;
  1267.  
  1268. if (this.onGround) {
  1269. f2 = this.world.getType(MathHelper.floor(this.locX), MathHelper.floor(this.boundingBox.b) - 1, MathHelper.floor(this.locZ)).frictionFactor * 0.91F;
  1270. }
  1271.  
  1272. float f3 = 0.16277136F / (f2 * f2 * f2);
  1273. float f4;
  1274.  
  1275. if (this.onGround) {
  1276. f4 = this.bl() * f3;
  1277. } else {
  1278. f4 = this.aQ;
  1279. }
  1280.  
  1281. this.a(f, f1, f4);
  1282. f2 = 0.91F;
  1283. if (this.onGround) {
  1284. f2 = this.world.getType(MathHelper.floor(this.locX), MathHelper.floor(this.boundingBox.b) - 1, MathHelper.floor(this.locZ)).frictionFactor * 0.91F;
  1285. }
  1286.  
  1287. if (this.h_()) {
  1288. float f5 = 0.15F;
  1289.  
  1290. if (this.motX < (double) (-f5)) {
  1291. this.motX = (double) (-f5);
  1292. }
  1293.  
  1294. if (this.motX > (double) f5) {
  1295. this.motX = (double) f5;
  1296. }
  1297.  
  1298. if (this.motZ < (double) (-f5)) {
  1299. this.motZ = (double) (-f5);
  1300. }
  1301.  
  1302. if (this.motZ > (double) f5) {
  1303. this.motZ = (double) f5;
  1304. }
  1305.  
  1306. this.fallDistance = 0.0F;
  1307. if (this.motY < -0.15D) {
  1308. this.motY = -0.15D;
  1309. }
  1310.  
  1311. boolean flag = this.isSneaking() && this instanceof EntityHuman;
  1312.  
  1313. if (flag && this.motY < 0.0D) {
  1314. this.motY = 0.0D;
  1315. }
  1316. }
  1317.  
  1318. this.move(this.motX, this.motY, this.motZ);
  1319. if (this.positionChanged && this.h_()) {
  1320. this.motY = 0.2D;
  1321. }
  1322.  
  1323. if (this.world.isStatic && (!this.world.isLoaded((int) this.locX, 0, (int) this.locZ) || !this.world.getChunkAtWorldCoords((int) this.locX, (int) this.locZ).d)) {
  1324. if (this.locY > 0.0D) {
  1325. this.motY = -0.1D;
  1326. } else {
  1327. this.motY = 0.0D;
  1328. }
  1329. } else {
  1330. this.motY -= 0.08D;
  1331. }
  1332.  
  1333. this.motY *= 0.9800000190734863D;
  1334. this.motX *= (double) f2;
  1335. this.motZ *= (double) f2;
  1336. }
  1337.  
  1338. this.aE = this.aF;
  1339. d0 = this.locX - this.lastX;
  1340. double d1 = this.locZ - this.lastZ;
  1341. float f6 = MathHelper.sqrt(d0 * d0 + d1 * d1) * 4.0F;
  1342.  
  1343. if (f6 > 1.0F) {
  1344. f6 = 1.0F;
  1345. }
  1346.  
  1347. this.aF += (f6 - this.aF) * 0.4F;
  1348. this.aG += this.aF;
  1349. }
  1350.  
  1351. protected boolean bk() {
  1352. return false;
  1353. }
  1354.  
  1355. public float bl() {
  1356. return this.bk() ? this.bp : 0.1F;
  1357. }
  1358.  
  1359. public void i(float f) {
  1360. this.bp = f;
  1361. }
  1362.  
  1363. public boolean n(Entity entity) {
  1364. this.l(entity);
  1365. return false;
  1366. }
  1367.  
  1368. public boolean isSleeping() {
  1369. return false;
  1370. }
  1371.  
  1372. public void h() {
  1373. SpigotTimings.timerEntityBaseTick.startTiming(); // Spigot
  1374. super.h();
  1375. if (!this.world.isStatic) {
  1376. int i = this.aZ();
  1377.  
  1378. if (i > 0) {
  1379. if (this.av <= 0) {
  1380. this.av = 20 * (30 - i);
  1381. }
  1382.  
  1383. --this.av;
  1384. if (this.av <= 0) {
  1385. this.p(i - 1);
  1386. }
  1387. }
  1388.  
  1389. for (int j = 0; j < 5; ++j) {
  1390. ItemStack itemstack = this.g[j];
  1391. ItemStack itemstack1 = this.getEquipment(j);
  1392.  
  1393. if (!ItemStack.matches(itemstack1, itemstack)) {
  1394. ((WorldServer) this.world).getTracker().a((Entity) this, (Packet) (new PacketPlayOutEntityEquipment(this.getId(), j, itemstack1)));
  1395. if (itemstack != null) {
  1396. this.d.a(itemstack.D());
  1397. }
  1398.  
  1399. if (itemstack1 != null) {
  1400. this.d.b(itemstack1.D());
  1401. }
  1402.  
  1403. this.g[j] = itemstack1 == null ? null : itemstack1.cloneItemStack();
  1404. }
  1405. }
  1406.  
  1407. if (this.ticksLived % 20 == 0) {
  1408. this.aW().g();
  1409. }
  1410. }
  1411.  
  1412. SpigotTimings.timerEntityBaseTick.stopTiming(); // Spigot
  1413. this.e();
  1414. SpigotTimings.timerEntityTickRest.startTiming(); // Spigot
  1415. double d0 = this.locX - this.lastX;
  1416. double d1 = this.locZ - this.lastZ;
  1417. float f = (float) (d0 * d0 + d1 * d1);
  1418. float f1 = this.aM;
  1419. float f2 = 0.0F;
  1420.  
  1421. this.aV = this.aW;
  1422. float f3 = 0.0F;
  1423.  
  1424. if (f > 0.0025000002F) {
  1425. f3 = 1.0F;
  1426. f2 = (float) Math.sqrt((double) f) * 3.0F;
  1427. // CraftBukkit - Math -> TrigMath
  1428. f1 = (float) org.bukkit.craftbukkit.TrigMath.atan2(d1, d0) * 180.0F / 3.1415927F - 90.0F;
  1429. }
  1430.  
  1431. if (this.aD > 0.0F) {
  1432. f1 = this.yaw;
  1433. }
  1434.  
  1435. if (!this.onGround) {
  1436. f3 = 0.0F;
  1437. }
  1438.  
  1439. this.aW += (f3 - this.aW) * 0.3F;
  1440. this.world.methodProfiler.a("headTurn");
  1441. f2 = this.f(f1, f2);
  1442. this.world.methodProfiler.b();
  1443. this.world.methodProfiler.a("rangeChecks");
  1444.  
  1445. while (this.yaw - this.lastYaw < -180.0F) {
  1446. this.lastYaw -= 360.0F;
  1447. }
  1448.  
  1449. while (this.yaw - this.lastYaw >= 180.0F) {
  1450. this.lastYaw += 360.0F;
  1451. }
  1452.  
  1453. while (this.aM - this.aN < -180.0F) {
  1454. this.aN -= 360.0F;
  1455. }
  1456.  
  1457. while (this.aM - this.aN >= 180.0F) {
  1458. this.aN += 360.0F;
  1459. }
  1460.  
  1461. while (this.pitch - this.lastPitch < -180.0F) {
  1462. this.lastPitch -= 360.0F;
  1463. }
  1464.  
  1465. while (this.pitch - this.lastPitch >= 180.0F) {
  1466. this.lastPitch += 360.0F;
  1467. }
  1468.  
  1469. while (this.aO - this.aP < -180.0F) {
  1470. this.aP -= 360.0F;
  1471. }
  1472.  
  1473. while (this.aO - this.aP >= 180.0F) {
  1474. this.aP += 360.0F;
  1475. }
  1476.  
  1477. this.world.methodProfiler.b();
  1478. this.aX += f2;
  1479. SpigotTimings.timerEntityTickRest.stopTiming(); // Spigot
  1480. }
  1481.  
  1482. protected float f(float f, float f1) {
  1483. float f2 = MathHelper.g(f - this.aM);
  1484.  
  1485. this.aM += f2 * 0.3F;
  1486. float f3 = MathHelper.g(this.yaw - this.aM);
  1487. boolean flag = f3 < -90.0F || f3 >= 90.0F;
  1488.  
  1489. if (f3 < -75.0F) {
  1490. f3 = -75.0F;
  1491. }
  1492.  
  1493. if (f3 >= 75.0F) {
  1494. f3 = 75.0F;
  1495. }
  1496.  
  1497. this.aM = this.yaw - f3;
  1498. if (f3 * f3 > 2500.0F) {
  1499. this.aM += f3 * 0.2F;
  1500. }
  1501.  
  1502. if (flag) {
  1503. f1 *= -1.0F;
  1504. }
  1505.  
  1506. return f1;
  1507. }
  1508.  
  1509. public void e() {
  1510. if (this.bq > 0) {
  1511. --this.bq;
  1512. }
  1513.  
  1514. if (this.bg > 0) {
  1515. double d0 = this.locX + (this.bh - this.locX) / (double) this.bg;
  1516. double d1 = this.locY + (this.bi - this.locY) / (double) this.bg;
  1517. double d2 = this.locZ + (this.bj - this.locZ) / (double) this.bg;
  1518. double d3 = MathHelper.g(this.bk - (double) this.yaw);
  1519.  
  1520. this.yaw = (float) ((double) this.yaw + d3 / (double) this.bg);
  1521. this.pitch = (float) ((double) this.pitch + (this.bl - (double) this.pitch) / (double) this.bg);
  1522. --this.bg;
  1523. this.setPosition(d0, d1, d2);
  1524. this.b(this.yaw, this.pitch);
  1525. } else if (!this.br()) {
  1526. this.motX *= 0.98D;
  1527. this.motY *= 0.98D;
  1528. this.motZ *= 0.98D;
  1529. }
  1530.  
  1531. if (Math.abs(this.motX) < 0.005D) {
  1532. this.motX = 0.0D;
  1533. }
  1534.  
  1535. if (Math.abs(this.motY) < 0.005D) {
  1536. this.motY = 0.0D;
  1537. }
  1538.  
  1539. if (Math.abs(this.motZ) < 0.005D) {
  1540. this.motZ = 0.0D;
  1541. }
  1542.  
  1543. this.world.methodProfiler.a("ai");
  1544. SpigotTimings.timerEntityAI.startTiming(); // Spigot
  1545. if (this.bh()) {
  1546. this.bc = false;
  1547. this.bd = 0.0F;
  1548. this.be = 0.0F;
  1549. this.bf = 0.0F;
  1550. } else if (this.br()) {
  1551. if (this.bk()) {
  1552. this.world.methodProfiler.a("newAi");
  1553. this.bn();
  1554. this.world.methodProfiler.b();
  1555. } else {
  1556. this.world.methodProfiler.a("oldAi");
  1557. this.bq();
  1558. this.world.methodProfiler.b();
  1559. this.aO = this.yaw;
  1560. }
  1561. }
  1562. SpigotTimings.timerEntityAI.stopTiming(); // Spigot
  1563.  
  1564. this.world.methodProfiler.b();
  1565. this.world.methodProfiler.a("jump");
  1566. if (this.bc) {
  1567. if (!this.M() && !this.P()) {
  1568. if (this.onGround && this.bq == 0) {
  1569. this.bj();
  1570. this.bq = 10;
  1571. }
  1572. } else {
  1573. this.motY += 0.03999999910593033D;
  1574. }
  1575. } else {
  1576. this.bq = 0;
  1577. }
  1578.  
  1579. this.world.methodProfiler.b();
  1580. this.world.methodProfiler.a("travel");
  1581. this.bd *= 0.98F;
  1582. this.be *= 0.98F;
  1583. this.bf *= 0.9F;
  1584. SpigotTimings.timerEntityAIMove.startTiming(); // Spigot
  1585. this.e(this.bd, this.be);
  1586. SpigotTimings.timerEntityAIMove.stopTiming(); // Spigot
  1587. this.world.methodProfiler.b();
  1588. this.world.methodProfiler.a("push");
  1589. if (!this.world.isStatic) {
  1590. SpigotTimings.timerEntityAICollision.startTiming(); // Spigot
  1591. this.bo();
  1592. SpigotTimings.timerEntityAICollision.stopTiming(); // Spigot
  1593. }
  1594.  
  1595. this.world.methodProfiler.b();
  1596. }
  1597.  
  1598. protected void bn() {}
  1599.  
  1600. protected void bo() {
  1601. List list = this.world.getEntities(this, this.boundingBox.grow(0.20000000298023224D, 0.0D, 0.20000000298023224D));
  1602.  
  1603. if (this.R() && list != null && !list.isEmpty()) { // Spigot: Add this.R() condition
  1604. numCollisions -= world.spigotConfig.maxCollisionsPerEntity; // Spigot
  1605. for (int i = 0; i < list.size(); ++i) {
  1606. if (numCollisions > world.spigotConfig.maxCollisionsPerEntity) { break; } // Spigot
  1607. Entity entity = (Entity) list.get(i);
  1608.  
  1609. // TODO better check now?
  1610. // CraftBukkit start - Only handle mob (non-player) collisions every other tick
  1611. if (entity instanceof EntityLiving && !(this instanceof EntityPlayer) && this.ticksLived % 2 == 0) {
  1612. continue;
  1613. }
  1614. // CraftBukkit end
  1615.  
  1616. if (entity.S()) {
  1617. entity.numCollisions++; // Spigot
  1618. numCollisions++; // Spigot
  1619. this.o(entity);
  1620. }
  1621. }
  1622. numCollisions = 0; // Spigot
  1623. }
  1624. }
  1625.  
  1626. protected void o(Entity entity) {
  1627. entity.collide(this);
  1628. }
  1629.  
  1630. public void ab() {
  1631. super.ab();
  1632. this.aV = this.aW;
  1633. this.aW = 0.0F;
  1634. this.fallDistance = 0.0F;
  1635. }
  1636.  
  1637. protected void bp() {}
  1638.  
  1639. protected void bq() {
  1640. ++this.aU;
  1641. }
  1642.  
  1643. public void f(boolean flag) {
  1644. this.bc = flag;
  1645. }
  1646.  
  1647. public void receive(Entity entity, int i) {
  1648. if (!entity.dead && !this.world.isStatic) {
  1649. EntityTracker entitytracker = ((WorldServer) this.world).getTracker();
  1650.  
  1651. if (entity instanceof EntityItem) {
  1652. entitytracker.a(entity, (Packet) (new PacketPlayOutCollect(entity.getId(), this.getId())));
  1653. }
  1654.  
  1655. if (entity instanceof EntityArrow) {
  1656. entitytracker.a(entity, (Packet) (new PacketPlayOutCollect(entity.getId(), this.getId())));
  1657. }
  1658.  
  1659. if (entity instanceof EntityExperienceOrb) {
  1660. entitytracker.a(entity, (Packet) (new PacketPlayOutCollect(entity.getId(), this.getId())));
  1661. }
  1662. }
  1663. }
  1664.  
  1665. public boolean hasLineOfSight(Entity entity) {
  1666. return this.world.a(Vec3D.a(this.locX, this.locY + (double) this.getHeadHeight(), this.locZ), Vec3D.a(entity.locX, entity.locY + (double) entity.getHeadHeight(), entity.locZ)) == null;
  1667. }
  1668.  
  1669. public Vec3D ag() {
  1670. return this.j(1.0F);
  1671. }
  1672.  
  1673. public Vec3D j(float f) {
  1674. float f1;
  1675. float f2;
  1676. float f3;
  1677. float f4;
  1678.  
  1679. if (f == 1.0F) {
  1680. f1 = MathHelper.cos(-this.yaw * 0.017453292F - 3.1415927F);
  1681. f2 = MathHelper.sin(-this.yaw * 0.017453292F - 3.1415927F);
  1682. f3 = -MathHelper.cos(-this.pitch * 0.017453292F);
  1683. f4 = MathHelper.sin(-this.pitch * 0.017453292F);
  1684. return Vec3D.a((double) (f2 * f3), (double) f4, (double) (f1 * f3));
  1685. } else {
  1686. f1 = this.lastPitch + (this.pitch - this.lastPitch) * f;
  1687. f2 = this.lastYaw + (this.yaw - this.lastYaw) * f;
  1688. f3 = MathHelper.cos(-f2 * 0.017453292F - 3.1415927F);
  1689. f4 = MathHelper.sin(-f2 * 0.017453292F - 3.1415927F);
  1690. float f5 = -MathHelper.cos(-f1 * 0.017453292F);
  1691. float f6 = MathHelper.sin(-f1 * 0.017453292F);
  1692.  
  1693. return Vec3D.a((double) (f4 * f5), (double) f6, (double) (f3 * f5));
  1694. }
  1695. }
  1696.  
  1697. public boolean br() {
  1698. return !this.world.isStatic;
  1699. }
  1700.  
  1701. public boolean R() {
  1702. return !this.dead;
  1703. }
  1704.  
  1705. public boolean S() {
  1706. return !this.dead;
  1707. }
  1708.  
  1709. public float getHeadHeight() {
  1710. return this.length * 0.85F;
  1711. }
  1712.  
  1713. protected void Q() {
  1714. this.velocityChanged = this.random.nextDouble() >= this.getAttributeInstance(GenericAttributes.c).getValue();
  1715. }
  1716.  
  1717. public float getHeadRotation() {
  1718. return this.aO;
  1719. }
  1720.  
  1721. public float getAbsorptionHearts() {
  1722. return this.br;
  1723. }
  1724.  
  1725. public void setAbsorptionHearts(float f) {
  1726. if (f < 0.0F) {
  1727. f = 0.0F;
  1728. }
  1729.  
  1730. this.br = f;
  1731. }
  1732.  
  1733. public ScoreboardTeamBase getScoreboardTeam() {
  1734. return null;
  1735. }
  1736.  
  1737. public boolean c(EntityLiving entityliving) {
  1738. return this.a(entityliving.getScoreboardTeam());
  1739. }
  1740.  
  1741. public boolean a(ScoreboardTeamBase scoreboardteambase) {
  1742. return this.getScoreboardTeam() != null ? this.getScoreboardTeam().isAlly(scoreboardteambase) : false;
  1743. }
  1744.  
  1745. public void bu() {}
  1746.  
  1747. public void bv() {}
  1748. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement