Advertisement
Guest User

Untitled

a guest
Jul 16th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. package me.eazzy.client.utils;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Iterator;
  5. import net.minecraft.client.Minecraft;
  6. import net.minecraft.entity.EntityLivingBase;
  7. import net.minecraft.util.AxisAlignedBB;
  8. import org.lwjgl.util.vector.Vector3f;
  9.  
  10. public class RayTraceUtil {
  11. protected Minecraft mc = Minecraft.getMinecraft();
  12. private float startX;
  13. private float startY;
  14. private float startZ;
  15. private float endX;
  16. private float endY;
  17. private float endZ;
  18. private static final float MAX_STEP = 0.1F;
  19. private ArrayList<Vector3f> positions = new ArrayList();
  20. private EntityLivingBase entity;
  21.  
  22. public RayTraceUtil(EntityLivingBase entity) {
  23. this.startX = (float) this.mc.thePlayer.posX;
  24. this.startY = (float) this.mc.thePlayer.posY + 1.0F;
  25. this.startZ = (float) this.mc.thePlayer.posZ;
  26. this.endX = (float) entity.posX;
  27. this.endY = (float) entity.posY + entity.height / 2.0F;
  28. this.endZ = (float) entity.posZ;
  29. this.entity = entity;
  30. this.positions.clear();
  31. this.addPositions();
  32. }
  33.  
  34. private void addPositions() {
  35. float diffX = this.endX - this.startX;
  36. float diffY = this.endY - this.startY;
  37. float diffZ = this.endZ - this.startZ;
  38. float currentX = 0.0F;
  39. float currentY = 1.0F;
  40. float currentZ = 0.0F;
  41. int steps = (int) Math.max(Math.abs(diffX) / 0.1F, Math.max(Math.abs(diffY) / 0.1F, Math.abs(diffZ) / 0.1F));
  42.  
  43. for (int i = 0; i <= steps; ++i) {
  44. this.positions.add(new Vector3f(currentX, currentY, currentZ));
  45. currentX += diffX / (float) steps;
  46. currentY += diffY / (float) steps;
  47. currentZ += diffZ / (float) steps;
  48. }
  49.  
  50. }
  51.  
  52. private boolean isInBox(Vector3f point, EntityLivingBase target) {
  53. AxisAlignedBB box = target.getEntityBoundingBox();
  54. double posX = this.mc.thePlayer.posX + (double) point.x;
  55. double posY = this.mc.thePlayer.posY + (double) point.y;
  56. double posZ = this.mc.thePlayer.posZ + (double) point.z;
  57. boolean x = posX >= box.minX - 0.25D && posX <= box.maxX + 0.25D;
  58. boolean y = posY >= box.minY && posY <= box.maxY;
  59. boolean z = posZ >= box.minZ - 0.25D && posZ <= box.maxZ + 0.25D;
  60. return x && z && y;
  61. }
  62.  
  63. public ArrayList<Vector3f> getPositions() {
  64. return this.positions;
  65. }
  66.  
  67. public EntityLivingBase getEntity() {
  68. new ArrayList();
  69. double dist = (double) this.mc.thePlayer.getDistanceToEntity(this.entity);
  70. EntityLivingBase entity = this.entity;
  71. Iterator arg5 = this.mc.theWorld.loadedEntityList.iterator();
  72.  
  73. while (true) {
  74. EntityLivingBase e;
  75. do {
  76. do {
  77. Object o;
  78. do {
  79. if (!arg5.hasNext()) {
  80. return entity;
  81. }
  82.  
  83. o = arg5.next();
  84. } while (!(o instanceof EntityLivingBase));
  85.  
  86. e = (EntityLivingBase) o;
  87. } while ((double) this.mc.thePlayer.getDistanceToEntity(e) >= dist);
  88. } while (this.mc.thePlayer == e);
  89.  
  90. Iterator arg8 = this.getPositions().iterator();
  91.  
  92. while (arg8.hasNext()) {
  93. Vector3f vec = (Vector3f) arg8.next();
  94. if (this.isInBox(vec, e)
  95. && this.mc.thePlayer.getDistanceToEntity(e) < this.mc.thePlayer.getDistanceToEntity(entity)) {
  96. entity = e;
  97. }
  98. }
  99. }
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement