Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2018
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. package gg.ragemc.spigot.util;
  2.  
  3. import net.jafama.FastMath;
  4. import net.minecraft.server.EnumDirection;
  5. import net.minecraft.server.MathHelper;
  6. import net.minecraft.server.Vec3D;
  7. import net.minecraft.server.WorldSettings;
  8.  
  9. public class NotchUtil {
  10.  
  11. // Stitched this together from old source lol
  12. // NOTE: y is locY + headHeight
  13. public static EnumDirection getDirection(float pitch, float yaw, double x, double y, double z, WorldSettings.EnumGamemode gamemode) {
  14. Vec3D firstVector = new Vec3D(x, y, z);
  15.  
  16. float f3 = MathHelper.cos(-yaw * 0.017453292F - 3.1415927F);
  17. float f4 = (float) FastMath.sin(-yaw * 0.017453292F - 3.1415927F);
  18. float f5 = -MathHelper.cos(-pitch * 0.017453292F);
  19. float f6 = (float) FastMath.sin(-pitch * 0.017453292F);
  20. float f7 = f4 * f5;
  21. float f8 = f3 * f5;
  22. double d3 = gamemode == WorldSettings.EnumGamemode.CREATIVE ? 5.0D : 4.5D;
  23.  
  24. Vec3D secondVector = firstVector.add((double) f7 * d3, (double) f6 * d3, (double) f8 * d3);
  25.  
  26. int i = MathHelper.floor(secondVector.a);
  27. int j = MathHelper.floor(secondVector.b);
  28. int k = MathHelper.floor(secondVector.c);
  29. int l = MathHelper.floor(firstVector.a);
  30. int i1 = MathHelper.floor(firstVector.b);
  31. int j1 = MathHelper.floor(firstVector.c);
  32.  
  33. boolean xDivide = true;
  34. boolean yDivide = true;
  35. boolean zDivide = true;
  36. double startX = 999.0D;
  37. double startY = 999.0D;
  38. double startZ = 999.0D;
  39. double xDifference = secondVector.a - firstVector.a;
  40. double yDifference = secondVector.b - firstVector.b;
  41. double zDifference = secondVector.c - firstVector.c;
  42.  
  43. if (i > l) {
  44. startX = (double) l + 1.0D;
  45. } else if (i < l) {
  46. startX = (double) l + 0.0D;
  47. } else {
  48. xDivide = false;
  49. }
  50.  
  51. if (j > i1) {
  52. startY = (double) i1 + 1.0D;
  53. } else if (j < i1) {
  54. startY = (double) i1 + 0.0D;
  55. } else {
  56. yDivide = false;
  57. }
  58.  
  59. if (k > j1) {
  60. startZ = (double) j1 + 1.0D;
  61. } else if (k < j1) {
  62. startZ = (double) j1 + 0.0D;
  63. } else {
  64. zDivide = false;
  65. }
  66.  
  67. if (xDivide) {
  68. startX = (startX - firstVector.a) / xDifference;
  69. }
  70.  
  71. if (yDivide) {
  72. startY = (startY - firstVector.b) / yDifference;
  73. }
  74.  
  75. if (zDivide) {
  76. startZ = (startZ - firstVector.c) / zDifference;
  77. }
  78.  
  79. if (startX == -0.0D) {
  80. startX = -1.0E-4D;
  81. }
  82.  
  83. if (startY == -0.0D) {
  84. startY = -1.0E-4D;
  85. }
  86.  
  87. if (startZ == -0.0D) {
  88. startZ = -1.0E-4D;
  89. }
  90.  
  91. EnumDirection enumdirection;
  92.  
  93. if (startX < startY && startX < startZ) {
  94. enumdirection = i > l ? EnumDirection.WEST : EnumDirection.EAST;
  95. } else if (startY < startZ) {
  96. enumdirection = j > i1 ? EnumDirection.DOWN : EnumDirection.UP;
  97. } else {
  98. enumdirection = k > j1 ? EnumDirection.NORTH : EnumDirection.SOUTH;
  99. }
  100.  
  101. return enumdirection;
  102. }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement