Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.40 KB | None | 0 0
  1. package me.pascal.hook.util;
  2.  
  3. import me.pascal.hook.Hook;
  4. import me.pascal.hook.module.modules.ESP;
  5. import net.minecraft.client.Minecraft;
  6. import net.minecraft.client.entity.EntityOtherPlayerMP;
  7. import net.minecraft.client.entity.EntityPlayerSP;
  8. import net.minecraft.entity.Entity;
  9. import net.minecraft.entity.item.EntityItem;
  10. import net.minecraft.entity.monster.EntityMob;
  11. import net.minecraft.entity.passive.EntityAnimal;
  12. import net.minecraft.entity.player.EntityPlayer;
  13. import net.minecraft.util.math.AxisAlignedBB;
  14. import net.minecraft.util.math.Vec3d;
  15. import org.lwjgl.BufferUtils;
  16. import org.lwjgl.opengl.Display;
  17. import org.lwjgl.opengl.GL11;
  18. import org.lwjgl.util.glu.GLU;
  19.  
  20. import java.nio.FloatBuffer;
  21. import java.nio.IntBuffer;
  22. import java.util.*;
  23.  
  24. /**
  25. * Created by Pascal on 19.02.2017.
  26. */
  27. public class ScreenPosUtil {
  28. private static Minecraft mc;
  29. private static Map<Entity, Vec3d[]> entity2DBounding;
  30.  
  31.  
  32. public static void captureEntity2DBounding() {
  33. if (entity2DBounding == null) {
  34. entity2DBounding = new HashMap<Entity, Vec3d[]>();
  35. }
  36. if (mc == null) {
  37. mc = Minecraft.getMinecraft();
  38. }
  39. try {
  40. entity2DBounding.clear();
  41. List<Entity> sortedList = new ArrayList();
  42.  
  43. for (Entity e : mc.world.loadedEntityList) {
  44. if (valid(e))
  45. sortedList.add(e);
  46. }
  47. for(Entity entity : sortedList){
  48. if (entity instanceof EntityPlayerSP) continue;
  49. Vec3d pos = getEntityRenderPos(entity);
  50. double x = pos.xCoord;
  51. double y = pos.yCoord;
  52. double z = pos.zCoord;
  53. double entityHeight = entity.height;
  54. AxisAlignedBB bb = entity.boundingBox;
  55. double maxX = (bb.maxX - bb.minX) / 2;
  56. double maxY = (bb.maxY - bb.minY) / 2;
  57. double maxZ = (bb.maxZ - bb.minZ) / 2;
  58. double[][] bbox
  59. = {
  60. {x + maxX, y + maxY + maxY, z + maxZ},
  61. {x - maxX, y - maxY + maxY, z + maxZ},
  62. {x - maxX, y + maxY + maxY, z + maxZ},
  63. {x + maxX, y - maxY + maxY, z + maxZ},
  64. {x + maxX, y + maxY + maxY, z - maxZ},
  65. {x - maxX, y - maxY + maxY, z - maxZ},
  66. {x - maxX, y + maxY + maxY, z - maxZ},
  67. {x + maxX, y - maxY + maxY, z - maxZ},
  68. {x, y + entityHeight / 2, z},//BB middlepos
  69. {x, y + entityHeight, z},//boudingbox end
  70. {x, y + entityHeight + 0.9, z}//Nametagpos
  71. };
  72. Vec3d[] corners = new Vec3d[bbox.length];
  73. for (int j = 0; j < corners.length && (entity instanceof EntityPlayer || j <= 7); ++j) {
  74. Vec3d vec = getScreenCoords(bbox[j][0], bbox[j][1], bbox[j][2]);
  75. if (vec == null) continue;
  76. corners[j] = vec;
  77. }
  78. entity2DBounding.put(entity, corners);
  79. }
  80.  
  81. return;
  82. } catch (Exception ex) {
  83. ex.printStackTrace();
  84. }
  85. }
  86.  
  87. public static boolean valid(Entity ent) {
  88. ESP esp = (ESP) Hook.getInstance().getModuleManager().getModuleByName("ESP");
  89.  
  90. if (ent instanceof EntityMob && esp.mobs.getValue()) {
  91. return true;
  92. } else if (ent instanceof EntityAnimal && esp.animals.getValue()) {
  93. return true;
  94. } else if (ent instanceof EntityItem && esp.items.getValue()) {
  95. return true;
  96. } else if (ent instanceof EntityOtherPlayerMP && esp.players.getValue()) {
  97. return true;
  98. }
  99.  
  100. return false;
  101. }
  102.  
  103. public static Vec3d getEntityRenderPos(final Entity player) {
  104. final double x = player.lastTickPosX + (player.posX - player.lastTickPosX) * mc.timer.renderPartialTicks
  105. - mc.getRenderManager().renderPosX;
  106. double y = player.lastTickPosY + (player.posY - player.lastTickPosY) * mc.timer.renderPartialTicks
  107. - mc.getRenderManager().renderPosY;
  108. final double z = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * mc.timer.renderPartialTicks
  109. - mc.getRenderManager().renderPosZ;
  110. return new Vec3d(x, y, z);
  111. }
  112.  
  113. public static Vec3d getScreenCoords(final double x, final double y, final double z) {
  114. final FloatBuffer screenCoordinates = BufferUtils.createFloatBuffer(3);
  115. final IntBuffer viewport = BufferUtils.createIntBuffer(16);
  116. final FloatBuffer modelView = BufferUtils.createFloatBuffer(16);
  117. final FloatBuffer projection = BufferUtils.createFloatBuffer(16);
  118. GL11.glGetFloat(2982, modelView);
  119. GL11.glGetFloat(2983, projection);
  120. GL11.glGetInteger(2978, viewport);
  121. final boolean result = GLU.gluProject((float) x, (float) y, (float) z, modelView, projection, viewport,
  122. screenCoordinates);
  123. if (result) {
  124. return new Vec3d(screenCoordinates.get(0), Display.getHeight() - screenCoordinates.get(1), screenCoordinates.get(2));
  125. }
  126. return null;
  127. }
  128.  
  129. public static Map getScreenPoses() {
  130. return ScreenPosUtil.entity2DBounding;
  131. }
  132.  
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement