Welcome on MasterOf13FPS! MasterOf13FPS

Register today or sign up if you are already a member and never miss any cool content again :)

Source 2d ESP

Red

New member
Joined
May 16, 2022
Messages
9
Reaction score
4
Points
3
Today I want to share my 2d esp that I made some time ago
I tried to explain some of the code with comments
Feel free to give me suggestions for improvement


You may need to generate some getters and replace some variables as my client is in 1.12.2
In your event method:
Java:
if (event instanceof EventRender2D) {
    for (Entity entity : mc.world.loadedEntityList) {
        if (entity instanceof EntityPlayer) {
            // continue if we are in third person
            if (entity == mc.player && mc.gameSettings.thirdPersonView == 0) continue;
            render2DESP(entity.getEntityBoundingBox().offset(-entity.posX, -entity.posY, -entity.posZ)
                    .offset(interpolate(entity.lastTickPosX, entity.posX), interpolate(entity.lastTickPosY, entity.posY), interpolate(entity.lastTickPosZ, entity.posZ))
                    .offset(-mc.getRenderManager().getRenderPosX(), -mc.getRenderManager().getRenderPosY(), -mc.getRenderManager().getRenderPosZ()), Color.white, 2f
            );
        }
    }
}

Java:
private void render2DESP(AxisAlignedBB axisAlignedBB, Color color, float lineWidth) {
    ScaledResolution scaledResolution = new ScaledResolution(mc);

    // use an extreme high or low value that will probably never be valid
    double minX = Double.MAX_VALUE, minY = Double.MAX_VALUE;
    double maxX = Double.MIN_VALUE, maxY = Double.MIN_VALUE;

    // clear the last stored window position
    windowPos.clear();

    // loop thought all min max combinations
    for (int x = 0; x < 2; x++) {
        for (int z = 0; z < 2; z++) {
            for (int y = 0; y < 2; y++) {
                // use gluProject to convert the 3D object coords to 2D window coords
                if (GLU.gluProject((float) (x == 1 ? axisAlignedBB.minX : axisAlignedBB.maxX), (float) (y == 1 ? axisAlignedBB.minY : axisAlignedBB.maxY), (float) (z == 1 ? axisAlignedBB.minZ : axisAlignedBB.maxZ), ActiveRenderInfo.getMODELVIEW(), ActiveRenderInfo.getPROJECTION(), ActiveRenderInfo.getVIEWPORT(), windowPos)) {
                    if (windowPos.get(2) > 1) {
                        continue;
                    }

                    // scale the output coords with our current scale factor
                    double screenX = windowPos.get(0) / scaledResolution.getScaleFactor();
                    double screenY = windowPos.get(1) / scaledResolution.getScaleFactor();

                    // find the max and min coords
                    minX = Math.min(screenX, minX);
                    minY = Math.min(screenY, minY);
                    maxX = Math.max(screenX, maxX);
                    maxY = Math.max(screenY, maxY);
                }
            }
        }
    }

    // if minX isn't Double.MAX_VALUE then the other values should also be valid
    if (minX != Double.MAX_VALUE) {
        if (minX > 0 || minY > 0 || maxX <= mc.displayWidth || maxX <= mc.displayHeight) {
            // invert the y coords because Minecraft has inverted them as well
            minY = scaledResolution.getScaledHeight() - minY;
            maxY = scaledResolution.getScaledHeight() - maxY;

            GL11.glPushMatrix();
            // enable alpha blending
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
            // disable texture 2d since we don't want to draw any textures
            GL11.glDisable(GL11.GL_TEXTURE_2D);
            GL11.glColor4d(color.getRed() / 255d, color.getGreen() / 255d, color.getBlue() / 255d, color.getAlpha() / 255d);
            // set the outline width to 2
            GL11.glLineWidth(lineWidth);
            // render the outline line loop connects the last point automatically
            GL11.glBegin(GL11.GL_LINE_LOOP);
            GL11.glVertex2d(minX, minY);
            GL11.glVertex2d(minX, maxY);
            GL11.glVertex2d(maxX, maxY);
            GL11.glVertex2d(maxX, minY);
            GL11.glEnd();
            GL11.glEnable(GL11.GL_TEXTURE_2D);
            GL11.glDisable(GL11.GL_BLEND);
            GL11.glPopMatrix();
        }
    }
}

private double interpolate(double lastPos, double pos) {
    return lastPos + (pos - lastPos) * mc.timer.renderPartialTicks;
}
You can also use this method for tile entities like chests or blocks like beds
 
shape1
shape2
shape3
shape4
shape5
shape6
Back
Top