Advertisement
Guest User

Untitled

a guest
May 24th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.28 KB | None | 0 0
  1. package net.minecraft.server;
  2.  
  3. import java.util.Iterator;
  4. import java.util.List;
  5. import java.util.UUID;
  6.  
  7. // CraftBukkit start
  8. import org.bukkit.craftbukkit.event.CraftEventFactory;
  9. import org.bukkit.event.entity.EntityUnleashEvent;
  10. import org.bukkit.event.entity.EntityUnleashEvent.UnleashReason;
  11. // CraftBukkit end
  12.  
  13. public abstract class EntityInsentient extends EntityLiving {
  14.  
  15. public int a_;
  16. protected int b;
  17. private ControllerLook lookController;
  18. private ControllerMove moveController;
  19. private ControllerJump bm;
  20. private EntityAIBodyControl bn;
  21. private Navigation navigation;
  22. protected final PathfinderGoalSelector goalSelector;
  23. protected final PathfinderGoalSelector targetSelector;
  24. private EntityLiving goalTarget;
  25. private EntitySenses bq;
  26. private ItemStack[] equipment = new ItemStack[5];
  27. public float[] dropChances = new float[5]; // CraftBukkit - protected -> public
  28. public boolean canPickUpLoot; // CraftBukkit - private -> public
  29. public boolean persistent = !isTypeNotPersistent(); // CraftBukkit - private -> public
  30. protected float f;
  31. private Entity bu;
  32. protected int g;
  33. private boolean bv;
  34. private Entity bw;
  35. private NBTTagCompound bx;
  36.  
  37. public EntityInsentient(World world) {
  38. super(world);
  39. this.goalSelector = new PathfinderGoalSelector(world != null && world.methodProfiler != null ? world.methodProfiler : null);
  40. this.targetSelector = new PathfinderGoalSelector(world != null && world.methodProfiler != null ? world.methodProfiler : null);
  41. this.lookController = new ControllerLook(this);
  42. this.moveController = new ControllerMove(this);
  43. this.bm = new ControllerJump(this);
  44. this.bn = new EntityAIBodyControl(this);
  45. this.navigation = new Navigation(this, world);
  46. this.bq = new EntitySenses(this);
  47.  
  48. for (int i = 0; i < this.dropChances.length; ++i) {
  49. this.dropChances[i] = 0.085F;
  50. }
  51. }
  52.  
  53. protected void aD() {
  54. super.aD();
  55. this.getAttributeMap().b(GenericAttributes.b).setValue(16.0D);
  56. }
  57.  
  58. public ControllerLook getControllerLook() {
  59. return this.lookController;
  60. }
  61.  
  62. public ControllerMove getControllerMove() {
  63. return this.moveController;
  64. }
  65.  
  66. public ControllerJump getControllerJump() {
  67. return this.bm;
  68. }
  69.  
  70. public Navigation getNavigation() {
  71. return this.navigation;
  72. }
  73.  
  74. public EntitySenses getEntitySenses() {
  75. return this.bq;
  76. }
  77.  
  78. public EntityLiving getGoalTarget() {
  79. return this.goalTarget;
  80. }
  81.  
  82. public void setGoalTarget(EntityLiving entityliving) {
  83. this.goalTarget = entityliving;
  84. }
  85.  
  86. public boolean a(Class oclass) {
  87. return EntityCreeper.class != oclass && EntityGhast.class != oclass;
  88. }
  89.  
  90. public void p() {}
  91.  
  92. protected void c() {
  93. super.c();
  94. this.datawatcher.a(11, Byte.valueOf((byte) 0));
  95. this.datawatcher.a(10, "");
  96. // Spigot start - protocol patch
  97. this.datawatcher.a(3, Byte.valueOf((byte) 0));
  98. this.datawatcher.a(2, "");
  99. // Spigot end
  100. }
  101.  
  102. public int q() {
  103. return 80;
  104. }
  105.  
  106. public void r() {
  107. String s = this.t();
  108.  
  109. if (s != null) {
  110. this.makeSound(s, this.bf(), this.bg());
  111. }
  112. }
  113.  
  114. public void C() {
  115. super.C();
  116. this.world.methodProfiler.a("mobBaseTick");
  117. if (this.isAlive() && this.random.nextInt(1000) < this.a_++) {
  118. this.a_ = -this.q();
  119. this.r();
  120. }
  121.  
  122. this.world.methodProfiler.b();
  123. }
  124.  
  125. protected int getExpValue(EntityHuman entityhuman) {
  126. if (this.b > 0) {
  127. int i = this.b;
  128. ItemStack[] aitemstack = this.getEquipment();
  129.  
  130. for (int j = 0; j < aitemstack.length; ++j) {
  131. if (aitemstack[j] != null && this.dropChances[j] <= 1.0F) {
  132. i += 1 + this.random.nextInt(3);
  133. }
  134. }
  135.  
  136. return i;
  137. } else {
  138. return this.b;
  139. }
  140. }
  141.  
  142. public void s() {
  143. for (int i = 0; i < 20; ++i) {
  144. double d0 = this.random.nextGaussian() * 0.02D;
  145. double d1 = this.random.nextGaussian() * 0.02D;
  146. double d2 = this.random.nextGaussian() * 0.02D;
  147. double d3 = 10.0D;
  148.  
  149. this.world.addParticle("explode", this.locX + (double) (this.random.nextFloat() * this.width * 2.0F) - (double) this.width - d0 * d3, this.locY + (double) (this.random.nextFloat() * this.length) - d1 * d3, this.locZ + (double) (this.random.nextFloat() * this.width * 2.0F) - (double) this.width - d2 * d3, d0, d1, d2);
  150. }
  151. }
  152.  
  153. public void h() {
  154. super.h();
  155. if (!this.world.isStatic) {
  156. this.bL();
  157. }
  158. }
  159.  
  160. protected float f(float f, float f1) {
  161. if (this.bk()) {
  162. this.bn.a();
  163. return f1;
  164. } else {
  165. return super.f(f, f1);
  166. }
  167. }
  168.  
  169. protected String t() {
  170. return null;
  171. }
  172.  
  173. protected Item getLoot() {
  174. return Item.getById(0);
  175. }
  176.  
  177. protected void dropDeathLoot(boolean flag, int i) {
  178. Item item = this.getLoot();
  179.  
  180. if (item != null) {
  181. int j = this.random.nextInt(3);
  182.  
  183. if (i > 0) {
  184. j += this.random.nextInt(i + 1);
  185. }
  186.  
  187. for (int k = 0; k < j; ++k) {
  188. this.a(item, 1);
  189. }
  190. }
  191. }
  192.  
  193. public void b(NBTTagCompound nbttagcompound) {
  194. super.b(nbttagcompound);
  195. nbttagcompound.setBoolean("CanPickUpLoot", this.bJ());
  196. nbttagcompound.setBoolean("PersistenceRequired", this.persistent);
  197. NBTTagList nbttaglist = new NBTTagList();
  198.  
  199. NBTTagCompound nbttagcompound1;
  200.  
  201. for (int i = 0; i < this.equipment.length; ++i) {
  202. nbttagcompound1 = new NBTTagCompound();
  203. if (this.equipment[i] != null) {
  204. this.equipment[i].save(nbttagcompound1);
  205. }
  206.  
  207. nbttaglist.add(nbttagcompound1);
  208. }
  209.  
  210. nbttagcompound.set("Equipment", nbttaglist);
  211. NBTTagList nbttaglist1 = new NBTTagList();
  212.  
  213. for (int j = 0; j < this.dropChances.length; ++j) {
  214. nbttaglist1.add(new NBTTagFloat(this.dropChances[j]));
  215. }
  216.  
  217. nbttagcompound.set("DropChances", nbttaglist1);
  218. nbttagcompound.setString("CustomName", this.getCustomName());
  219. nbttagcompound.setBoolean("CustomNameVisible", this.getCustomNameVisible());
  220. nbttagcompound.setBoolean("Leashed", this.bv);
  221. if (this.bw != null) {
  222. nbttagcompound1 = new NBTTagCompound();
  223. if (this.bw instanceof EntityLiving) {
  224. nbttagcompound1.setLong("UUIDMost", this.bw.getUniqueID().getMostSignificantBits());
  225. nbttagcompound1.setLong("UUIDLeast", this.bw.getUniqueID().getLeastSignificantBits());
  226. } else if (this.bw instanceof EntityHanging) {
  227. EntityHanging entityhanging = (EntityHanging) this.bw;
  228.  
  229. nbttagcompound1.setInt("X", entityhanging.x);
  230. nbttagcompound1.setInt("Y", entityhanging.y);
  231. nbttagcompound1.setInt("Z", entityhanging.z);
  232. }
  233.  
  234. nbttagcompound.set("Leash", nbttagcompound1);
  235. }
  236. }
  237.  
  238. public void a(NBTTagCompound nbttagcompound) {
  239. super.a(nbttagcompound);
  240.  
  241. // CraftBukkit start - If looting or persistence is false only use it if it was set after we started using it
  242. boolean data = nbttagcompound.getBoolean("CanPickUpLoot");
  243. if (isLevelAtLeast(nbttagcompound, 1) || data) {
  244. this.canPickUpLoot = data;
  245. }
  246.  
  247. data = nbttagcompound.getBoolean("PersistenceRequired");
  248. if (isLevelAtLeast(nbttagcompound, 1) || data) {
  249. this.persistent = data;
  250. }
  251. // CraftBukkit end
  252.  
  253. if (nbttagcompound.hasKeyOfType("CustomName", 8) && nbttagcompound.getString("CustomName").length() > 0) {
  254. this.setCustomName(nbttagcompound.getString("CustomName"));
  255. }
  256.  
  257. this.setCustomNameVisible(nbttagcompound.getBoolean("CustomNameVisible"));
  258. NBTTagList nbttaglist;
  259. int i;
  260.  
  261. if (nbttagcompound.hasKeyOfType("Equipment", 9)) {
  262. nbttaglist = nbttagcompound.getList("Equipment", 10);
  263.  
  264. for (i = 0; i < this.equipment.length; ++i) {
  265. this.equipment[i] = ItemStack.createStack(nbttaglist.get(i));
  266. }
  267. }
  268.  
  269. if (nbttagcompound.hasKeyOfType("DropChances", 9)) {
  270. nbttaglist = nbttagcompound.getList("DropChances", 5);
  271.  
  272. for (i = 0; i < nbttaglist.size(); ++i) {
  273. this.dropChances[i] = nbttaglist.e(i);
  274. }
  275. }
  276.  
  277. this.bv = nbttagcompound.getBoolean("Leashed");
  278. if (this.bv && nbttagcompound.hasKeyOfType("Leash", 10)) {
  279. this.bx = nbttagcompound.getCompound("Leash");
  280. }
  281. }
  282.  
  283. public void n(float f) {
  284. this.be = f;
  285. }
  286.  
  287. public void i(float f) {
  288. super.i(f);
  289. this.n(f);
  290. }
  291.  
  292. public void e() {
  293. super.e();
  294. this.world.methodProfiler.a("looting");
  295. if (!this.world.isStatic && this.bJ() && !this.aT && this.world.getGameRules().getBoolean("mobGriefing")) {
  296. List list = this.world.a(EntityItem.class, this.boundingBox.grow(1.0D, 0.0D, 1.0D));
  297. Iterator iterator = list.iterator();
  298.  
  299. while (iterator.hasNext()) {
  300. EntityItem entityitem = (EntityItem) iterator.next();
  301.  
  302. if (!entityitem.dead && entityitem.getItemStack() != null) {
  303. ItemStack itemstack = entityitem.getItemStack();
  304. int i = b(itemstack);
  305.  
  306. if (i > -1) {
  307. boolean flag = true;
  308. ItemStack itemstack1 = this.getEquipment(i);
  309.  
  310. if (itemstack1 != null) {
  311. if (i == 0) {
  312. if (itemstack.getItem() instanceof ItemSword && !(itemstack1.getItem() instanceof ItemSword)) {
  313. flag = true;
  314. } else if (itemstack.getItem() instanceof ItemSword && itemstack1.getItem() instanceof ItemSword) {
  315. ItemSword itemsword = (ItemSword) itemstack.getItem();
  316. ItemSword itemsword1 = (ItemSword) itemstack1.getItem();
  317.  
  318. if (itemsword.i() == itemsword1.i()) {
  319. flag = itemstack.getData() > itemstack1.getData() || itemstack.hasTag() && !itemstack1.hasTag();
  320. } else {
  321. flag = itemsword.i() > itemsword1.i();
  322. }
  323. } else {
  324. flag = false;
  325. }
  326. } else if (itemstack.getItem() instanceof ItemArmor && !(itemstack1.getItem() instanceof ItemArmor)) {
  327. flag = true;
  328. } else if (itemstack.getItem() instanceof ItemArmor && itemstack1.getItem() instanceof ItemArmor) {
  329. ItemArmor itemarmor = (ItemArmor) itemstack.getItem();
  330. ItemArmor itemarmor1 = (ItemArmor) itemstack1.getItem();
  331.  
  332. if (itemarmor.c == itemarmor1.c) {
  333. flag = itemstack.getData() > itemstack1.getData() || itemstack.hasTag() && !itemstack1.hasTag();
  334. } else {
  335. flag = itemarmor.c > itemarmor1.c;
  336. }
  337. } else {
  338. flag = false;
  339. }
  340. }
  341.  
  342. if (flag) {
  343. if (itemstack1 != null && this.random.nextFloat() - 0.1F < this.dropChances[i]) {
  344. this.a(itemstack1, 0.0F);
  345. }
  346.  
  347. if (itemstack.getItem() == Items.DIAMOND && entityitem.j() != null) {
  348. EntityHuman entityhuman = this.world.a(entityitem.j());
  349.  
  350. if (entityhuman != null) {
  351. entityhuman.a((Statistic) AchievementList.x);
  352. }
  353. }
  354.  
  355. this.setEquipment(i, itemstack);
  356. this.dropChances[i] = 2.0F;
  357. this.persistent = true;
  358. this.receive(entityitem, 1);
  359. entityitem.die();
  360. }
  361. }
  362. }
  363. }
  364. }
  365.  
  366. this.world.methodProfiler.b();
  367. }
  368.  
  369. protected boolean bk() {
  370. return false;
  371. }
  372.  
  373. protected boolean isTypeNotPersistent() {
  374. return true;
  375. }
  376.  
  377. protected void w() {
  378. if (this.persistent) {
  379. this.aU = 0;
  380. } else {
  381. EntityHuman entityhuman = this.world.findNearbyPlayer(this, -1.0D);
  382.  
  383. if (entityhuman != null) {
  384. double d0 = entityhuman.locX - this.locX;
  385. double d1 = entityhuman.locY - this.locY;
  386. double d2 = entityhuman.locZ - this.locZ;
  387. double d3 = d0 * d0 + d1 * d1 + d2 * d2;
  388.  
  389. if (d3 > 16384.0D) { // CraftBukkit - remove isTypeNotPersistent() check
  390. this.die();
  391. }
  392.  
  393. if (this.aU > 600 && this.random.nextInt(800) == 0 && d3 > 1024.0D) { // CraftBukkit - remove isTypeNotPersistent() check
  394. this.die();
  395. } else if (d3 < 1024.0D) {
  396. this.aU = 0;
  397. }
  398. }
  399. }
  400. }
  401.  
  402. protected void bn() {
  403. ++this.aU;
  404. this.world.methodProfiler.a("checkDespawn");
  405. this.w();
  406. this.world.methodProfiler.b();
  407. // Spigot Start
  408. if ( this.fromMobSpawner )
  409. {
  410. return;
  411. }
  412. // Spigot End
  413. this.world.methodProfiler.a("sensing");
  414. this.bq.a();
  415. this.world.methodProfiler.b();
  416. this.world.methodProfiler.a("targetSelector");
  417. this.targetSelector.a();
  418. this.world.methodProfiler.b();
  419. this.world.methodProfiler.a("goalSelector");
  420. this.goalSelector.a();
  421. this.world.methodProfiler.b();
  422. this.world.methodProfiler.a("navigation");
  423. this.navigation.f();
  424. this.world.methodProfiler.b();
  425. this.world.methodProfiler.a("mob tick");
  426. this.bp();
  427. this.world.methodProfiler.b();
  428. this.world.methodProfiler.a("controls");
  429. this.world.methodProfiler.a("move");
  430. this.moveController.c();
  431. this.world.methodProfiler.c("look");
  432. this.lookController.a();
  433. this.world.methodProfiler.c("jump");
  434. this.bm.b();
  435. this.world.methodProfiler.b();
  436. this.world.methodProfiler.b();
  437. }
  438.  
  439. protected void bq() {
  440. super.bq();
  441. this.bd = 0.0F;
  442. this.be = 0.0F;
  443. this.w();
  444. float f = 8.0F;
  445.  
  446. if (this.random.nextFloat() < 0.02F) {
  447. EntityHuman entityhuman = this.world.findNearbyPlayer(this, (double) f);
  448.  
  449. if (entityhuman != null) {
  450. this.bu = entityhuman;
  451. this.g = 10 + this.random.nextInt(20);
  452. } else {
  453. this.bf = (this.random.nextFloat() - 0.5F) * 20.0F;
  454. }
  455. }
  456.  
  457. if (this.bu != null) {
  458. this.a(this.bu, 10.0F, (float) this.x());
  459. if (this.g-- <= 0 || this.bu.dead || this.bu.f((Entity) this) > (double) (f * f)) {
  460. this.bu = null;
  461. }
  462. } else {
  463. if (this.random.nextFloat() < 0.05F) {
  464. this.bf = (this.random.nextFloat() - 0.5F) * 20.0F;
  465. }
  466.  
  467. this.yaw += this.bf;
  468. this.pitch = this.f;
  469. }
  470.  
  471. boolean flag = this.M();
  472. boolean flag1 = this.P();
  473.  
  474. if (flag || flag1) {
  475. this.bc = this.random.nextFloat() < 0.8F;
  476. }
  477. }
  478.  
  479. public int x() {
  480. return 40;
  481. }
  482.  
  483. public void a(Entity entity, float f, float f1) {
  484. double d0 = entity.locX - this.locX;
  485. double d1 = entity.locZ - this.locZ;
  486. double d2;
  487.  
  488. if (entity instanceof EntityLiving) {
  489. EntityLiving entityliving = (EntityLiving) entity;
  490.  
  491. d2 = entityliving.locY + (double) entityliving.getHeadHeight() - (this.locY + (double) this.getHeadHeight());
  492. } else {
  493. d2 = (entity.boundingBox.b + entity.boundingBox.e) / 2.0D - (this.locY + (double) this.getHeadHeight());
  494. }
  495.  
  496. double d3 = (double) MathHelper.sqrt(d0 * d0 + d1 * d1);
  497. float f2 = (float) (Math.atan2(d1, d0) * 180.0D / 3.1415927410125732D) - 90.0F;
  498. float f3 = (float) (-(Math.atan2(d2, d3) * 180.0D / 3.1415927410125732D));
  499.  
  500. this.pitch = this.b(this.pitch, f3, f1);
  501. this.yaw = this.b(this.yaw, f2, f);
  502. }
  503.  
  504. private float b(float f, float f1, float f2) {
  505. float f3 = MathHelper.g(f1 - f);
  506.  
  507. if (f3 > f2) {
  508. f3 = f2;
  509. }
  510.  
  511. if (f3 < -f2) {
  512. f3 = -f2;
  513. }
  514.  
  515. return f + f3;
  516. }
  517.  
  518. public boolean canSpawn() {
  519. return this.world.b(this.boundingBox) && this.world.getCubes(this, this.boundingBox).isEmpty() && !this.world.containsLiquid(this.boundingBox);
  520. }
  521.  
  522. public int bB() {
  523. return 4;
  524. }
  525.  
  526. public int ax() {
  527. if (this.getGoalTarget() == null) {
  528. return 3;
  529. } else {
  530. int i = (int) (this.getHealth() - this.getMaxHealth() * 0.33F);
  531.  
  532. i -= (3 - this.world.difficulty.a()) * 4;
  533. if (i < 0) {
  534. i = 0;
  535. }
  536.  
  537. return i + 3;
  538. }
  539. }
  540.  
  541. public ItemStack be() {
  542. return this.equipment[0];
  543. }
  544.  
  545. public ItemStack getEquipment(int i) {
  546. return this.equipment[i];
  547. }
  548.  
  549. public ItemStack r(int i) {
  550. return this.equipment[i + 1];
  551. }
  552.  
  553. public void setEquipment(int i, ItemStack itemstack) {
  554. this.equipment[i] = itemstack;
  555. }
  556.  
  557. public ItemStack[] getEquipment() {
  558. return this.equipment;
  559. }
  560.  
  561. protected void dropEquipment(boolean flag, int i) {
  562. for (int j = 0; j < this.getEquipment().length; ++j) {
  563. ItemStack itemstack = this.getEquipment(j);
  564. boolean flag1 = this.dropChances[j] > 1.0F;
  565.  
  566. if (itemstack != null && (flag || flag1) && this.random.nextFloat() - (float) i * 0.01F < this.dropChances[j]) {
  567. if (!flag1 && itemstack.g()) {
  568. int k = Math.max(itemstack.l() - 25, 1);
  569. int l = itemstack.l() - this.random.nextInt(this.random.nextInt(k) + 1);
  570.  
  571. if (l > k) {
  572. l = k;
  573. }
  574.  
  575. if (l < 1) {
  576. l = 1;
  577. }
  578.  
  579. itemstack.setData(l);
  580. }
  581.  
  582. this.a(itemstack, 0.0F);
  583. }
  584. }
  585. }
  586.  
  587. protected void bC() {
  588. if (this.random.nextFloat() < 0.15F * this.world.b(this.locX, this.locY, this.locZ)) {
  589. int i = this.random.nextInt(2);
  590. float f = this.world.difficulty == EnumDifficulty.HARD ? 0.1F : 0.25F;
  591.  
  592. if (this.random.nextFloat() < 0.095F) {
  593. ++i;
  594. }
  595.  
  596. if (this.random.nextFloat() < 0.095F) {
  597. ++i;
  598. }
  599.  
  600. if (this.random.nextFloat() < 0.095F) {
  601. ++i;
  602. }
  603.  
  604. for (int j = 3; j >= 0; --j) {
  605. ItemStack itemstack = this.r(j);
  606.  
  607. if (j < 3 && this.random.nextFloat() < f) {
  608. break;
  609. }
  610.  
  611. if (itemstack == null) {
  612. Item item = a(j + 1, i);
  613.  
  614. if (item != null) {
  615. this.setEquipment(j + 1, new ItemStack(item));
  616. }
  617. }
  618. }
  619. }
  620. }
  621.  
  622. public static int b(ItemStack itemstack) {
  623. if (itemstack.getItem() != Item.getItemOf(Blocks.PUMPKIN) && itemstack.getItem() != Items.SKULL) {
  624. if (itemstack.getItem() instanceof ItemArmor) {
  625. switch (((ItemArmor) itemstack.getItem()).b) {
  626. case 0:
  627. return 4;
  628.  
  629. case 1:
  630. return 3;
  631.  
  632. case 2:
  633. return 2;
  634.  
  635. case 3:
  636. return 1;
  637. }
  638. }
  639.  
  640. return 0;
  641. } else {
  642. return 4;
  643. }
  644. }
  645.  
  646. public static Item a(int i, int j) {
  647. switch (i) {
  648. case 4:
  649. if (j == 0) {
  650. return Items.LEATHER_HELMET;
  651. } else if (j == 1) {
  652. return Items.GOLD_HELMET;
  653. } else if (j == 2) {
  654. return Items.CHAINMAIL_HELMET;
  655. } else if (j == 3) {
  656. return Items.IRON_HELMET;
  657. } else if (j == 4) {
  658. return Items.DIAMOND_HELMET;
  659. }
  660.  
  661. case 3:
  662. if (j == 0) {
  663. return Items.LEATHER_CHESTPLATE;
  664. } else if (j == 1) {
  665. return Items.GOLD_CHESTPLATE;
  666. } else if (j == 2) {
  667. return Items.CHAINMAIL_CHESTPLATE;
  668. } else if (j == 3) {
  669. return Items.IRON_CHESTPLATE;
  670. } else if (j == 4) {
  671. return Items.DIAMOND_CHESTPLATE;
  672. }
  673.  
  674. case 2:
  675. if (j == 0) {
  676. return Items.LEATHER_LEGGINGS;
  677. } else if (j == 1) {
  678. return Items.GOLD_LEGGINGS;
  679. } else if (j == 2) {
  680. return Items.CHAINMAIL_LEGGINGS;
  681. } else if (j == 3) {
  682. return Items.IRON_LEGGINGS;
  683. } else if (j == 4) {
  684. return Items.DIAMOND_LEGGINGS;
  685. }
  686.  
  687. case 1:
  688. if (j == 0) {
  689. return Items.LEATHER_BOOTS;
  690. } else if (j == 1) {
  691. return Items.GOLD_BOOTS;
  692. } else if (j == 2) {
  693. return Items.CHAINMAIL_BOOTS;
  694. } else if (j == 3) {
  695. return Items.IRON_BOOTS;
  696. } else if (j == 4) {
  697. return Items.DIAMOND_BOOTS;
  698. }
  699.  
  700. default:
  701. return null;
  702. }
  703. }
  704.  
  705. protected void bD() {
  706. float f = this.world.b(this.locX, this.locY, this.locZ);
  707.  
  708. if (this.be() != null && this.random.nextFloat() < 0.25F * f) {
  709. EnchantmentManager.a(this.random, this.be(), (int) (5.0F + f * (float) this.random.nextInt(18)));
  710. }
  711.  
  712. for (int i = 0; i < 4; ++i) {
  713. ItemStack itemstack = this.r(i);
  714.  
  715. if (itemstack != null && this.random.nextFloat() < 0.5F * f) {
  716. EnchantmentManager.a(this.random, itemstack, (int) (5.0F + f * (float) this.random.nextInt(18)));
  717. }
  718. }
  719. }
  720.  
  721. public GroupDataEntity prepare(GroupDataEntity groupdataentity) {
  722. this.getAttributeInstance(GenericAttributes.b).a(new AttributeModifier("Random spawn bonus", this.random.nextGaussian() * 0.05D, 1));
  723. return groupdataentity;
  724. }
  725.  
  726. public boolean bE() {
  727. return false;
  728. }
  729.  
  730. public String getName() {
  731. return this.hasCustomName() ? this.getCustomName() : super.getName();
  732. }
  733.  
  734. public void bF() {
  735. this.persistent = true;
  736. }
  737.  
  738. public void setCustomName(String s) {
  739. this.datawatcher.watch(10, s);
  740. this.datawatcher.watch(2, s); // Spigot - protocol patch
  741. }
  742.  
  743. public String getCustomName() {
  744. return this.datawatcher.getString(10);
  745. }
  746.  
  747. public boolean hasCustomName() {
  748. return this.datawatcher.getString(10).length() > 0;
  749. }
  750.  
  751. public void setCustomNameVisible(boolean flag) {
  752. this.datawatcher.watch(11, Byte.valueOf((byte) (flag ? 1 : 0)));
  753. this.datawatcher.watch(3, Byte.valueOf((byte) (flag ? 1 : 0))); // Spigot - protocol patch
  754. }
  755.  
  756. public boolean getCustomNameVisible() {
  757. return this.datawatcher.getByte(11) == 1;
  758. }
  759.  
  760. public void a(int i, float f) {
  761. this.dropChances[i] = f;
  762. }
  763.  
  764. public boolean bJ() {
  765. return this.canPickUpLoot;
  766. }
  767.  
  768. public void h(boolean flag) {
  769. this.canPickUpLoot = flag;
  770. }
  771.  
  772. public boolean isPersistent() {
  773. return this.persistent;
  774. }
  775.  
  776. public final boolean c(EntityHuman entityhuman) {
  777. if (this.bN() && this.getLeashHolder() == entityhuman) {
  778. // CraftBukkit start - fire PlayerUnleashEntityEvent
  779. if (CraftEventFactory.callPlayerUnleashEntityEvent(this, entityhuman).isCancelled()) {
  780. ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutAttachEntity(1, this, this.getLeashHolder()));
  781. return false;
  782. }
  783. // CraftBukkit end
  784. this.unleash(true, !entityhuman.abilities.canInstantlyBuild);
  785. return true;
  786. } else {
  787. ItemStack itemstack = entityhuman.inventory.getItemInHand();
  788.  
  789. if (itemstack != null && itemstack.getItem() == Items.LEASH && this.bM()) {
  790. if (!(this instanceof EntityTameableAnimal) || !((EntityTameableAnimal) this).isTamed()) {
  791. // CraftBukkit start - fire PlayerLeashEntityEvent
  792. if (CraftEventFactory.callPlayerLeashEntityEvent(this, entityhuman, entityhuman).isCancelled()) {
  793. ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutAttachEntity(1, this, this.getLeashHolder()));
  794. return false;
  795. }
  796. // CraftBukkit end
  797. this.setLeashHolder(entityhuman, true);
  798. --itemstack.count;
  799. return true;
  800. }
  801.  
  802. if (((EntityTameableAnimal) this).e(entityhuman)) {
  803. // CraftBukkit start - fire PlayerLeashEntityEvent
  804. if (CraftEventFactory.callPlayerLeashEntityEvent(this, entityhuman, entityhuman).isCancelled()) {
  805. ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutAttachEntity(1, this, this.getLeashHolder()));
  806. return false;
  807. }
  808. // CraftBukkit end
  809. this.setLeashHolder(entityhuman, true);
  810. --itemstack.count;
  811. return true;
  812. }
  813. }
  814.  
  815. return this.a(entityhuman) ? true : super.c(entityhuman);
  816. }
  817. }
  818.  
  819. protected boolean a(EntityHuman entityhuman) {
  820. return false;
  821. }
  822.  
  823. protected void bL() {
  824. if (this.bx != null) {
  825. this.bP();
  826. }
  827.  
  828. if (this.bv) {
  829. if (this.bw == null || this.bw.dead) {
  830. this.world.getServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.HOLDER_GONE)); // CraftBukkit
  831. this.unleash(true, true);
  832. }
  833. }
  834. }
  835.  
  836. public void unleash(boolean flag, boolean flag1) {
  837. if (this.bv) {
  838. this.bv = false;
  839. this.bw = null;
  840. if (!this.world.isStatic && flag1) {
  841. this.a(Items.LEASH, 1);
  842. }
  843.  
  844. if (!this.world.isStatic && flag && this.world instanceof WorldServer) {
  845. ((WorldServer) this.world).getTracker().a((Entity) this, (Packet) (new PacketPlayOutAttachEntity(1, this, (Entity) null)));
  846. }
  847. }
  848. }
  849.  
  850. public boolean bM() {
  851. return !this.bN() && !(this instanceof IMonster);
  852. }
  853.  
  854. public boolean bN() {
  855. return this.bv;
  856. }
  857.  
  858. public Entity getLeashHolder() {
  859. return this.bw;
  860. }
  861.  
  862. public void setLeashHolder(Entity entity, boolean flag) {
  863. this.bv = true;
  864. this.bw = entity;
  865. if (!this.world.isStatic && flag && this.world instanceof WorldServer) {
  866. ((WorldServer) this.world).getTracker().a((Entity) this, (Packet) (new PacketPlayOutAttachEntity(1, this, this.bw)));
  867. }
  868. }
  869.  
  870. private void bP() {
  871. if (this.bv && this.bx != null) {
  872. if (this.bx.hasKeyOfType("UUIDMost", 4) && this.bx.hasKeyOfType("UUIDLeast", 4)) {
  873. UUID uuid = new UUID(this.bx.getLong("UUIDMost"), this.bx.getLong("UUIDLeast"));
  874. List list = this.world.a(EntityLiving.class, this.boundingBox.grow(10.0D, 10.0D, 10.0D));
  875. Iterator iterator = list.iterator();
  876.  
  877. while (iterator.hasNext()) {
  878. EntityLiving entityliving = (EntityLiving) iterator.next();
  879.  
  880. if (entityliving.getUniqueID().equals(uuid)) {
  881. this.bw = entityliving;
  882. break;
  883. }
  884. }
  885. } else if (this.bx.hasKeyOfType("X", 99) && this.bx.hasKeyOfType("Y", 99) && this.bx.hasKeyOfType("Z", 99)) {
  886. int i = this.bx.getInt("X");
  887. int j = this.bx.getInt("Y");
  888. int k = this.bx.getInt("Z");
  889. EntityLeash entityleash = EntityLeash.b(this.world, i, j, k);
  890.  
  891. if (entityleash == null) {
  892. entityleash = EntityLeash.a(this.world, i, j, k);
  893. }
  894.  
  895. this.bw = entityleash;
  896. } else {
  897. this.world.getServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN)); // CraftBukkit
  898. this.unleash(false, true);
  899. }
  900. }
  901.  
  902. this.bx = null;
  903. }
  904. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement