Advertisement
Guest User

minecraft Entity move()

a guest
Feb 15th, 2020
688
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.55 KB | None | 0 0
  1. public void move(EnumMoveType enummovetype, double d0, double d1, double d2) {
  2. SpigotTimings.entityMoveTimer.startTiming();
  3. if (this.noclip) {
  4. this.a(this.getBoundingBox().d(d0, d1, d2));
  5. this.recalcPosition();
  6. } else {
  7. try {
  8. this.checkBlockCollisions();
  9. } catch (Throwable var60) {
  10. CrashReport crashreport = CrashReport.a(var60, "Checking entity block collision");
  11. CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Entity being checked for collision");
  12. this.appendEntityCrashDetails(crashreportsystemdetails);
  13. throw new ReportedException(crashreport);
  14. }
  15.  
  16. if (d0 == 0.0D && d1 == 0.0D && d2 == 0.0D && this.isVehicle() && this.isPassenger()) {
  17. return;
  18. }
  19.  
  20. if (enummovetype == EnumMoveType.PISTON) {
  21. long i = this.world.getTime();
  22. if (i != this.aK) {
  23. Arrays.fill(this.aJ, 0.0D);
  24. this.aK = i;
  25. }
  26.  
  27. double d3;
  28. int j;
  29. if (d0 != 0.0D) {
  30. j = EnumAxis.X.ordinal();
  31. d3 = MathHelper.a(d0 + this.aJ[j], -0.51D, 0.51D);
  32. d0 = d3 - this.aJ[j];
  33. this.aJ[j] = d3;
  34. if (Math.abs(d0) <= 9.999999747378752E-6D) {
  35. return;
  36. }
  37. } else if (d1 != 0.0D) {
  38. j = EnumAxis.Y.ordinal();
  39. d3 = MathHelper.a(d1 + this.aJ[j], -0.51D, 0.51D);
  40. d1 = d3 - this.aJ[j];
  41. this.aJ[j] = d3;
  42. if (Math.abs(d1) <= 9.999999747378752E-6D) {
  43. return;
  44. }
  45. } else {
  46. if (d2 == 0.0D) {
  47. return;
  48. }
  49.  
  50. j = EnumAxis.Z.ordinal();
  51. d3 = MathHelper.a(d2 + this.aJ[j], -0.51D, 0.51D);
  52. d2 = d3 - this.aJ[j];
  53. this.aJ[j] = d3;
  54. if (Math.abs(d2) <= 9.999999747378752E-6D) {
  55. return;
  56. }
  57. }
  58. }
  59.  
  60. this.world.methodProfiler.a("move");
  61. double d4 = this.locX;
  62. double d5 = this.locY;
  63. double d6 = this.locZ;
  64. if (this.E) {
  65. this.E = false;
  66. d0 *= 0.25D;
  67. d1 *= 0.05000000074505806D;
  68. d2 *= 0.25D;
  69. this.motX = 0.0D;
  70. this.motY = 0.0D;
  71. this.motZ = 0.0D;
  72. }
  73.  
  74. double d7 = d0;
  75. double d8 = d1;
  76. double d9 = d2;
  77. if ((enummovetype == EnumMoveType.SELF || enummovetype == EnumMoveType.PLAYER) && this.onGround && this.isSneaking() && this instanceof EntityHuman) {
  78. for(; d0 != 0.0D && this.world.getCubes(this, this.getBoundingBox().d(d0, (double)(-this.P), 0.0D)).isEmpty(); d7 = d0) {
  79. if (d0 < 0.05D && d0 >= -0.05D) {
  80. d0 = 0.0D;
  81. } else if (d0 > 0.0D) {
  82. d0 -= 0.05D;
  83. } else {
  84. d0 += 0.05D;
  85. }
  86. }
  87.  
  88. for(; d2 != 0.0D && this.world.getCubes(this, this.getBoundingBox().d(0.0D, (double)(-this.P), d2)).isEmpty(); d9 = d2) {
  89. if (d2 < 0.05D && d2 >= -0.05D) {
  90. d2 = 0.0D;
  91. } else if (d2 > 0.0D) {
  92. d2 -= 0.05D;
  93. } else {
  94. d2 += 0.05D;
  95. }
  96. }
  97.  
  98. for(; d0 != 0.0D && d2 != 0.0D && this.world.getCubes(this, this.getBoundingBox().d(d0, (double)(-this.P), d2)).isEmpty(); d9 = d2) {
  99. if (d0 < 0.05D && d0 >= -0.05D) {
  100. d0 = 0.0D;
  101. } else if (d0 > 0.0D) {
  102. d0 -= 0.05D;
  103. } else {
  104. d0 += 0.05D;
  105. }
  106.  
  107. d7 = d0;
  108. if (d2 < 0.05D && d2 >= -0.05D) {
  109. d2 = 0.0D;
  110. } else if (d2 > 0.0D) {
  111. d2 -= 0.05D;
  112. } else {
  113. d2 += 0.05D;
  114. }
  115. }
  116. }
  117.  
  118. List list = this.world.getCubes(this, this.getBoundingBox().b(d0, d1, d2));
  119. AxisAlignedBB axisalignedbb = this.getBoundingBox();
  120. int k;
  121. int l;
  122. if (d1 != 0.0D) {
  123. k = 0;
  124.  
  125. for(l = list.size(); k < l; ++k) {
  126. d1 = ((AxisAlignedBB)list.get(k)).b(this.getBoundingBox(), d1);
  127. }
  128.  
  129. this.a(this.getBoundingBox().d(0.0D, d1, 0.0D));
  130. }
  131.  
  132. if (d0 != 0.0D) {
  133. k = 0;
  134.  
  135. for(l = list.size(); k < l; ++k) {
  136. d0 = ((AxisAlignedBB)list.get(k)).a(this.getBoundingBox(), d0);
  137. }
  138.  
  139. if (d0 != 0.0D) {
  140. this.a(this.getBoundingBox().d(d0, 0.0D, 0.0D));
  141. }
  142. }
  143.  
  144. if (d2 != 0.0D) {
  145. k = 0;
  146.  
  147. for(l = list.size(); k < l; ++k) {
  148. d2 = ((AxisAlignedBB)list.get(k)).c(this.getBoundingBox(), d2);
  149. }
  150.  
  151. if (d2 != 0.0D) {
  152. this.a(this.getBoundingBox().d(0.0D, 0.0D, d2));
  153. }
  154. }
  155.  
  156. boolean flag = this.onGround || d1 != d1 && d1 < 0.0D;
  157. double d11;
  158. if (this.P > 0.0F && flag && (d7 != d0 || d9 != d2)) {
  159. double d12 = d0;
  160. double d13 = d1;
  161. double d14 = d2;
  162. AxisAlignedBB axisalignedbb1 = this.getBoundingBox();
  163. this.a(axisalignedbb);
  164. d1 = (double)this.P;
  165. List list1 = this.world.getCubes(this, this.getBoundingBox().b(d7, d1, d9));
  166. AxisAlignedBB axisalignedbb2 = this.getBoundingBox();
  167. AxisAlignedBB axisalignedbb3 = axisalignedbb2.b(d7, 0.0D, d9);
  168. d11 = d1;
  169. int i1 = 0;
  170.  
  171. for(int j1 = list1.size(); i1 < j1; ++i1) {
  172. d11 = ((AxisAlignedBB)list1.get(i1)).b(axisalignedbb3, d11);
  173. }
  174.  
  175. axisalignedbb2 = axisalignedbb2.d(0.0D, d11, 0.0D);
  176. double d15 = d7;
  177. int k1 = 0;
  178.  
  179. for(int l1 = list1.size(); k1 < l1; ++k1) {
  180. d15 = ((AxisAlignedBB)list1.get(k1)).a(axisalignedbb2, d15);
  181. }
  182.  
  183. axisalignedbb2 = axisalignedbb2.d(d15, 0.0D, 0.0D);
  184. double d16 = d9;
  185. int i2 = 0;
  186.  
  187. for(int j2 = list1.size(); i2 < j2; ++i2) {
  188. d16 = ((AxisAlignedBB)list1.get(i2)).c(axisalignedbb2, d16);
  189. }
  190.  
  191. axisalignedbb2 = axisalignedbb2.d(0.0D, 0.0D, d16);
  192. AxisAlignedBB axisalignedbb4 = this.getBoundingBox();
  193. double d17 = d1;
  194. int k2 = 0;
  195.  
  196. for(int l2 = list1.size(); k2 < l2; ++k2) {
  197. d17 = ((AxisAlignedBB)list1.get(k2)).b(axisalignedbb4, d17);
  198. }
  199.  
  200. axisalignedbb4 = axisalignedbb4.d(0.0D, d17, 0.0D);
  201. double d18 = d7;
  202. int i3 = 0;
  203.  
  204. for(int j3 = list1.size(); i3 < j3; ++i3) {
  205. d18 = ((AxisAlignedBB)list1.get(i3)).a(axisalignedbb4, d18);
  206. }
  207.  
  208. axisalignedbb4 = axisalignedbb4.d(d18, 0.0D, 0.0D);
  209. double d19 = d9;
  210. int k3 = 0;
  211.  
  212. for(int l3 = list1.size(); k3 < l3; ++k3) {
  213. d19 = ((AxisAlignedBB)list1.get(k3)).c(axisalignedbb4, d19);
  214. }
  215.  
  216. axisalignedbb4 = axisalignedbb4.d(0.0D, 0.0D, d19);
  217. double d20 = d15 * d15 + d16 * d16;
  218. double d21 = d18 * d18 + d19 * d19;
  219. if (d20 > d21) {
  220. d0 = d15;
  221. d2 = d16;
  222. d1 = -d11;
  223. this.a(axisalignedbb2);
  224. } else {
  225. d0 = d18;
  226. d2 = d19;
  227. d1 = -d17;
  228. this.a(axisalignedbb4);
  229. }
  230.  
  231. int i4 = 0;
  232.  
  233. for(int j4 = list1.size(); i4 < j4; ++i4) {
  234. d1 = ((AxisAlignedBB)list1.get(i4)).b(this.getBoundingBox(), d1);
  235. }
  236.  
  237. this.a(this.getBoundingBox().d(0.0D, d1, 0.0D));
  238. if (d12 * d12 + d14 * d14 >= d0 * d0 + d2 * d2) {
  239. d0 = d12;
  240. d1 = d13;
  241. d2 = d14;
  242. this.a(axisalignedbb1);
  243. }
  244. }
  245.  
  246. this.world.methodProfiler.b();
  247. this.world.methodProfiler.a("rest");
  248. this.recalcPosition();
  249. this.positionChanged = d7 != d0 || d9 != d2;
  250. this.B = d1 != d8;
  251. this.onGround = this.B && d8 < 0.0D;
  252. this.C = this.positionChanged || this.B;
  253. l = MathHelper.floor(this.locX);
  254. int k4 = MathHelper.floor(this.locY - 0.20000000298023224D);
  255. int l4 = MathHelper.floor(this.locZ);
  256. BlockPosition blockposition = new BlockPosition(l, k4, l4);
  257. IBlockData iblockdata = this.world.getType(blockposition);
  258. if (iblockdata.getMaterial() == Material.AIR) {
  259. BlockPosition blockposition1 = blockposition.down();
  260. IBlockData iblockdata1 = this.world.getType(blockposition1);
  261. net.minecraft.server.v1_12_R1.Block block = iblockdata1.getBlock();
  262. if (block instanceof BlockFence || block instanceof BlockCobbleWall || block instanceof BlockFenceGate) {
  263. iblockdata = iblockdata1;
  264. blockposition = blockposition1;
  265. }
  266. }
  267.  
  268. this.a(d1, this.onGround, iblockdata, blockposition);
  269. if (d7 != d0) {
  270. this.motX = 0.0D;
  271. }
  272.  
  273. if (d9 != d2) {
  274. this.motZ = 0.0D;
  275. }
  276.  
  277. net.minecraft.server.v1_12_R1.Block block1 = iblockdata.getBlock();
  278. if (d8 != d1) {
  279. block1.a(this.world, this);
  280. }
  281.  
  282. if (this.positionChanged && this.getBukkitEntity() instanceof Vehicle) {
  283. Vehicle vehicle = (Vehicle)this.getBukkitEntity();
  284. Block bl = this.world.getWorld().getBlockAt(MathHelper.floor(this.locX), MathHelper.floor(this.locY), MathHelper.floor(this.locZ));
  285. if (d7 > d0) {
  286. bl = bl.getRelative(BlockFace.EAST);
  287. } else if (d7 < d0) {
  288. bl = bl.getRelative(BlockFace.WEST);
  289. } else if (d9 > d2) {
  290. bl = bl.getRelative(BlockFace.SOUTH);
  291. } else if (d9 < d2) {
  292. bl = bl.getRelative(BlockFace.NORTH);
  293. }
  294.  
  295. if (bl.getType() != org.bukkit.Material.AIR) {
  296. VehicleBlockCollisionEvent event = new VehicleBlockCollisionEvent(vehicle, bl);
  297. this.world.getServer().getPluginManager().callEvent(event);
  298. }
  299. }
  300.  
  301. if (this.playStepSound() && (!this.onGround || !this.isSneaking() || !(this instanceof EntityHuman)) && !this.isPassenger()) {
  302. double d22 = this.locX - d4;
  303. double d23 = this.locY - d5;
  304. d11 = this.locZ - d6;
  305. if (block1 != Blocks.LADDER) {
  306. d23 = 0.0D;
  307. }
  308.  
  309. if (block1 != null && this.onGround) {
  310. block1.stepOn(this.world, blockposition, this);
  311. }
  312.  
  313. this.J = (float)((double)this.J + (double)MathHelper.sqrt(d22 * d22 + d11 * d11) * 0.6D);
  314. this.K = (float)((double)this.K + (double)MathHelper.sqrt(d22 * d22 + d23 * d23 + d11 * d11) * 0.6D);
  315. if (this.K > (float)this.ax && iblockdata.getMaterial() != Material.AIR) {
  316. this.ax = (int)this.K + 1;
  317. if (!this.isInWater()) {
  318. this.a(blockposition, block1);
  319. } else {
  320. Entity entity = this.isVehicle() && this.bE() != null ? this.bE() : this;
  321. float f = entity == this ? 0.35F : 0.4F;
  322. float f1 = MathHelper.sqrt(entity.motX * entity.motX * 0.20000000298023224D + entity.motY * entity.motY + entity.motZ * entity.motZ * 0.20000000298023224D) * f;
  323. if (f1 > 1.0F) {
  324. f1 = 1.0F;
  325. }
  326.  
  327. this.a(this.ae(), f1, 1.0F + (this.random.nextFloat() - this.random.nextFloat()) * 0.4F);
  328. }
  329. } else if (this.K > this.ay && this.ah() && iblockdata.getMaterial() == Material.AIR) {
  330. this.ay = this.d(this.K);
  331. }
  332. }
  333.  
  334. boolean flag1 = this.an();
  335. if (this.world.e(this.getBoundingBox().shrink(0.001D))) {
  336. this.burn(1.0F);
  337. if (!flag1) {
  338. ++this.fireTicks;
  339. if (this.fireTicks == 0) {
  340. EntityCombustEvent event = new EntityCombustByBlockEvent((Block)null, this.getBukkitEntity(), 8);
  341. this.world.getServer().getPluginManager().callEvent(event);
  342. if (!event.isCancelled()) {
  343. this.setOnFire(event.getDuration());
  344. }
  345. }
  346. }
  347. } else if (this.fireTicks <= 0) {
  348. this.fireTicks = -this.getMaxFireTicks();
  349. }
  350.  
  351. if (flag1 && this.isBurning()) {
  352. this.a(SoundEffects.bW, 0.7F, 1.6F + (this.random.nextFloat() - this.random.nextFloat()) * 0.4F);
  353. this.fireTicks = -this.getMaxFireTicks();
  354. }
  355.  
  356. this.world.methodProfiler.b();
  357. }
  358.  
  359. SpigotTimings.entityMoveTimer.stopTiming();
  360. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement