Welcome on MasterOf13FPS! MasterOf13FPS

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

I need help

Avis

New member
Joined
Apr 6, 2024
Messages
6
Reaction score
0
Points
1
Ok so if I am being completely honest I have no idea how to make ESP or Nametags can anybody help me the only thing I know is we need to make a method which draws the ESP or nametag and we do like for(Entity e : mc.theWorld.loadedEntityList){ and do drawEsp(e);
 
Well here is a quick and easy guide, totally not written by chatGPT:
1. Get the render position and scaling factor;
2. Iterate through the loaded entities in the minecraft world;
3. Project a 3D point onto the 2D screen, for this you can use GLU.gluProject;
4. Check if the position is valid and in front of the camera;
5. Calculate screen coordinates aka divide both x and y values with z(because why not?);
6. Draw the nametag itself.

Here is some code I put together from the code it provided to make sense.

PS. I don't know if this code works and I do now see that it used two types of methods of getting the minecraft instance: "getMinecraft()" and "mc."
😂

Java:
public void render2D() {
    double renderX = getMinecraft().getRenderManager().getRenderPosX();
    double renderY = getMinecraft().getRenderManager().getRenderPosY();
    double renderZ = getMinecraft().getRenderManager().getRenderPosZ();
   
    int scaleFactor = new ScaledResolution(getMinecraft()).getScaleFactor();
   
    for (Entity entity : getWorld().loadedEntityList) {
        if (!shouldRenderNametag(entity)) {
                continue;
        }

        EntityLivingBase livingEntity = (EntityLivingBase) entity;
        Vector3f position = projectEntityToScreen(scaleFactor, renderX, renderY, renderZ, livingEntity);
       
        if (position != null && position.z >= 0.0D && position.z < 1.0D) {
            drawNametag(livingEntity.getName(), position);
        }
    }
}

// Check if an entity should have a nametag rendered
private boolean shouldRenderNametag(Entity entity) {
    if (getMinecraft().getRenderManager() == null ||
        entity == getPlayer() ||
        entity.isDead ||
        entity.isInvisible() ||
        (entity instanceof EntityArmorStand) ||
        !(entity instanceof EntityLivingBase)) {
        return false;
    }
    return true;
}

// Project entity's position to the screen
private Vector3f projectEntityToScreen(int scaleFactor, double renderX, double renderY, double renderZ, EntityLivingBase livingEntity) {
    if (GLU.gluProject((float) (livingEntity.lastTickPosX - renderX),
            (float) (livingEntity.lastTickPosY - renderY),
            (float) (livingEntity.lastTickPosZ - renderZ),
            ActiveRenderInfo.MODELVIEW,
            ActiveRenderInfo.PROJECTION,
            ActiveRenderInfo.VIEWPORT,
            ActiveRenderInfo.OBJECTCOORDS)) {
        float x = ActiveRenderInfo.OBJECTCOORDS.get(0) / scaleFactor;
        float y = (Display.getHeight() - ActiveRenderInfo.OBJECTCOORDS.get(1)) / scaleFactor;
        float z = ActiveRenderInfo.OBJECTCOORDS.get(2);
        return new Vector3f(x, y, z);
    }
    return null;
}

// Draw nametag on the screen
private void drawNametag(String name, Vector3f position) {
    int x = (int) (position.x - mc.fontRendererObj.getStringWidth(name) / 2);
    int y = (int) (position.y - 2 - mc.fontRendererObj.FONT_HEIGHT);
    mc.fontRendererObj.drawStringWithShadow(name, x, y, -1);
}
 
shape1
shape2
shape3
shape4
shape5
shape6
Back
Top